BlueGit

ict rusty-teams

Files

rusty-teams / packaging / kvt / release-assets.sh

release-assets.sh

release-assets.sh 2.9 KiB Download Raw
1#!/usr/bin/env bash
2# KVT fork: the release assets of a tag pipeline on git.kvt.nl.
3# release-assets.sh sums <tag> writes dist/kvt/SHA256SUMS
4# release-assets.sh json <tag> <commit> body for POST .../releases/<tag>/assets
5#
6# BlueGit artifacts have fixed paths, so the build jobs write fixed names under
7# dist/kvt and the release gives each file its versioned name. The updater and the
8# AUR package look for exactly these names:
9# rusty-teams-<v>-linux-amd64 bare binary, Linux self-update (linux_release)
10# rusty-teams-<v>-linux-x86_64.tar.gz FHS tree, source of kvt-rusty-teams-bin (linux_release)
11# rusty-teams-<v>-windows-amd64.exe Windows self-update (windows_release)
12# rusty-teams-<v>-windows-arm64.exe Windows on ARM self-update (windows_arm64_release)
13# SHA256SUMS the updater checks these before it installs (checksums)
14# The Linux assets are required (`sums` refuses to run without them). The Windows exe's are
15# optional in this script, but the tag pipeline publishes the release before the Windows
16# jobs run (Tim, t2430u). A second POST to .../releases/<tag>/assets is create-only and
17# returns 409 if the release already exists, so later Windows artifacts cannot be added.
18set -euo pipefail
19DIST="${DIST:-dist/kvt}"
20
21# job|artifact path|asset suffix
22TABLE="linux_release|teams-linux-amd64|-linux-amd64
23linux_release|linux-x86_64.tar.gz|-linux-x86_64.tar.gz
24windows_release|teams-windows-amd64.exe|-windows-amd64.exe
25windows_arm64_release|teams-windows-arm64.exe|-windows-arm64.exe"
26
27present() {
28 local version="${1#v}" job file suffix
29 while IFS='|' read -r job file suffix; do
30 [[ -f "$DIST/$file" ]] && printf '%s|%s|%s\n' "$job" "$DIST/$file" "rusty-teams-$version$suffix"
31 done <<<"$TABLE"
32 return 0
33}
34
35case "${1:-}" in
36 sums)
37 tag="${2:?tag}"
38 for required in teams-linux-amd64:linux_release linux-x86_64.tar.gz:linux_release; do
39 [[ -f "$DIST/${required%%:*}" ]] || { echo "missing $DIST/${required%%:*} (job ${required##*:})" >&2; exit 1; }
40 done
41 : > "$DIST/SHA256SUMS.tmp"
42 while IFS='|' read -r _job path name; do
43 printf '%s %s\n' "$(sha256sum "$path" | awk '{print $1}')" "$name" >> "$DIST/SHA256SUMS.tmp"
44 done < <(present "$tag")
45 mv "$DIST/SHA256SUMS.tmp" "$DIST/SHA256SUMS"
46 cat "$DIST/SHA256SUMS"
47 ;;
48 json)
49 tag="${2:?tag}" commit="${3:?commit}"
50 [[ "$commit" =~ ^[0-9a-f]{40}$ ]] || { echo "commit must be a full sha" >&2; exit 1; }
51 printf '{"commit":"%s","name":"%s","body":"Rusty Teams (KVT) %s","assets":[' "$commit" "$tag" "$tag"
52 while IFS='|' read -r job path name; do
53 printf '{"job":"%s","path":"%s","name":"%s"},' "$job" "$path" "$name"
54 done < <(present "$tag")
55 printf '{"job":"checksums","path":"%s/SHA256SUMS","name":"SHA256SUMS"}]}\n' "$DIST"
56 ;;
57 *) echo "usage: $0 sums <tag> | json <tag> <commit>" >&2; exit 2 ;;
58esac