BlueGit

ict rusty-teams

Files

rusty-teams / packaging / aur-source / publish.sh

publish.sh

publish.sh 4.1 KiB Download Raw
1#!/usr/bin/env bash
2# KVT fork: publish the AUR package kvt-rusty-teams (built from source) for a release tag.
3# Job publish_aur_source in blue-ci-cd.yml. No build and no makepkg: it only fills in the
4# tag and commit in PKGBUILD, writes .SRCINFO and pushes both. Same secrets and approach as
5# packaging/kvt/publish-aur.sh (the -bin package):
6# AUR_SSH_PRIVATE_KEY or AUR_SSH_PRIVATE_KEY_B64 the AUR account's SSH key
7# AUR_GIT_AUTHOR_NAME, AUR_GIT_AUTHOR_EMAIL name and e-mail in the AUR commit
8# Without a key the script says so and exits 0.
9#
10# Usage: packaging/aur-source/publish.sh [tag [commit]] (default: $CI_COMMIT_TAG, $CI_COMMIT_SHA)
11# packaging/aur-source/publish.sh --render <tag> <commit> <out-dir> PKGBUILD and .SRCINFO only
12set -euo pipefail
13
14HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
15PKG="${AUR_PKG:-kvt-rusty-teams}"
16
17# pkgver may not contain '-': v0.6.1-kvt.4 becomes 0.6.1.kvt.4 (vercmp still orders it).
18pkgver_of_tag() {
19 local version="${1#v}"
20 [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+([.-][A-Za-z0-9.]+)?$ ]] || {
21 echo "tag is not v<major>.<minor>.<patch>[-suffix]: $1" >&2
22 return 1
23 }
24 printf '%s\n' "${version//-/.}"
25}
26
27render_pkgbuild() {
28 local tag="$1" commit="$2" out="$3" pkgver
29 [[ "$commit" =~ ^[0-9a-f]{40}$ ]] || { echo "commit must be a full sha" >&2; return 1; }
30 pkgver="$(pkgver_of_tag "$tag")"
31 mkdir -p "$out"
32 sed -e "s/^pkgver=.*/pkgver=${pkgver}/" \
33 -e "s/^pkgrel=.*/pkgrel=1/" \
34 -e "s/^_tag=.*/_tag=${tag}/" \
35 -e "s/^_commit=.*/_commit=${commit}/" \
36 "$HERE/PKGBUILD" > "$out/PKGBUILD"
37}
38
39# .SRCINFO from a PKGBUILD without makepkg (the CI image has no Arch tooling). Same field
40# order and format as `makepkg --printsrcinfo`; tests.sh compares it with the committed file.
41srcinfo() {
42 (
43 set -eu
44 # shellcheck disable=SC1090
45 source "$1"
46 echo "pkgbase = $pkgname"
47 echo " pkgdesc = $pkgdesc"
48 echo " pkgver = $pkgver"
49 echo " pkgrel = $pkgrel"
50 echo " url = $url"
51 local key arr
52 for key in arch license makedepends depends provides conflicts options source sha256sums; do
53 declare -n arr="$key"
54 for value in "${arr[@]}"; do echo " $key = $value"; done
55 done
56 echo
57 echo "pkgname = $pkgname"
58 )
59}
60
61if [[ "${1:-}" == "--render" ]]; then
62 out="${4:?out-dir}"
63 render_pkgbuild "${2:?tag}" "${3:?commit}" "$out"
64 srcinfo "$out/PKGBUILD" > "$out/.SRCINFO"
65 exit 0
66fi
67
68TAG="${1:-${CI_COMMIT_TAG:-}}"
69COMMIT="${2:-${CI_COMMIT_SHA:-}}"
70[[ -n "$TAG" ]] || { echo "No tag: run this in a tag pipeline or pass the tag." >&2; exit 1; }
71[[ -n "$COMMIT" ]] || { echo "No commit: pass it or run this in a tag pipeline." >&2; exit 1; }
72
73if [[ -z "${AUR_SSH_PRIVATE_KEY:-}" && -z "${AUR_SSH_PRIVATE_KEY_B64:-}" ]]; then
74 echo "AUR: geen AUR_SSH_PRIVATE_KEY of AUR_SSH_PRIVATE_KEY_B64 gezet; $PKG wordt overgeslagen."
75 echo "Zet die (beschermde) geheimen op ict/rusty-teams en bescherm het tagpatroon v*."
76 exit 0
77fi
78
79for cmd in git ssh ssh-keygen ssh-keyscan sed; do
80 command -v "$cmd" >/dev/null || { echo "Missing command: $cmd" >&2; exit 1; }
81done
82
83WORKDIR="$(mktemp -d "${TMPDIR:-/tmp}/kvt-aur-source-XXXXXX")"
84trap 'rm -rf "$WORKDIR"' EXIT
85
86"$HERE/../kvt/aur-ssh-setup.sh"
87export GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking=yes -o BatchMode=yes"
88
89dest="$WORKDIR/$PKG"
90remote="ssh://aur@aur.archlinux.org/${PKG}.git"
91echo "Cloning $remote"
92if ! git clone -q "$remote" "$dest"; then
93 echo "AUR repo $PKG does not exist yet; it is created on the first push"
94 mkdir -p "$dest"
95 git -C "$dest" init -q
96 git -C "$dest" checkout -q -b master
97 git -C "$dest" remote add origin "$remote"
98fi
99git config --global --add safe.directory '*'
100
101render_pkgbuild "$TAG" "$COMMIT" "$dest"
102srcinfo "$dest/PKGBUILD" > "$dest/.SRCINFO"
103cat "$dest/.SRCINFO"
104
105cd "$dest"
106git config user.name "${AUR_GIT_AUTHOR_NAME:-KVT release bot}"
107git config user.email "${AUR_GIT_AUTHOR_EMAIL:-hephaestus@noreply.kvt.nl}"
108git add PKGBUILD .SRCINFO
109if git rev-parse --verify -q HEAD >/dev/null && git diff --cached --quiet; then
110 echo "AUR repo already up to date: $PKG $TAG"
111 exit 0
112fi
113git commit -q -m "${TAG}"
114git push -q origin HEAD:master
115echo "AUR updated: $PKG $(pkgver_of_tag "$TAG")"