BlueGit

timfa bluegit

Files

bluegit / scripts / publish-aur.sh

publish-aur.sh

fix: reken ISO-8601-pkgver om zonder GNU date
timfa project_87923614_bot_3aff574f6f98414b945a8799374f9092 · pushed by timfa · 3 weeks ago
06b050d1 History
publish-aur.sh 4.0 KiB Download Raw
1#!/usr/bin/env bash
2# Update the AUR package bluegit from the GitLab 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 -C "$root" rev-parse HEAD)"
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 stamp="$(git -C "$root" show -s --format=%cI "$commit")"
26 fi
27 version="$(utc_digits "$stamp")" || return 1
28 [[ "$version" =~ ^[0-9]{14}$ ]] || { echo "pkgver is not a timestamp: ${version:-empty} from ${stamp:-empty}" >&2; return 1; }
29 printf '%s\n' "$version"
30}
31
32# utc_digits turns ISO 8601 into YYYYMMDDHHMMSS in UTC.
33# Accepted forms: 2026-10-22T23:32:33Z, 2026-10-22T23:32:33+01:00, 2026-10-22T23:32:33+0100.
34utc_digits() {
35 local stamp="$1" core off sign hh mm epoch adj
36 if [[ "$stamp" == *Z ]]; then
37 core="${stamp%Z}"
38 off="+00:00"
39 elif [[ "$stamp" =~ ^(.+)([+-][0-9]{2}:[0-9]{2})$ ]]; then
40 core="${BASH_REMATCH[1]}"
41 off="${BASH_REMATCH[2]}"
42 elif [[ "$stamp" =~ ^(.+)([+-][0-9]{4})$ ]]; then
43 core="${BASH_REMATCH[1]}"
44 off="${BASH_REMATCH[2]:0:3}:${BASH_REMATCH[2]:3:2}"
45 else
46 core="$stamp"
47 off="+00:00"
48 fi
49 core="${core%%.*}"
50 core="${core/T/ }"
51 [[ "$core" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}\ [0-9]{2}:[0-9]{2}:[0-9]{2}$ ]] || {
52 echo "pkgver stamp is not ISO 8601: $stamp" >&2
53 return 1
54 }
55 sign="${off:0:1}"
56 hh="${off:1:2}"
57 mm="${off:4:2}"
58 epoch="$(TZ=UTC date -u -d "$core" +%s)" || return 1
59 adj=$((10#$hh * 3600 + 10#$mm * 60))
60 if [[ "$sign" == "+" ]]; then
61 epoch=$((epoch - adj))
62 else
63 epoch=$((epoch + adj))
64 fi
65 TZ=UTC date -u -d "@$epoch" +%Y%m%d%H%M%S
66}
67
68if [[ "${1:-}" == "--rewrite-only" ]]; then
69 rewrite_pkgbuild "$2" "$3" "$4" "$5"
70 exit 0
71fi
72
73if [[ "${1:-}" == "--print-pkgver" ]]; then
74 pkgver_of_commit "$ROOT" "${CI_COMMIT_SHA:-}"
75 exit
76fi
77
78for cmd in git sed sha256sum curl; do
79 command -v "$cmd" >/dev/null || { echo "Missing command: $cmd" >&2; exit 1; }
80done
81
82COMMIT="${CI_COMMIT_SHA:-$(git -C "$ROOT" rev-parse HEAD)}"
83VERSION="$(pkgver_of_commit "$ROOT" "$COMMIT")"
84
85TMPDIR="${TMPDIR:-/tmp}"
86WORKDIR="$(mktemp -d "$TMPDIR/bluegit-aur-XXXXXX")"
87cleanup() { rm -rf "$WORKDIR"; }
88trap cleanup EXIT
89
90SOURCE_URL="https://gitlab.com/Timfa/bluegit/-/archive/${COMMIT}/bluegit-${COMMIT}.tar.gz"
91TMP_SOURCE="$WORKDIR/source.tar.gz"
92echo "Checking source tarball: $SOURCE_URL"
93if ! curl -fsSL "$SOURCE_URL" -o "$TMP_SOURCE"; then
94 echo "Could not download $SOURCE_URL" >&2
95 exit 1
96fi
97SOURCE_SHA="$(sha256sum "$TMP_SOURCE" | awk '{print $1}')"
98
99dest="$WORKDIR/bluegit"
100clone_or_init_aur_repo "bluegit" "$dest"
101cd "$dest"
102git config user.name "${AUR_GIT_AUTHOR_NAME:-BlueGit release bot}"
103git config user.email "${AUR_GIT_AUTHOR_EMAIL:-noreply@example.invalid}"
104cp "$ROOT/packaging/aur/PKGBUILD" PKGBUILD
105cp "$ROOT/packaging/aur/bluegit.install" bluegit.install
106rewrite_pkgbuild "$VERSION" "$COMMIT" "$SOURCE_SHA" PKGBUILD
107generate_srcinfo
108
109if git diff --quiet -- PKGBUILD .SRCINFO bluegit.install 2>/dev/null && git rev-parse --verify HEAD >/dev/null 2>&1; then
110 echo "AUR repo already up to date: bluegit ${VERSION}"
111 exit 0
112fi
113
114git add PKGBUILD .SRCINFO bluegit.install
115if git rev-parse --verify HEAD >/dev/null 2>&1; then
116 git commit -m "upstream ${VERSION}"
117else
118 git commit -m "initial import ${VERSION}"
119fi
120git push -u origin master
121echo "AUR updated: bluegit ${VERSION}"