summaryrefslogtreecommitdiff
path: root/contrib/cirrus/upload_release_archive.sh
blob: 942255821729943b90dc1d82802f9365d8b3f588 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash

set -eo pipefail

source $(dirname $0)/lib.sh

req_env_var CI UPLDREL_IMAGE CIRRUS_BUILD_ID GOSRC RELEASE_GCPJSON RELEASE_GCPNAME RELEASE_GCPROJECT

[[ "$CI" == "true" ]] || \
    die 56 "$0 must be run under Cirrus-CI to function"

unset PR_OR_BRANCH BUCKET
if [[ -n "$CIRRUS_PR" ]]
then
    PR_OR_BRANCH="pr$CIRRUS_PR"
    BUCKET="libpod-pr-releases"
elif [[ -n "$CIRRUS_BRANCH" ]]
then
    PR_OR_BRANCH="$CIRRUS_BRANCH"
    BUCKET="libpod-$CIRRUS_BRANCH-releases"
else
    die 1 "Expecting either \$CIRRUS_PR or \$CIRRUS_BRANCH to be non-empty."
fi

# Functional local podman required for uploading a release
cd $GOSRC
[[ -n "$(type -P podman)" ]] || \
    make install || \
    die 57 "$0 requires working podman binary on path to function"

TMPF=$(mktemp -p '' $(basename $0)_XXXX.json)
trap "rm -f $TMPF" EXIT
set +x
echo "$RELEASE_GCPJSON" > "$TMPF"
unset RELEASE_GCPJSON

cd $GOSRC
for filename in $(ls -1 *.tar.gz *.zip)
do
    echo "Running podman ... $UPLDREL_IMAGE $filename"
    podman run -i --rm \
        -e "GCPNAME=$RELEASE_GCPNAME" \
        -e "GCPPROJECT=$RELEASE_GCPROJECT" \
        -e "GCPJSON_FILEPATH=$TMPF" \
        -e "REL_ARC_FILEPATH=/tmp/$filename" \
        -e "PR_OR_BRANCH=$PR_OR_BRANCH" \
        -e "BUCKET=$BUCKET" \
        --security-opt label=disable \
        -v "$TMPF:$TMPF:ro" \
        -v "$GOSRC/$filename:/tmp/$filename:ro" \
        $UPLDREL_IMAGE
done