forked from esirplayground/AutoBuild-OpenWrt
-
Notifications
You must be signed in to change notification settings - Fork 1
/
upload2release.sh
67 lines (52 loc) · 1.85 KB
/
upload2release.sh
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
#!/bin/bash
#set -e
#set -o pipefail
# Ensure that the GITHUB_TOKEN secret is included
if [[ -z "$GITHUB_TOKEN" ]]; then
echo "Set the GITHUB_TOKEN env variable."
exit 1
fi
# Only upload to non-draft releases
IS_DRAFT=$(jq --raw-output '.release.draft' $GITHUB_EVENT_PATH)
if [ "$IS_DRAFT" = true ]; then
echo "This is a draft, so nothing to do!"
exit 0
fi
# Build the Upload URL from the various pieces
echo GITHUB_EVENT_PATH = $GITHUB_EVENT_PATH
cat $GITHUB_EVENT_PATH
#RELEASE_ID=$(jq --raw-output '.release.id' $GITHUB_EVENT_PATH)
#echo RELEASE_ID = $RELEASE_ID
#curl -s --fail -H "Authorization: token ${GITHUB_TOKEN}" "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases"
RELEASE_ID=$(curl -s --fail \
-H "Authorization: token ${GITHUB_TOKEN}" \
"https://api.github.com/repos/${GITHUB_REPOSITORY}/releases" |
jq --raw-output ".[0] |.tag_name ")
echo RELEASE_ID = $RELEASE_ID
if [[ -z "${RELEASE_ID}" ]]; then
echo "There was no release ID in the GitHub event. Are you using the release event type?"
exit 1
fi
# Prepare the headers
AUTH_HEADER="Authorization: token ${GITHUB_TOKEN}"
CONTENT_TYPE_HEADER="Content-Type: application/zip"
#CONTENT_LENGTH_HEADER="Content-Length: $(stat -c%s "${1}")"
find /lede/bin/ -name '*' -type f -exec bash -c 'echo "$1" | tr / _ ' - {} \; | xargs -I % \
curl --connect-timeout 20 --retry 5 \
-sSL \
-XPOST \
-H "${AUTH_HEADER}" \
-H "${CONTENT_TYPE_HEADER}" \
https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets?name=%
#FILENAME=$(basename $1)
#UPLOAD_URL="https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets?name=${FILENAME}"
#echo "$UPLOAD_URL"
## Upload the file
#curl \
# -sSL \
# -XPOST \
# -H "${AUTH_HEADER}" \
# -H "${CONTENT_LENGTH_HEADER}" \
# -H "${CONTENT_TYPE_HEADER}" \
# --upload-file "${1}" \
# "${UPLOAD_URL}"