forked from ClangBuiltLinux/tc-build
-
Notifications
You must be signed in to change notification settings - Fork 31
/
upload-build.sh
executable file
·103 lines (87 loc) · 3.1 KB
/
upload-build.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env bash
set -veuo pipefail
# Helper function to perform a GitHub API call
function gh_call() {
local req="$1"
local server="$2"
local endpoint="$3"
shift
shift
shift
resp="$(curl -Lfu "$GH_USER:$GH_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
-X "$req" \
"https://$server.github.com/repos/$GH_REL_REPO/$endpoint" \
"$@")" || \
{ ret="$?"; echo "Request failed with exit code $ret:"; cat <<< "$resp"; return $ret; }
cat <<< "$resp"
}
# Helper function to send a Telegram message
function tg_send() {
local msg_type="$1"
shift
local args=()
for arg in "$@"; do
args+=(-F "$arg")
done
curl -sf --form-string chat_id="$TG_CHAT_ID" \
"${args[@]}" \
"https://api.telegram.org/bot$TG_TOKEN/send$msg_type" \
> /dev/null
}
# Generate build info
rel_date="$(date "+%Y%m%d")" # ISO 8601 format
rel_friendly_date="$(date "+%B %-d, %Y")" # "Month day, year" format
clang_version="$(install/bin/clang --version | head -n1 | cut -d' ' -f4)"
# Generate release info
builder_commit="$(git rev-parse HEAD)"
pushd llvm-project
llvm_commit="$(git rev-parse HEAD)"
short_llvm_commit="$(cut -c-8 <<< $llvm_commit)"
popd
llvm_commit_url="https://github.com/llvm/llvm-project/commit/$llvm_commit"
binutils_ver="$(ls | grep "^binutils-" | sed "s/binutils-//g")"
# Update Git repository
git clone "https://$GH_USER:[email protected]/$GH_REL_REPO" rel_repo
pushd rel_repo
rm -fr *
cp -r ../install/* .
# Keep files that aren't part of the toolchain itself
git checkout README.md LICENSE
git add .
git commit -am "Update to $rel_date build
LLVM commit: $llvm_commit_url
binutils version: $binutils_ver
Builder commit: https://github.com/$GH_BUILD_REPO/commit/$builder_commit"
git push
popd
# Delete the existing release with this date, if necessary
resp="$(gh_call GET api "releases/tags/$rel_date" -sS)" && \
old_rel_id="$(jq .id <<< "$resp")" && \
gh_call DELETE api "releases/$old_rel_id" -sS
# Create new release
payload="$(cat <<END
{
"tag_name": "$rel_date",
"target_commitish": "master",
"name": "$rel_friendly_date",
"body": "Automated build of LLVM + Clang $clang_version as of commit [$short_llvm_commit]($llvm_commit_url) and binutils $binutils_ver."
}
END
)"
resp="$(gh_call POST api "releases" --data-binary "@-" -sS <<< "$payload")"
rel_url="$(jq -r .html_url <<< "$resp")"
rel_id="$(jq .id <<< "$resp")"
echo "Release created: $rel_url"
echo "Release ID: $rel_id"
# Send Telegram notification
set +u # we're checking potentially unset variables here
if [[ -n "$TG_CHAT_ID" ]] && [[ -n "$TG_TOKEN" ]]; then
if [[ -n "$GH_RUN_ID" ]]; then
build_desc="[$rel_date build](https://github.com/$GH_BUILD_REPO/actions/runs/$GH_RUN_ID)"
else
build_desc="*$rel_date build*"
fi
set -u
tg_send Message parse_mode=Markdown disable_web_page_preview=true text="$build_desc on LLVM commit [$short_llvm_commit]($llvm_commit_url) is now available: [tarball](https://github.com/$GH_REL_REPO/archive/$rel_date.tar.gz) or [Git repository](https://github.com/$GH_REL_REPO)"
fi