BlueGit

timfa bluegit

fix: reken ISO-8601-pkgver om zonder GNU date

BusyBox date op Alpine weigert een Z of een offset. publish-aur.sh past de offset zelf toe, zodat Steve dezelfde UTC-committertijd publiceert.

Co-authored-by: tim <tim@timfalken.com>

timfa project_87923614_bot_3aff574f6f98414b945a8799374f9092 · pushed by timfa

Authored 2026-10-23 · 3 weeks ago

Hash
06b050d131f8a82c38025e6a298cf40db7f64e13
Parent
2388e414
2 files changed +42 −13
scripts/aur_test.go +4 −12
@@ -493,19 +493,11 @@ func TestPkgverUsesCommitterTime(t *testing.T) {
493 493 if got := printPkgver(t, script, sha, "2026-10-22T23:32:33+01:00"); got != "20261022223233" {
494 494 t.Fatalf("offset: %s", got)
495 495 }
496 if got := printPkgver(t, script, sha, "2026-10-22T00:30:00+02:00"); got != "20261021223000" {
497 t.Fatalf("rollover: %s", got)
498 }
496 499
497 500 got := printPkgver(t, script, sha, "")
498 stamp, err := exec.Command("git", "-C", root, "show", "-s", "--format=%cI", sha).Output()
499 if err != nil {
500 t.Fatal(err)
501 }
502 want, err := exec.Command("date", "-u", "-d", strings.TrimSpace(string(stamp)), "+%Y%m%d%H%M%S").Output()
503 if err != nil {
504 t.Fatal(err)
505 }
506 if got != strings.TrimSpace(string(want)) {
507 t.Fatalf("fallback %s, git show %s", got, strings.TrimSpace(string(want)))
508 }
509 501 updater := exec.Command("git", "-C", root, "show", "-s", "--date=format-local:%Y%m%d%H%M%S", "--format=%cd", sha)
510 502 updater.Env = append(os.Environ(), "TZ=UTC")
511 503 up, err := updater.Output()
@@ -519,7 +511,7 @@ func TestPkgverUsesCommitterTime(t *testing.T) {
519 511 if err != nil {
520 512 t.Fatal(err)
521 513 }
522 if got == strings.TrimSpace(string(now)) && got != strings.TrimSpace(string(want)) {
514 if got == strings.TrimSpace(string(now)) && got != strings.TrimSpace(string(up)) {
523 515 t.Fatal("pkgver volgt de klok van de job")
524 516 }
525 517 }
@@ -493,19 +493,11 @@ func TestPkgverUsesCommitterTime(t *testing.T) {
493 if got := printPkgver(t, script, sha, "2026-10-22T23:32:33+01:00"); got != "20261022223233" {
493 if got := printPkgver(t, script, sha, "2026-10-22T23:32:33+01:00"); got != "20261022223233" {
494 t.Fatalf("offset: %s", got)
494 t.Fatalf("offset: %s", got)
495 }
495 }
496 if got := printPkgver(t, script, sha, "2026-10-22T00:30:00+02:00"); got != "20261021223000" {
497 t.Fatalf("rollover: %s", got)
498 }
496
499
497 got := printPkgver(t, script, sha, "")
500 got := printPkgver(t, script, sha, "")
498 stamp, err := exec.Command("git", "-C", root, "show", "-s", "--format=%cI", sha).Output()
499 if err != nil {
500 t.Fatal(err)
501 }
502 want, err := exec.Command("date", "-u", "-d", strings.TrimSpace(string(stamp)), "+%Y%m%d%H%M%S").Output()
503 if err != nil {
504 t.Fatal(err)
505 }
506 if got != strings.TrimSpace(string(want)) {
507 t.Fatalf("fallback %s, git show %s", got, strings.TrimSpace(string(want)))
508 }
509 updater := exec.Command("git", "-C", root, "show", "-s", "--date=format-local:%Y%m%d%H%M%S", "--format=%cd", sha)
501 updater := exec.Command("git", "-C", root, "show", "-s", "--date=format-local:%Y%m%d%H%M%S", "--format=%cd", sha)
510 updater.Env = append(os.Environ(), "TZ=UTC")
502 updater.Env = append(os.Environ(), "TZ=UTC")
511 up, err := updater.Output()
503 up, err := updater.Output()
@@ -519,7 +511,7 @@ func TestPkgverUsesCommitterTime(t *testing.T) {
519 if err != nil {
511 if err != nil {
520 t.Fatal(err)
512 t.Fatal(err)
521 }
513 }
522 if got == strings.TrimSpace(string(now)) && got != strings.TrimSpace(string(want)) {
514 if got == strings.TrimSpace(string(now)) && got != strings.TrimSpace(string(up)) {
523 t.Fatal("pkgver volgt de klok van de job")
515 t.Fatal("pkgver volgt de klok van de job")
524 }
516 }
525}
517}
scripts/publish-aur.sh +38 −1
@@ -10,6 +10,7 @@ source "$(dirname "$0")/aur-common.sh"
10 10 # pkgver_of_commit is YYYYMMDDHHMMSS in UTC, from the committer time.
11 11 # CI_COMMIT_TIMESTAMP is ISO 8601. Without it, git show -s --format=%cI
12 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.
13 14 pkgver_of_commit() {
14 15 local root="$1"
15 16 local commit="${2:-}"
@@ -23,11 +24,47 @@ pkgver_of_commit() {
23 24 else
24 25 stamp="$(git -C "$root" show -s --format=%cI "$commit")"
25 26 fi
26 version="$(date -u -d "$stamp" +%Y%m%d%H%M%S)"
27 version="$(utc_digits "$stamp")" || return 1
27 28 [[ "$version" =~ ^[0-9]{14}$ ]] || { echo "pkgver is not a timestamp: ${version:-empty} from ${stamp:-empty}" >&2; return 1; }
28 29 printf '%s\n' "$version"
29 30 }
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.
34 utc_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
31 68 if [[ "${1:-}" == "--rewrite-only" ]]; then
32 69 rewrite_pkgbuild "$2" "$3" "$4" "$5"
33 70 exit 0
@@ -10,6 +10,7 @@ source "$(dirname "$0")/aur-common.sh"
10# pkgver_of_commit is YYYYMMDDHHMMSS in UTC, from the committer time.
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
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.
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.
13pkgver_of_commit() {
14pkgver_of_commit() {
14 local root="$1"
15 local root="$1"
15 local commit="${2:-}"
16 local commit="${2:-}"
@@ -23,11 +24,47 @@ pkgver_of_commit() {
23 else
24 else
24 stamp="$(git -C "$root" show -s --format=%cI "$commit")"
25 stamp="$(git -C "$root" show -s --format=%cI "$commit")"
25 fi
26 fi
26 version="$(date -u -d "$stamp" +%Y%m%d%H%M%S)"
27 version="$(utc_digits "$stamp")" || return 1
27 [[ "$version" =~ ^[0-9]{14}$ ]] || { echo "pkgver is not a timestamp: ${version:-empty} from ${stamp:-empty}" >&2; return 1; }
28 [[ "$version" =~ ^[0-9]{14}$ ]] || { echo "pkgver is not a timestamp: ${version:-empty} from ${stamp:-empty}" >&2; return 1; }
28 printf '%s\n' "$version"
29 printf '%s\n' "$version"
29}
30}
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
31if [[ "${1:-}" == "--rewrite-only" ]]; then
68if [[ "${1:-}" == "--rewrite-only" ]]; then
32 rewrite_pkgbuild "$2" "$3" "$4" "$5"
69 rewrite_pkgbuild "$2" "$3" "$4" "$5"
33 exit 0
70 exit 0