BlueGit

timfa bluegit

Files

bluegit / scripts / publish-aur.sh

publish-aur.sh

fix: haal het AUR-archief van BlueGit
timfa project_87923614_bot_3aff574f6f98414b945a8799374f9092 · pushed by timfa · 3 weeks ago
Passed c66968f4 History
publish-aur.sh 4.2 KiB Download Raw
1#!/usr/bin/env bash
2# Update the AUR package bluegit from the BlueGit source archive of this commit.
3# Pushes ssh://aur@aur.archlinux.org/bluegit.git master. AUR only accepts master.
4set -euo pipefail
5
6ROOT="$(cd "$(dirname "$0")/.." && pwd)"
7# shellcheck source=aur-common.sh
8source "$(dirname "$0")/aur-common.sh"
9
10# pkgver_of_commit is YYYYMMDDHHMMSS in UTC, from the committer time.
11# CI_COMMIT_TIMESTAMP is ISO 8601. Without it, git show -s --format=%cI
12# is the same instant the self-updater uses. The job clock is not a version.
13# BusyBox date does not parse the Z or an offset, so the offset is applied here.
14pkgver_of_commit() {
15 local root="$1"
16 local commit="${2:-}"
17 if [[ -z "$commit" ]]; then
18 commit="$(git_safe "$root" rev-parse HEAD)" || return 1
19 fi
20 [[ "$commit" =~ ^[0-9a-f]{40}$ ]] || { echo "CI_COMMIT_SHA or HEAD is not a full sha" >&2; return 1; }
21 local stamp version
22 if [[ -n "${CI_COMMIT_TIMESTAMP:-}" ]]; then
23 stamp="$CI_COMMIT_TIMESTAMP"
24 else
25 # Zonder || blijft stamp leeg: set -e stopt niet op een falende
26 # command substitution, en utc_digits meldt dan een lege stempel.
27 stamp="$(git_safe "$root" show -s --format=%cI "$commit")" || return 1
28 fi
29 version="$(utc_digits "$stamp")" || return 1
30 [[ "$version" =~ ^[0-9]{14}$ ]] || { echo "pkgver is not a timestamp: ${version:-empty} from ${stamp:-empty}" >&2; return 1; }
31 printf '%s\n' "$version"
32}
33
34# utc_digits turns ISO 8601 into YYYYMMDDHHMMSS in UTC.
35# Accepted forms: 2026-10-22T23:32:33Z, 2026-10-22T23:32:33+01:00, 2026-10-22T23:32:33+0100.
36utc_digits() {
37 local stamp="$1" core off sign hh mm epoch adj
38 if [[ "$stamp" == *Z ]]; then
39 core="${stamp%Z}"
40 off="+00:00"
41 elif [[ "$stamp" =~ ^(.+)([+-][0-9]{2}:[0-9]{2})$ ]]; then
42 core="${BASH_REMATCH[1]}"
43 off="${BASH_REMATCH[2]}"
44 elif [[ "$stamp" =~ ^(.+)([+-][0-9]{4})$ ]]; then
45 core="${BASH_REMATCH[1]}"
46 off="${BASH_REMATCH[2]:0:3}:${BASH_REMATCH[2]:3:2}"
47 else
48 core="$stamp"
49 off="+00:00"
50 fi
51 core="${core%%.*}"
52 core="${core/T/ }"
53 [[ "$core" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}\ [0-9]{2}:[0-9]{2}:[0-9]{2}$ ]] || {
54 echo "pkgver stamp is not ISO 8601: $stamp" >&2
55 return 1
56 }
57 sign="${off:0:1}"
58 hh="${off:1:2}"
59 mm="${off:4:2}"
60 epoch="$(TZ=UTC date -u -d "$core" +%s)" || return 1
61 adj=$((10#$hh * 3600 + 10#$mm * 60))
62 if [[ "$sign" == "+" ]]; then
63 epoch=$((epoch - adj))
64 else
65 epoch=$((epoch + adj))
66 fi
67 TZ=UTC date -u -d "@$epoch" +%Y%m%d%H%M%S
68}
69
70if [[ "${1:-}" == "--rewrite-only" ]]; then
71 rewrite_pkgbuild "$2" "$3" "$4" "$5"
72 exit 0
73fi
74
75if [[ "${1:-}" == "--print-pkgver" ]]; then
76 pkgver_of_commit "$ROOT" "${CI_COMMIT_SHA:-}"
77 exit
78fi
79
80for cmd in git sed sha256sum curl; do
81 command -v "$cmd" >/dev/null || { echo "Missing command: $cmd" >&2; exit 1; }
82done
83
84if [[ -n "${CI_COMMIT_SHA:-}" ]]; then
85 COMMIT="$CI_COMMIT_SHA"
86else
87 COMMIT="$(git_safe "$ROOT" rev-parse HEAD)" || exit 1
88fi
89VERSION="$(pkgver_of_commit "$ROOT" "$COMMIT")"
90
91TMPDIR="${TMPDIR:-/tmp}"
92WORKDIR="$(mktemp -d "$TMPDIR/bluegit-aur-XXXXXX")"
93cleanup() { rm -rf "$WORKDIR"; }
94trap cleanup EXIT
95
96SOURCE_URL="https://git.timfalken.com/timfa/bluegit/-/archive/${COMMIT}/bluegit-${COMMIT}.tar.gz"
97TMP_SOURCE="$WORKDIR/source.tar.gz"
98echo "Checking source tarball: $SOURCE_URL"
99if ! curl -fsSL "$SOURCE_URL" -o "$TMP_SOURCE"; then
100 echo "Could not download $SOURCE_URL" >&2
101 exit 1
102fi
103SOURCE_SHA="$(sha256sum "$TMP_SOURCE" | awk '{print $1}')"
104
105dest="$WORKDIR/bluegit"
106clone_or_init_aur_repo "bluegit" "$dest"
107cd "$dest"
108git config user.name "${AUR_GIT_AUTHOR_NAME:-BlueGit release bot}"
109git config user.email "${AUR_GIT_AUTHOR_EMAIL:-noreply@example.invalid}"
110cp "$ROOT/packaging/aur/PKGBUILD" PKGBUILD
111cp "$ROOT/packaging/aur/bluegit.install" bluegit.install
112rewrite_pkgbuild "$VERSION" "$COMMIT" "$SOURCE_SHA" PKGBUILD
113generate_srcinfo
114
115if git diff --quiet -- PKGBUILD .SRCINFO bluegit.install 2>/dev/null && git rev-parse --verify HEAD >/dev/null 2>&1; then
116 echo "AUR repo already up to date: bluegit ${VERSION}"
117 exit 0
118fi
119
120git add PKGBUILD .SRCINFO bluegit.install
121if git rev-parse --verify HEAD >/dev/null 2>&1; then
122 git commit -m "upstream ${VERSION}"
123else
124 git commit -m "initial import ${VERSION}"
125fi
126git push -u origin master
127echo "AUR updated: bluegit ${VERSION}"