forked from cri-o/cri-o
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload-artifacts
executable file
·53 lines (47 loc) · 1.82 KB
/
upload-artifacts
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
53
#!/usr/bin/env bash
set -euo pipefail
GITHUB_TOKEN=${GITHUB_TOKEN:-}
GCS_CRIO_SA=${GCS_CRIO_SA:-}
if [[ -z $GCS_CRIO_SA ]]; then
echo "Skipping artifact upload to Google Cloud Bucket (no \$GCS_CRIO_SA set)"
else
echo "Uploading artifacts to Google Cloud Bucket"
echo "$GCS_CRIO_SA" >/tmp/key.json
gcloud auth activate-service-account --key-file=/tmp/key.json
BUCKET=gs://cri-o
gsutil cp -n build/bundle/*.tar.gz $BUCKET/artifacts
# update the latest version marker file for the branch
MARKER=$(git rev-parse --abbrev-ref HEAD)
VERSION=$(git rev-parse HEAD)
# if in detached head state, we assume we're on a tag
if [[ $MARKER == HEAD ]]; then
# use the major.minor as marker
VERSION=$(git describe --tags --exact-match)
MARKER=$(echo "$VERSION" | cut -c 2-5)
fi
echo "$VERSION" >"latest-$MARKER.txt"
gsutil cp "latest-$MARKER.txt" $BUCKET
fi
if TAG=$(git describe --exact-match --tags 2>/dev/null); then
echo "Uploading artifact to GitHub tag $TAG"
if [[ -z $GITHUB_TOKEN ]]; then
echo GITHUB_TOKEN not set, skipping artifact upload to GitHub
else
UPLOAD_URL=$(curl -sSfL https://api.github.com/repos/cri-o/cri-o/releases |
jq -r ".[] | select(.tag_name == \"$TAG\") | .upload_url")
if [[ -z $UPLOAD_URL ]]; then
echo "Unable to find GitHub release for tag $TAG"
exit 1
fi
UPLOAD_URL=${UPLOAD_URL%"{?name,label}"}
for FILE in build/bundle/*.tar.gz; do
curl -f \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: $(file -b --mime-type "$FILE")" \
--data-binary @"$FILE" \
"$UPLOAD_URL?name=$(basename "$FILE")"
done
fi
else
echo "Skipping artifact upload to GitHub (not on a tag)"
fi