ci/bash-lib: fix gcs return code (#7630)

Currently the return code of the function is the return code of the
`eval "$restore_trap"` line, whereas semantically we want the return
code of the `gsutil` call. This is not an issue in most cases as the
`set -e` should kick in, but if the function appears as the condition in
an `if` statement the `-e` flag is suspended.

The main use-case right now is that the daily license check is _not_
uploading artifacts.

CHANGELOG_BEGIN
CHANGELOG_END
This commit is contained in:
Gary Verhaegen 2020-10-11 19:07:22 +02:00 committed by GitHub
parent 664a0c0076
commit 8e905b34c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 6 deletions

View File

@ -30,7 +30,8 @@ steps:
| curl -XPOST -i -H 'Content-Type: application/json' -d @- $channel
}
gcs() {
local args cleanup cmd cred key restore_trap
local args cleanup cmd cred key restore_trap ret
ret=1
cred="$1"
cmd="$2"
@ -45,9 +46,11 @@ steps:
gcloud auth activate-service-account --key-file=$key
BOTO_CONFIG=/dev/null gsutil $cmd "${args[@]}"
ret=$?
eval "$cleanup"
trap - EXIT
eval "$restore_trap"
return $ret
}
gpg_verify() {
local key gpg_dir signature_file res

View File

@ -245,8 +245,6 @@ fetch_s3_versions = do
docs :: IO ()
docs = do
Control.forM_ [IO.stdout, IO.stderr] $
\h -> IO.hSetBuffering h IO.LineBuffering
putStrLn "Checking for new version..."
gh_versions <- fetch_gh_versions
s3_versions <- fetch_s3_versions
@ -318,7 +316,11 @@ does_backup_exist gcp_credentials bash_lib path = do
"set -euo pipefail",
"eval \"$(dev-env/bin/dade assist)\"",
"source \"" <> bash_lib <> "\"",
"if gcs \"" <> gcp_credentials <> "\" ls \"" <> path <> "\"; then",
"GCRED=$(cat <<END",
gcp_credentials,
"END",
")",
"if gcs \"$GCRED\" ls \"" <> path <> "\" >/dev/null; then",
"echo True",
"else",
"echo False",
@ -332,7 +334,11 @@ push_to_gcp gcp_credentials bash_lib local_path remote_path = do
"set -euo pipefail",
"eval \"$(dev-env/bin/dade assist)\"",
"source \"" <> bash_lib <> "\"",
"gcs \"" <> gcp_credentials <> "\" cp \"" <> local_path <> "\" \"" <> remote_path <> "\"",
"GCRED=$(cat <<END",
gcp_credentials,
"END",
")",
"gcs \"$GCRED\" cp \"" <> local_path <> "\" \"" <> remote_path <> "\"",
"'"]
check_releases :: String -> String -> IO ()
@ -351,7 +357,7 @@ check_releases gcp_credentials bash_lib = do
putStrLn $ gcp_path <> " already exists."
else do
putStr $ gcp_path <> " does not exist; pushing..."
push_to_gcp gcp_credentials bash_lib f gcp_path
push_to_gcp gcp_credentials bash_lib (temp_dir </> f) gcp_path
putStrLn " done."))
data CliArgs = Docs | Check { bash_lib :: String, gcp_credentials :: String }
@ -373,6 +379,8 @@ parser = info "This program is meant to be run by CI cron. You probably don't ha
main :: IO ()
main = do
Control.forM_ [IO.stdout, IO.stderr] $
\h -> IO.hSetBuffering h IO.LineBuffering
opts <- Opt.execParser parser
case opts of
Docs -> docs