From 494f99b478ed8628a62d20b3c37557702c699306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Fri, 24 Jan 2025 21:53:15 +0100 Subject: Option to run jobs for new tags --- src/Command/Run.hs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'src/Command/Run.hs') diff --git a/src/Command/Run.hs b/src/Command/Run.hs index b998a60..f93e619 100644 --- a/src/Command/Run.hs +++ b/src/Command/Run.hs @@ -17,6 +17,7 @@ import System.Console.GetOpt import System.Directory import System.Exit import System.FilePath +import System.FilePath.Glob import System.IO import System.Process @@ -32,6 +33,7 @@ data RunCommand = RunCommand RunOptions [ Text ] data RunOptions = RunOptions { roRanges :: [ Text ] , roNewCommitsOn :: [ Text ] + , roNewTags :: [ Pattern ] } instance Command RunCommand where @@ -55,6 +57,7 @@ instance Command RunCommand where defaultCommandOptions _ = RunOptions { roRanges = [] , roNewCommitsOn = [] + , roNewTags = [] } commandOptions _ = @@ -64,6 +67,9 @@ instance Command RunCommand where , Option [] [ "new-commits-on" ] (ReqArg (\val opts -> opts { roNewCommitsOn = T.pack val : roNewCommitsOn opts }) "") "run jobs for new commits on given branch" + , Option [] [ "new-tags" ] + (ReqArg (\val opts -> opts { roNewTags = compile val : roNewTags opts }) "") + "run jobs for new annotated tags matching pattern" ] commandInit _ = RunCommand @@ -136,6 +142,25 @@ watchBranchSource repo branch = do atomically $ putTMVar tmvar Nothing return $ JobSource tmvar +watchTagSource :: Repo -> Pattern -> IO JobSource +watchTagSource repo pat = do + chan <- watchTags repo + + let go tmvar = do + tag <- atomically $ readTChan chan + if match pat $ T.unpack $ tagTag tag + then do + jobset <- loadJobSetForCommit $ tagObject tag + nextvar <- newEmptyTMVarIO + atomically $ putTMVar tmvar $ Just ( [ jobset ], JobSource nextvar ) + go nextvar + else do + go tmvar + + tmvar <- newEmptyTMVarIO + void $ forkIO $ go tmvar + return $ JobSource tmvar + cmdRun :: RunCommand -> CommandExec () cmdRun (RunCommand RunOptions {..} args) = do CommonOptions {..} <- getCommonOptions @@ -165,10 +190,11 @@ cmdRun (RunCommand RunOptions {..} args) = do rangeSource repo base tip branches <- mapM (watchBranchSource repo) roNewCommitsOn + tags <- mapM (watchTagSource repo) roNewTags mngr <- newJobManager (baseDir ".minici") optJobs - source <- mergeSources $ concat [ ranges, branches ] + source <- mergeSources $ concat [ ranges, branches, tags ] headerLine <- newLine tout "" threadCount <- newTVarIO (0 :: Int) -- cgit v1.2.3