-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdistribute-latest-swift
executable file
·75 lines (57 loc) · 1.83 KB
/
distribute-latest-swift
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
#!/bin/bash
set -xe
repository='soloturn/swift-aur'
wfname=$1
branch=master
gh_api=https://api.github.com/repos/${repository}
github() {
curl --header "authorization: Bearer $GITHUB_TOKEN" "$@"
}
latest_run=$(github "${gh_api}/actions/workflows/${wfname}/runs?head_branch=${branch}&status=completed&conclusion=success" \
| jq ".workflow_runs | map(select(.head_branch == \"$branch\")) | sort_by(.run_number) | last")
if [ -z "$latest_run" ] || [ "$latest_run" == "null" ]; then
echo "No successful runs available"
exit 0
fi
artifacts_url=$(echo $latest_run | jq .artifacts_url --raw-output)
head_sha=$(echo $latest_run | jq .head_sha --raw-output)
get_artifact_url() {
local name=$1
github $artifacts_url --fail | jq ".artifacts[] | select(.name == \"$name\") | .archive_download_url" | sed 's/\"//g'
}
download_artifact() {
local name=$1
local artifact_url="$(get_artifact_url $name)"
if [ -z "$artifact_url" ] || [ "$artifact_url" == "null" ]; then
echo "No successfully built artifacts available for $name"
exit 0
fi
github -L "$artifact_url" --fail -o "$name.zip"
}
get_release_id() {
response=$(github ${gh_api}/releases/latest)
echo $response | jq -r .id
}
upload_tarball() {
local release_id=$1
local artifact=$2
local filename=$(basename $artifact)
github -XPOST --fail \
-H "Content-Length: $(stat --printf="%s" "$artifact")" \
-H "Content-Type: application/x-gzip" \
--upload-file "$artifact" \
"https://uploads.github.com/repos/$repository/releases/$release_id/assets?name=$filename"
}
tmp_dir=$(mktemp -d)
pushd $tmp_dir
download_artifact zipped-arch-package
unzip zipped-arch-package.zip
# make sure files is empty if glob fails to match any files
release_id=$(get_release_id)
shopt -s nullglob
for file in *.zst
do
upload_tarball $release_id "$file"
done
popd
# vim:set ts=2 sw=2 et: