forked from direnv/direnv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdist-push
executable file
·86 lines (74 loc) · 2.12 KB
/
dist-push
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env bash
#
# Upload binary artifacts when a new release is made.
#
# Usage: ./script/dist-push [<tag>]
#
# Depends on: bash, coreutils, jq, curl
set -euo pipefail
# Ensure that the GITHUB_TOKEN secret is included
if [[ -z "${GITHUB_TOKEN:-}" ]]; then
echo "Set the GITHUB_TOKEN env variable."
exit 1
fi
# Prepare the headers for our curl-command.
AUTH_HEADER="Authorization: token ${GITHUB_TOKEN}"
# Set the github repository in CI
: "${GITHUB_REPOSITORY:=direnv/direnv}"
# Create the correct Upload URL.
if [[ -n "${1:-}" ]]; then
RELEASE_ID=$(curl -sfL \
-H "${AUTH_HEADER}" \
"https://api.github.com/repos/$GITHUB_REPOSITORY/releases/tags/$1" \
| jq .id)
else
# if not tag is given, assume we are in CI
RELEASE_ID=$(jq --raw-output '.release.id' "$GITHUB_EVENT_PATH")
fi
# start from the project root
cd "$(dirname "$0")/.."
# make sure we have all the dist files
make dist
# For each matching file..
for file in dist/*; do
echo "Processing '${file}'"
filename=$(basename "${file}")
upload_url="https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets?name=${filename}"
echo "Upload URL is '${upload_url}'"
# Generate a temporary file.
tmp=$(mktemp)
# Upload the artifact - capturing HTTP response-code in our output file.
if ! response=$(
curl \
-sSL \
-XPOST \
-H "${AUTH_HEADER}" \
--upload-file "${file}" \
--header "Content-Type:application/octet-stream" \
--write-out "%{http_code}" \
--output "$tmp" \
"${upload_url}"
); then
echo "**********************************"
echo " curl command did not return zero."
echo " Aborting"
echo "**********************************"
cat "$tmp"
rm "$tmp"
exit 1
fi
# If upload is not successful, we must abort
if [[ $response -ge 400 ]]; then
echo "***************************"
echo " upload was not successful."
echo " Aborting"
echo " HTTP status is $response"
echo "**********************************"
cat "$tmp"
rm "$tmp"
exit 1
fi
# Show pretty output, since we already have jq
jq . <"$tmp"
rm "$tmp"
done