-
Notifications
You must be signed in to change notification settings - Fork 25
/
maybe_upload_build_results
executable file
·67 lines (56 loc) · 2.03 KB
/
maybe_upload_build_results
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
################################################################################################
#
# If $B2_ACCOUNT_ID and $B2_APPLICATION_KEY are provided in the environment,
# this will try to upload the file specified on the command line from the
# build/ directory. The exit code will indicate whether the upload worked.
#
# If either of those environment variables isn't provided, this just returns
# prints a message and returns success.
#
################################################################################################
ZIP_TO_UPLOAD="$1"
if test -z "$ZIP_TO_UPLOAD"; then
echo "ERROR: missing name of the zip file to upload"
echo "usage: maybe_upload_build_results build.zip"
exit 1
fi
SRC=build/$ZIP_TO_UPLOAD
if test ! -f $SRC; then
echo "ERROR: file $SRC doesn't exist"
echo "usage: maybe_upload_build_results build.zip"
exit 1
fi
# verify that b2 works
b2v3 version
if test -z "$B2_ACCOUNT_ID" -o -z "$B2_APPLICATION_KEY"; then
echo "NOT uploading build results because no credentials are provided."
echo "this probably isn't a backblaze build."
# it's non-obvious that we would return success, but it's a reasonable outcome.
exit 0
fi
DEST=builds/$ZIP_TO_UPLOAD
if test -z "$B2_UPLOAD_BUCKET"; then
# no B2_UPLOAD_BUCKET was defined, so use the default
B2_UPLOAD_BUCKET=the-b2-sdk-java
echo "B2_UPLOAD_BUCKET not defined, using default bucket $B2_UPLOAD_BUCKET"
fi
echo authorizing account
b2v3 authorize_account $B2_ACCOUNT_ID $B2_APPLICATION_KEY
status=$?
if test $status != "0"; then
echo "failed to authorize with b2 server"
exit $status
fi
# B2 CLI now checks for B2_APPLICATION_KEY/B2_APPLICATION_KEY_ID and expects both
# if either is set, so we unset this here before calling upload_file
unset B2_APPLICATION_KEY
echo uploading $SRC to bucket: $B2_UPLOAD_BUCKET
b2v3 upload_file --contentType application/octet $B2_UPLOAD_BUCKET $SRC $DEST
status=$?
if test $status != "0"; then
echo "failed to upload $SRC to b2"
exit $status
fi
# finally!
exit 0