BlueGit

timfa bluegit

Files

bluegit / scripts / publish-aur.sh

publish-aur.sh

fix: laat publish_aur het sha-archief opnieuw ophalen
timfa project_87923614_bot_3aff574f6f98414b945a8799374f9092 · pushed by timfa · 3 weeks ago
Passed c6641e35 History
publish-aur.sh 5.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
70# fetch_archive URL DEST
71# De eerste poging is meteen. self_update antwoordt 202 zodra de unit start,
72# nog voor pacman de binary vervangt die /-/archive/<sha> uitdeelt.
73# AUR_ARCHIVE_ATTEMPTS (60) en AUR_ARCHIVE_INTERVAL (10s) overbruggen die bouw.
74fetch_archive() {
75 local url="$1" dest="$2"
76 local attempts="${AUR_ARCHIVE_ATTEMPTS:-60}"
77 local pause="${AUR_ARCHIVE_INTERVAL:-10}"
78 local i=1
79 [[ "$attempts" =~ ^[0-9]+$ ]] || attempts=60
80 [[ "$pause" =~ ^[0-9]+$ ]] || pause=10
81 while true; do
82 if curl -fsSL --connect-timeout 5 --max-time 20 "$url" -o "$dest"; then
83 return 0
84 fi
85 rm -f "$dest"
86 if (( i >= attempts )); then
87 echo "Could not download $url" >&2
88 return 1
89 fi
90 echo "Archive not ready (${i}/${attempts}): $url" >&2
91 sleep "$pause"
92 i=$((i + 1))
93 done
94}
95
96if [[ "${1:-}" == "--fetch-only" ]]; then
97 command -v curl >/dev/null || { echo "Missing command: curl" >&2; exit 1; }
98 [[ $# -eq 3 ]] || { echo "usage: publish-aur.sh --fetch-only URL DEST" >&2; exit 1; }
99 fetch_archive "$2" "$3"
100 exit
101fi
102
103if [[ "${1:-}" == "--rewrite-only" ]]; then
104 rewrite_pkgbuild "$2" "$3" "$4" "$5"
105 exit 0
106fi
107
108if [[ "${1:-}" == "--print-pkgver" ]]; then
109 pkgver_of_commit "$ROOT" "${CI_COMMIT_SHA:-}"
110 exit
111fi
112
113for cmd in git sed sha256sum curl; do
114 command -v "$cmd" >/dev/null || { echo "Missing command: $cmd" >&2; exit 1; }
115done
116
117if [[ -n "${CI_COMMIT_SHA:-}" ]]; then
118 COMMIT="$CI_COMMIT_SHA"
119else
120 COMMIT="$(git_safe "$ROOT" rev-parse HEAD)" || exit 1
121fi
122VERSION="$(pkgver_of_commit "$ROOT" "$COMMIT")"
123
124TMPDIR="${TMPDIR:-/tmp}"
125WORKDIR="$(mktemp -d "$TMPDIR/bluegit-aur-XXXXXX")"
126cleanup() { rm -rf "$WORKDIR"; }
127trap cleanup EXIT
128
129SOURCE_URL="https://git.timfalken.com/timfa/bluegit/-/archive/${COMMIT}/bluegit-${COMMIT}.tar.gz"
130TMP_SOURCE="$WORKDIR/source.tar.gz"
131echo "Checking source tarball: $SOURCE_URL"
132if ! fetch_archive "$SOURCE_URL" "$TMP_SOURCE"; then
133 exit 1
134fi
135SOURCE_SHA="$(sha256sum "$TMP_SOURCE" | awk '{print $1}')"
136
137dest="$WORKDIR/bluegit"
138clone_or_init_aur_repo "bluegit" "$dest"
139cd "$dest"
140git config user.name "${AUR_GIT_AUTHOR_NAME:-BlueGit release bot}"
141git config user.email "${AUR_GIT_AUTHOR_EMAIL:-noreply@example.invalid}"
142cp "$ROOT/packaging/aur/PKGBUILD" PKGBUILD
143cp "$ROOT/packaging/aur/bluegit.install" bluegit.install
144rewrite_pkgbuild "$VERSION" "$COMMIT" "$SOURCE_SHA" PKGBUILD
145generate_srcinfo
146
147if git diff --quiet -- PKGBUILD .SRCINFO bluegit.install 2>/dev/null && git rev-parse --verify HEAD >/dev/null 2>&1; then
148 echo "AUR repo already up to date: bluegit ${VERSION}"
149 exit 0
150fi
151
152git add PKGBUILD .SRCINFO bluegit.install
153if git rev-parse --verify HEAD >/dev/null 2>&1; then
154 git commit -m "upstream ${VERSION}"
155else
156 git commit -m "initial import ${VERSION}"
157fi
158git push -u origin master
159echo "AUR updated: bluegit ${VERSION}"