BlueGit

timfa posprint

Files

posprint / scripts / publish-aur.sh

publish-aur.sh

fix: restore tag release downloads and AUR bin publish
timfa project_84475926_bot_764f118ece54db37209130d2bbcb4ae7 · pushed by timfa · 8 weeks ago
65a63b91 History
publish-aur.sh 4.4 KiB Download Raw
1#!/usr/bin/env bash
2set -euo pipefail
3
4ROOT="$(cd "$(dirname "$0")/.." && pwd)"
5VERSION="${1:-}"
6TMPDIR="${TMPDIR:-/tmp}"
7WORKDIR="$(mktemp -d "$TMPDIR/posprint-aur-XXXXXX")"
8cleanup() { rm -rf "$WORKDIR"; }
9trap cleanup EXIT
10
11cd "$ROOT"
12
13if [[ -z "$VERSION" ]]; then
14 VERSION="$(grep '^version = ' Cargo.toml | sed -E 's/.*"([^"]+)"/\1/')"
15fi
16# Tags may be "0.5.1" or "v0.5.1"; GitLab archive URLs and pkgver use the bare version.
17VERSION="${VERSION#v}"
18
19for cmd in git makepkg sed sha256sum curl; do
20 command -v "$cmd" >/dev/null || { echo "Missing command: $cmd" >&2; exit 1; }
21done
22if [[ "$(id -u)" -eq 0 ]]; then
23 command -v runuser >/dev/null || { echo "Missing command: runuser" >&2; exit 1; }
24 command -v useradd >/dev/null || { echo "Missing command: useradd" >&2; exit 1; }
25fi
26
27SOURCE_ARCHIVE_URL="https://gitlab.com/Timfa/posprint/-/archive/${VERSION}/posprint-${VERSION}.tar.gz"
28BIN_TARBALL_NAME="posprint-${VERSION}-x86_64.tar.gz"
29# Durable Generic Package Registry URL (not jobs/artifacts/TAG permalinks — those
30# 404 while the tag pipeline is still running or if a later job failed).
31BIN_PACKAGE_URL="${POSPRINT_GENERIC_PACKAGE_URL:-https://gitlab.com/api/v4/projects/Timfa%2Fposprint/packages/generic/posprint/${VERSION}/${BIN_TARBALL_NAME}}"
32
33generate_srcinfo() {
34 # makepkg refuses root. mktemp parents are 0700 — aurbuild must be able to traverse
35 # $WORKDIR or [[ -d $BUILDDIR ]] fails and mkdir then errors.
36 if [[ "$(id -u)" -eq 0 ]]; then
37 local makepkg_user="${AUR_MAKEPKG_USER:-aurbuild}"
38 local build_tmp
39 if ! id "$makepkg_user" >/dev/null 2>&1; then
40 useradd --system --create-home --shell /bin/bash "$makepkg_user"
41 fi
42 chmod 755 "$WORKDIR"
43 chown -R "$makepkg_user:$makepkg_user" "$PWD"
44 build_tmp="$(runuser -u "$makepkg_user" -- mktemp -d)"
45 # Belt-and-suspenders: force BUILDDIR into a dir aurbuild definitely owns.
46 runuser -u "$makepkg_user" -- env BUILDDIR="$build_tmp" makepkg --printsrcinfo > .SRCINFO
47 rm -rf "$build_tmp"
48 chown -R root:root "$PWD"
49 else
50 makepkg --printsrcinfo > .SRCINFO
51 fi
52}
53
54clone_or_init_aur_repo() {
55 local pkgbase="$1"
56 local dest="$2"
57 local remote="ssh://aur@aur.archlinux.org/${pkgbase}.git"
58
59 echo "Cloning AUR repo: $remote"
60 if git clone "$remote" "$dest"; then
61 return 0
62 fi
63
64 echo "AUR repo ${pkgbase} does not exist yet; creating on first push"
65 mkdir -p "$dest"
66 git -C "$dest" init
67 git -C "$dest" checkout -b master
68 git -C "$dest" remote add origin "$remote"
69}
70
71publish_package() {
72 local pkgbase="$1"
73 local template_dir="$2"
74 local archive_sha="$3"
75 local dest="$WORKDIR/${pkgbase}"
76
77 if [[ ! -f "$ROOT/$template_dir/PKGBUILD" ]]; then
78 echo "Missing $template_dir/PKGBUILD template" >&2
79 exit 1
80 fi
81
82 clone_or_init_aur_repo "$pkgbase" "$dest"
83 cd "$dest"
84
85 git config user.name "${AUR_GIT_AUTHOR_NAME:-posprint release bot}"
86 git config user.email "${AUR_GIT_AUTHOR_EMAIL:-noreply@example.invalid}"
87
88 cp "$ROOT/$template_dir/PKGBUILD" PKGBUILD
89 sed -i "s/^pkgver=.*/pkgver=${VERSION}/" PKGBUILD
90 sed -i "s/^pkgrel=.*/pkgrel=1/" PKGBUILD
91 sed -i "s|^sha256sums=.*|sha256sums=('${archive_sha}')|" PKGBUILD
92
93 generate_srcinfo
94
95 if git diff --quiet -- PKGBUILD .SRCINFO 2>/dev/null && git rev-parse --verify HEAD >/dev/null 2>&1; then
96 echo "AUR repo already up to date: ${pkgbase} ${VERSION}"
97 cd "$ROOT"
98 return 0
99 fi
100
101 git add PKGBUILD .SRCINFO
102 if git rev-parse --verify HEAD >/dev/null 2>&1; then
103 git commit -m "upstream release ${VERSION}"
104 else
105 git commit -m "initial import ${VERSION}"
106 fi
107 git push -u origin master
108
109 echo "AUR updated: ${pkgbase} ${VERSION}"
110 cd "$ROOT"
111}
112
113echo "Checking source tarball: $SOURCE_ARCHIVE_URL"
114TMP_SOURCE="$WORKDIR/source.tar.gz"
115curl -fsSL "$SOURCE_ARCHIVE_URL" -o "$TMP_SOURCE"
116SOURCE_SHA="$(sha256sum "$TMP_SOURCE" | awk '{print $1}')"
117publish_package "posprint" "packaging/aur" "$SOURCE_SHA"
118
119BIN_TARBALL="$ROOT/dist/${BIN_TARBALL_NAME}"
120if [[ -f "$BIN_TARBALL" ]]; then
121 echo "Using local binary tarball: $BIN_TARBALL"
122else
123 echo "Binary tarball not in dist/; downloading $BIN_PACKAGE_URL"
124 mkdir -p "$ROOT/dist"
125 curl -fsSL "$BIN_PACKAGE_URL" -o "$BIN_TARBALL"
126fi
127if [[ ! -s "$BIN_TARBALL" ]]; then
128 echo "Missing binary tarball $BIN_TARBALL (build:linux-arch must produce dist/${BIN_TARBALL_NAME})" >&2
129 exit 1
130fi
131BIN_SHA="$(sha256sum "$BIN_TARBALL" | awk '{print $1}')"
132publish_package "posprint-bin" "packaging/aur-bin" "$BIN_SHA"