ci/cron: ability to run check locally (#7690)

This PR allows the script to run without GCP credentials. It will
obviously then skip the bits that require GCP credentials, but that
still leaves it with plenty of things to do.

Because checking all releases can still be quite long (around an hour on
CI, and my personal connection is a bit slower), this also introduces a
new parameter that restricts the number of releases to test.

CHANGELOG_BEGIN
CHANGELOG_END
This commit is contained in:
Gary Verhaegen 2020-10-15 12:18:45 +02:00 committed by GitHub
parent 76919ff33a
commit ad79acdb65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,6 +9,7 @@ import System.FilePath.Posix ((</>))
import qualified Control.Exception
import qualified Control.Monad as Control
import qualified Control.Monad.Extra
import qualified Data.Aeson as JSON
import qualified Data.ByteString.UTF8 as BS
import qualified Data.ByteString.Lazy.UTF8 as LBS
@ -341,26 +342,33 @@ push_to_gcp gcp_credentials bash_lib local_path remote_path = do
"gcs \"$GCRED\" cp \"" <> local_path <> "\" \"" <> remote_path <> "\"",
"'"]
check_releases :: String -> String -> IO ()
check_releases gcp_credentials bash_lib = do
releases <- fetch_gh_paginated "https://api.github.com/repos/digital-asset/daml/releases"
check_releases :: Maybe String -> String -> Maybe Int -> IO ()
check_releases gcp_credentials bash_lib max_releases = do
releases' <- fetch_gh_paginated "https://api.github.com/repos/digital-asset/daml/releases"
let releases = case max_releases of
Nothing -> releases'
Just n -> take n releases'
Data.Foldable.for_ releases (\release -> do
let v = show $ tag release
putStrLn $ "Checking release " <> v <> " ..."
IO.withTempDir $ \temp_dir -> do
download_assets temp_dir release
verify_signatures bash_lib temp_dir v >>= putStrLn
Directory.listDirectory temp_dir >>= Data.Foldable.traverse_ (\f -> do
let gcp_path = "gs://daml-data/releases/" <> v <> "/github/" <> f
exists <- does_backup_exist gcp_credentials bash_lib gcp_path
if exists then do
putStrLn $ gcp_path <> " already exists."
else do
putStr $ gcp_path <> " does not exist; pushing..."
push_to_gcp gcp_credentials bash_lib (temp_dir </> f) gcp_path
putStrLn " done."))
Control.Monad.Extra.whenJust gcp_credentials $ \gcred ->
Directory.listDirectory temp_dir >>= Data.Foldable.traverse_ (\f -> do
let gcp_path = "gs://daml-data/releases/" <> v <> "/github/" <> f
exists <- does_backup_exist gcred bash_lib gcp_path
if exists then do
putStrLn $ gcp_path <> " already exists."
else do
putStr $ gcp_path <> " does not exist; pushing..."
push_to_gcp gcred bash_lib (temp_dir </> f) gcp_path
putStrLn " done."))
data CliArgs = Docs | Check { bash_lib :: String, gcp_credentials :: String }
data CliArgs = Docs
| Check { bash_lib :: String,
gcp_credentials :: Maybe String,
max_releases :: Maybe Int }
parser :: Opt.ParserInfo CliArgs
parser = info "This program is meant to be run by CI cron. You probably don't have sufficient access rights to run it locally."
@ -373,9 +381,14 @@ parser = info "This program is meant to be run by CI cron. You probably don't ha
(Check <$> Opt.strOption (Opt.long "bash-lib"
<> Opt.metavar "PATH"
<> Opt.help "Path to Bash library file.")
<*> Opt.strOption (Opt.long "gcp-creds"
<*> (Opt.optional $
Opt.strOption (Opt.long "gcp-creds"
<> Opt.metavar "CRED_STRING"
<> Opt.help "GCP credentials as a string."))
<*> (Opt.optional $
Opt.option Opt.auto (Opt.long "max-releases"
<> Opt.metavar "INT"
<> Opt.help "Max number of releases to check.")))
main :: IO ()
main = do
@ -384,4 +397,4 @@ main = do
opts <- Opt.execParser parser
case opts of
Docs -> docs
Check { bash_lib, gcp_credentials } -> check_releases gcp_credentials bash_lib
Check { bash_lib, gcp_credentials, max_releases } -> check_releases gcp_credentials bash_lib max_releases