diff options
| author | Roman Smrž <roman.smrz@seznam.cz> | 2025-05-25 19:16:20 +0200 | 
|---|---|---|
| committer | Roman Smrž <roman.smrz@seznam.cz> | 2025-05-27 21:24:14 +0200 | 
| commit | ad922b3e1a817333b633891ea11afc9b3dbf6a32 (patch) | |
| tree | 19e19b6f64dc4142adff0c6474ade2842f6227cd | |
| parent | 4f1121a15d65d5defa7c6e477ed5124b934c461f (diff) | |
Run jobs using full job reference
Changelog: Run jobs by specifying full job id or reference
| -rw-r--r-- | src/Command/Run.hs | 15 | ||||
| -rw-r--r-- | test/asset/run/explicit.yaml | 7 | ||||
| -rw-r--r-- | test/script/run.et | 93 | 
3 files changed, 112 insertions, 3 deletions
| diff --git a/src/Command/Run.hs b/src/Command/Run.hs index c122cf6..9652529 100644 --- a/src/Command/Run.hs +++ b/src/Command/Run.hs @@ -147,6 +147,12 @@ argumentJobSource names = do          cmdEvalWith (\ei -> ei { eiCurrentIdRev = cidPart ++ eiCurrentIdRev ei })          (evalJobSet (map ( Nothing, ) jobtree) JobSet {..}) +refJobSource :: [ JobRef ] -> CommandExec JobSource +refJobSource [] = emptyJobSource +refJobSource refs = do +    jobs <- cmdEvalWith id $ mapM evalJobReference refs +    oneshotJobSource . map (JobSet Nothing . Right . (: [])) $ jobs +  loadJobSetFromRoot :: (MonadIO m, MonadFail m) => JobRoot -> Commit -> m DeclaredJobSet  loadJobSetFromRoot root commit = case root of      JobRootRepo _ -> loadJobSetForCommit commit @@ -248,11 +254,14 @@ cmdRun (RunCommand RunOptions {..} args) = do              [ base, tip ]                  | not (T.null base) && not (T.null tip)                  -> return $ Left ( Just base, tip ) -            [ _ ] -> return $ Right $ JobName arg +            [ _ ] -> return $ Right arg              _ -> tfail $ "invalid argument: " <> arg          ] -    argumentJobs <- argumentJobSource jobOptions +    let ( refOptions, nameOptions ) = partition (T.elem '.') jobOptions + +    argumentJobs <- argumentJobSource $ map JobName nameOptions +    refJobs <- refJobSource $ map parseJobRef refOptions      defaultSource <- getJobRoot >>= \case          _ | not (null rangeOptions && null roNewCommitsOn && null roNewTags && null jobOptions) -> do @@ -279,7 +288,7 @@ cmdRun (RunCommand RunOptions {..} args) = do      liftIO $ do          mngr <- newJobManager storageDir optJobs -        source <- mergeSources $ concat [ [ defaultSource, argumentJobs ], ranges, branches, tags ] +        source <- mergeSources $ concat [ [ defaultSource, argumentJobs, refJobs ], ranges, branches, tags ]          mbHeaderLine <- mapM (flip newLine "") (outputTerminal output)          threadCount <- newTVarIO (0 :: Int) diff --git a/test/asset/run/explicit.yaml b/test/asset/run/explicit.yaml new file mode 100644 index 0000000..d543d16 --- /dev/null +++ b/test/asset/run/explicit.yaml @@ -0,0 +1,7 @@ +job build: +  shell: +    - ls subdir | sed -e ':a;N;s/\n/ /;ta' > list +    - echo >> list + +  artifact out: +    path: list diff --git a/test/script/run.et b/test/script/run.et index 9efc0e7..b6dc1b0 100644 --- a/test/script/run.et +++ b/test/script/run.et @@ -135,3 +135,96 @@ test RunExternalRepo:          expect /(.*)/ from p capture done          guard (done == "run-finish") + + +test RunExplicitJob: +    node n +    shell on n as git_init: +        mkdir -p main +        git -C main -c init.defaultBranch=master init -q +        cp "${scripts.path}/explicit.yaml" main/minici.yaml +        git -C main add minici.yaml +        git -C main -c user.name=test -c user.email=test commit -q --allow-empty -m 'initial commit' + +        mkdir -p main/subdir + +        touch main/subdir/a +        git -C main add subdir +        git -C main -c user.name=test -c user.email=test commit -q -m 'commit' +        git -C main rev-parse HEAD^{commit} +        git -C main rev-parse HEAD^{tree} + +        touch main/subdir/b +        git -C main add subdir +        git -C main -c user.name=test -c user.email=test commit -q -m 'commit' +        git -C main rev-parse HEAD^{tree} + +        rm main/subdir/a +        rm main/subdir/b +        touch main/subdir/c +        git -C main add subdir +        git -C main -c user.name=test -c user.email=test commit -q -m 'commit' +        git -C main rev-parse HEAD^{tree} + +        touch main/subdir/d +        git -C main add subdir +        git -C main -c user.name=test -c user.email=test commit -q -m 'commit' +        git -C main rev-parse HEAD^{tree} + +    expect /([0-9a-f]+)/ from git_init capture c1 +    expect /([0-9a-f]+)/ from git_init capture t1 +    expect /([0-9a-f]+)/ from git_init capture t2 +    expect /([0-9a-f]+)/ from git_init capture t3 +    expect /([0-9a-f]+)/ from git_init capture t4 + +    local: +        spawn on n as p args [ "./main", "run", "$c1.build" ] +        expect_success from p of "$t1.build" +        expect /(.*)/ from p capture done +        guard (done == "run-finish") +    local: +        spawn on n as p args [ "./main", "extract", "$c1.build.out", "list" ] +    local: +        shell on n as s: +            cat list +            rm list +        expect /a/ from s + +    local: +        spawn on n as p args [ "./main", "run", "$t2.build" ] +        expect_success from p of "$t2.build" +        expect /(.*)/ from p capture done +        guard (done == "run-finish") +    local: +        spawn on n as p args [ "./main", "extract", "$t2.build.out", "list" ] +    local: +        shell on n as s: +            cat list +            rm list +        expect /a b/ from s + +    local: +        spawn on n as p args [ "./main", "run", "HEAD^.build" ] +        expect_success from p of "$t3.build" +        expect /(.*)/ from p capture done +        guard (done == "run-finish") +    local: +        spawn on n as p args [ "./main", "extract", "HEAD^.build.out", "list" ] +    local: +        shell on n as s: +            cat list +            rm list +        expect /c/ from s + +    local: +        spawn on n as p args [ "./main", "run", "HEAD.build" ] +        expect_success from p of "$t4.build" +        expect /(.*)/ from p capture done +        guard (done == "run-finish") +    local: +        spawn on n as p args [ "./main", "extract", "HEAD.build.out", "list" ] +    local: +        shell on n as s: +            cat list +            rm list +        expect /c d/ from s |