diff options
| author | Roman Smrž <roman.smrz@seznam.cz> | 2025-11-13 22:59:11 +0100 |
|---|---|---|
| committer | Roman Smrž <roman.smrz@seznam.cz> | 2025-11-13 22:59:11 +0100 |
| commit | d6ff11543a3897dd2b38ed121f958ef0050e272c (patch) | |
| tree | d37f1c58a214f9c3db84b229af7c832e5d5373a6 | |
| parent | e96ecb1ce8f81b3a256f6982c5da1aa7cbeb4e59 (diff) | |
Support publishing artifacts in the same job they're created
| -rw-r--r-- | src/Job.hs | 9 | ||||
| -rw-r--r-- | test/asset/publish/from_self.yaml | 22 | ||||
| -rw-r--r-- | test/script/publish.et | 25 |
3 files changed, 54 insertions, 2 deletions
@@ -296,7 +296,12 @@ waitForUsedArtifacts -> m [ ( ArtifactSpec, ArtifactOutput ) ] waitForUsedArtifacts tout job results outVar = do origState <- liftIO $ atomically $ readTVar outVar - let artSpecs = nubOrd $ jobUses job ++ (map jpArtifact $ jobPublish job) + let ( selfSpecs, artSpecs ) = partition ((jobName job ==) . fst) $ nubOrd $ jobUses job ++ (map jpArtifact $ jobPublish job) + + forM_ selfSpecs $ \( _, artName@(ArtifactName tname) ) -> do + when (not (artName `elem` map fst (jobArtifacts job))) $ do + throwError . JobError =<< liftIO (outputFootnote tout $ "Artifact ‘" <> tname <> "’ not produced by the job") + ujobs <- forM artSpecs $ \(ujobName@(JobName tjobName), uartName) -> do case find (\( j, _, _ ) -> jobName j == ujobName) results of Just ( _, _, var ) -> return ( var, ( ujobName, uartName )) @@ -413,7 +418,7 @@ runJob job uses checkoutPath jdir = do } forM_ (jobPublish job) $ \pub -> do - Just aout <- return $ lookup (jpArtifact pub) uses + Just aout <- return $ lookup (jpArtifact pub) $ map (\aout -> ( ( jobName job, aoutName aout ), aout )) artifacts ++ uses let ppath = case jpPath pub of Just path | hasTrailingPathSeparator path -> path </> takeFileName (aoutWorkPath aout) diff --git a/test/asset/publish/from_self.yaml b/test/asset/publish/from_self.yaml new file mode 100644 index 0000000..92d10e9 --- /dev/null +++ b/test/asset/publish/from_self.yaml @@ -0,0 +1,22 @@ +destination dest: + + +job gen_publish: + checkout: + + shell: + - touch x + - touch y + + artifact x: + path: x + + artifact y: + path: y + + publish: + - to: dest + artifact: x + + - to: dest + artifact: gen_publish.y diff --git a/test/script/publish.et b/test/script/publish.et index d5756cb..6cea2f2 100644 --- a/test/script/publish.et +++ b/test/script/publish.et @@ -42,3 +42,28 @@ test PublishFromDependency: /.\/fifth\/with_dir\/dir2\/for\/artifact\/dir2\/subdir\/z/ /(.*)/ capture done guard (done == "DONE") + + +test PublishFromSelf: + node n + shell on n: + mkdir workdir + cp ${scripts.path}/from_self.yaml workdir/minici.yaml + + spawn on n as p args [ "--destination=dest:destination", "workdir/minici.yaml", "run", "gen_publish" ] + expect_result from p: + of "gen_publish" result "done" + local: + expect /(.*)/ from p capture done + guard (done == "run-finish") + + shell on n as listing: + find . -path ./workdir/.minici -prune -o -type f -print + echo DONE + + expect from listing: + /.\/workdir\/minici.yaml/ + /.\/destination\/x/ + /.\/destination\/y/ + /(.*)/ capture done + guard (done == "DONE") |