-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.release.sh
executable file
·58 lines (53 loc) · 1.35 KB
/
.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
#!/usr/bin/env bash
set -eu
version="${CI_COMMIT_TAG#v}"
if ! grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$' <<<"$version"; then
echo "Tag has to be valid version number such as v1.0.0!" >&2
exit 1
fi
if [[ "$(cat version)" != "$version" ]]; then
echo "Version file does not contain the correct version!" >&2
exit 1
fi
# Changelog should contain as a first section this release as this is the
# latest release.
changelog="$(awk -v "version=$version" '
BEGIN {
flag = 0
}
/^## / {
if ( $0 !~ "^## \\[" version "\\]" ) {
exit
}
flag = 1
next
}
/^## \[/ && flag {
exit
}
flag {
print
}
' CHANGELOG.md)"
if [ -z "$changelog" ]; then
echo "Changelog is empty." \
"Have you updated the version? Is this the latest version?" >&2
exit 1
fi
declare -a args
while read -r dists; do
for dist in $dists; do
[ -f "$dist" ] || continue # ignore missing / not built
spec="release/${version}/${dist##*/}"
url="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${spec}"
echo "$dist -> $url"
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" \
--upload-file "${dist}" "${url}"
args+=("--assets-link" "{\"name\":\"${dist}\",\"url\":\"${url}\"}")
done
done <<<"$(yq '.build.artifacts.paths[]' .gitlab-ci.yml)"
release-cli create \
--name "Release $version" \
--tag-name "$CI_COMMIT_TAG" \
--description "$changelog" \
"${args[@]}"