-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction_create_release.sh
executable file
·68 lines (52 loc) · 1.59 KB
/
action_create_release.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
67
68
#!/usr/bin/env bash
set -eu
TOKEN=$1
BUILDS=$2
# shellcheck disable=SC2206
builds_array=(${BUILDS//;/ }) # split by ws
echo "Token=$TOKEN"
for build in "${builds_array[@]}"; do
echo "Creating release: $build"
build_artefact="$build.tar.xz"
file "$build_artefact"
ls -lah "$build_artefact"
# make sure it's quoted, so no `-r`
quotedChanges=$(jq "[ .\"$build\" | .changes | .[] | \"[\`\(.[0])\`] \`\(.[1]/1000 | todateiso8601)\` \(.[2])\"] | join(\"\n\")" builds.json)
echo "Build : $build"
echo "Changes: $quotedChanges"
release_config=$(
cat <<-END
{
"tag_name": "$build",
"name": "$build",
"body": $quotedChanges,
"draft": false,
"prerelease": false,
"generate_release_notes": false
}
END
)
echo "Using release config: $release_config"
release_json=$(curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $TOKEN" \
"https://api.github.com/repos/$GITHUB_REPOSITORY/releases" \
-d "$release_config")
release_id=$(echo "$release_json" | jq .id)
if [ "$release_id" == "null" ]; then
echo "Bad response:"
echo "$release_json"
echo "Cannot resolve release id, aborting..."
exit 2
fi
echo "Release created; $release_json"
echo "Release id: $release_id"
curl -X POST \
-H "Content-Type: $(file -b --mime-type "$build_artefact")" \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer $TOKEN" \
-T "$build_artefact" \
"https://uploads.github.com/repos/$GITHUB_REPOSITORY/releases/$release_id/assets?name=$build_artefact" | cat
echo "Release uploaded"
done