remove update-list option; improve result logging

This commit is contained in:
Ryan Mulligan 2023-01-04 20:25:21 -08:00
parent 6eb37deb29
commit 74f225c5c2
2 changed files with 5 additions and 56 deletions

View File

@ -31,8 +31,7 @@ data UpdateOptions = UpdateOptions
}
data Command
= UpdateList UpdateOptions
| Update UpdateOptions Text
= Update UpdateOptions Text
| UpdateBatch UpdateOptions Text
| DeleteDone Bool
| Version
@ -71,10 +70,7 @@ deleteDoneParser =
commandParser :: O.Parser Command
commandParser =
O.hsubparser
( O.command
"update-list"
(O.info (UpdateList <$> updateOptionsParser) (O.progDesc "Update a list of packages"))
<> O.command
(O.command
"update"
(O.info (updateParser) (O.progDesc "Update one package"))
<> O.command
@ -146,10 +142,6 @@ main = do
DeleteDone delete -> do
Git.setupNixpkgs token
deleteDone delete token ghUser
UpdateList UpdateOptions {pr, cve, nixpkgsReview, outpaths, attrpathOpt} -> do
updates <- T.readFile "packages-to-update.txt"
Git.setupNixpkgs token
updateAll (Options pr True ghUser token cve nixpkgsReview outpaths attrpathOpt) updates
Update UpdateOptions {pr, cve, nixpkgsReview, outpaths, attrpathOpt} update -> do
Git.setupNixpkgs token
updatePackage (Options pr False ghUser token cve nixpkgsReview outpaths attrpathOpt) update

View File

@ -14,7 +14,6 @@ module Update
cveReport,
prMessage,
sourceGithubAll,
updateAll,
updatePackage,
)
where
@ -22,7 +21,7 @@ where
import CVE (CVE, cveID, cveLI)
import qualified Check
import Control.Concurrent
import Control.Exception (IOException, catch, bracket)
import Control.Exception (bracket)
import Control.Monad.Writer (execWriterT, tell)
import qualified Data.ByteString.Lazy.Char8 as BSL
import Data.Maybe (fromJust)
@ -45,9 +44,7 @@ import qualified Skiplist
import Utils
( Boundary (..),
Options (..),
URL,
UpdateEnv (..),
Version,
VersionMatcher (..),
branchName,
logDir,
@ -119,13 +116,6 @@ notifyOptions log o = do
log $
[interpolate| [options] github_user: $ghUser, pull_request: $pr, batch_update: $batch, calculate_outpaths: $outpaths, cve_report: $cve, nixpkgs-review: $review, nixpkgs_dir: $npDir, use attrpath: $exactAttrPath|]
updateAll :: Options -> Text -> IO ()
updateAll o updates = do
log <- getLog o
log "New run of nixpkgs-update"
notifyOptions log o
updateLoop o log (parseUpdates updates)
cveAll :: Options -> Text -> IO ()
cveAll o updates = do
let u' = rights $ parseUpdates updates
@ -161,39 +151,6 @@ sourceGithubAll o updates = do
)
u'
updateLoop ::
Options ->
(Text -> IO ()) ->
[Either Text (Text, Version, Version, Maybe URL)] ->
IO ()
updateLoop _ log [] = log "nixpkgs-update finished"
updateLoop o log (Left e : moreUpdates) = do
log e
updateLoop o log moreUpdates
updateLoop o log (Right (pName, oldVer, newVer, url) : moreUpdates) = do
let updateInfoLine = (pName <> " " <> oldVer <> " -> " <> newVer <> fromMaybe "" (fmap (" " <>) url))
log updateInfoLine
let updateEnv = UpdateEnv pName oldVer newVer url o
updated <-
Control.Exception.catch (updatePackageBatch log updateInfoLine updateEnv)
(\e -> do let errMsg = tshow (e :: IOException)
log $ "Caught exception: " <> errMsg
return UpdatePackageFailure)
case updated of
UpdatePackageFailure -> do
log $ "Failed to update: " <> updateInfoLine
if ".0" `T.isSuffixOf` newVer
then
let newNewVersion = fromJust (".0" `T.stripSuffix` newVer)
in updateLoop
o
log
(Right (pName, oldVer, newNewVersion, url) : moreUpdates)
else updateLoop o log moreUpdates
UpdatePackageSuccess -> do
log $ "Success updating: " <> updateInfoLine
updateLoop o log moreUpdates
data UpdatePackageResult = UpdatePackageSuccess | UpdatePackageFailure
-- Arguments this function should have to make it testable:
@ -759,9 +716,9 @@ updatePackage o updateInfo = do
updated <- updatePackageBatch log updateInfoLine updateEnv
case updated of
UpdatePackageFailure -> do
log $ "Failed to update"
log $ "[result] Failed to update " <> updateInfoLine
UpdatePackageSuccess -> do
log $ "Success updating "
log $ "[result] Success updating " <> updateInfoLine
withWorktree :: Text -> Text -> UpdateEnv -> IO a -> IO a