Skip to content

Commit 44f103a

Browse files
author
damon
committed
release: auto-publish to AUR + Homebrew on tag, bump v1.2.0
Add publish job to release workflow that pushes to AUR (batdoc, batdoc-bin) and Homebrew tap after GitHub release is created. Uses dedicated SSH deploy keys via AUR_SSH_KEY and TAP_SSH_KEY secrets. Shared logic lives in pkg/publish-aur.sh which also works locally. Fix batdoc-bin debug package conflict.
1 parent dd5451a commit 44f103a

6 files changed

Lines changed: 233 additions & 6 deletions

File tree

.github/workflows/release.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,35 @@ jobs:
132132
*.rpm
133133
*.apk
134134
*.pkg.tar.zst
135+
136+
publish:
137+
needs: release
138+
runs-on: ubuntu-latest
139+
140+
steps:
141+
- uses: actions/checkout@v4
142+
143+
- name: Configure SSH + Git
144+
run: |
145+
mkdir -p ~/.ssh
146+
if [[ -n "${AUR_SSH_KEY:-}" ]]; then
147+
echo "$AUR_SSH_KEY" | base64 -d > ~/.ssh/aur
148+
chmod 600 ~/.ssh/aur
149+
printf 'Host aur.archlinux.org\n IdentityFile ~/.ssh/aur\n User aur\n StrictHostKeyChecking accept-new\n' >> ~/.ssh/config
150+
fi
151+
if [[ -n "${TAP_SSH_KEY:-}" ]]; then
152+
echo "$TAP_SSH_KEY" | base64 -d > ~/.ssh/tap
153+
chmod 600 ~/.ssh/tap
154+
printf 'Host github-tap\n HostName github.com\n IdentityFile ~/.ssh/tap\n User git\n StrictHostKeyChecking accept-new\n' >> ~/.ssh/config
155+
git config --global url."git@github-tap:daemonp/homebrew-tap".insteadOf "git@github.com:daemonp/homebrew-tap.git"
156+
fi
157+
git config --global user.name "Damon Petta"
158+
git config --global user.email "d@disassemble.net"
159+
env:
160+
AUR_SSH_KEY: ${{ secrets.AUR_SSH_KEY }}
161+
TAP_SSH_KEY: ${{ secrets.TAP_SSH_KEY }}
162+
163+
- name: Publish to AUR + Homebrew
164+
run: ./pkg/publish-aur.sh
165+
env:
166+
GH_TOKEN: ${{ github.token }}

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "batdoc"
3-
version = "1.0.1"
3+
version = "1.2.0"
44
edition = "2021"
55
description = "cat(1) for doc, docx, xls, xlsx, pptx, and pdf -- renders to markdown with bat"
66
license = "MIT"

pkg/arch-bin/.SRCINFO

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
pkgbase = batdoc-bin
22
pkgdesc = cat(1) for doc, docx, xls, xlsx, pptx, and pdf -- renders to markdown with bat. Pre-compiled.
3-
pkgver = 1.0.0
3+
pkgver = 1.0.1
44
pkgrel = 1
55
url = https://github.com/daemonp/batdoc
66
arch = x86_64
77
arch = aarch64
88
license = MIT
99
provides = batdoc
1010
conflicts = batdoc
11-
source_x86_64 = https://github.com/daemonp/batdoc/releases/download/v1.0.0/batdoc_1.0.0_x86_64.tar.gz
11+
conflicts = batdoc-debug
12+
options = !debug
13+
source_x86_64 = https://github.com/daemonp/batdoc/releases/download/v1.0.1/batdoc_1.0.1_x86_64.tar.gz
1214
sha256sums_x86_64 = SKIP
13-
source_aarch64 = https://github.com/daemonp/batdoc/releases/download/v1.0.0/batdoc_1.0.0_aarch64.tar.gz
15+
source_aarch64 = https://github.com/daemonp/batdoc/releases/download/v1.0.1/batdoc_1.0.1_aarch64.tar.gz
1416
sha256sums_aarch64 = SKIP
1517

1618
pkgname = batdoc-bin

pkg/arch-bin/PKGBUILD

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ url='https://github.com/daemonp/batdoc'
99
license=('MIT')
1010
depends=()
1111
provides=('batdoc')
12-
conflicts=('batdoc')
12+
conflicts=('batdoc' 'batdoc-debug')
13+
options=('!debug')
1314

1415
source_x86_64=("${url}/releases/download/v${pkgver}/batdoc_${pkgver}_x86_64.tar.gz")
1516
source_aarch64=("${url}/releases/download/v${pkgver}/batdoc_${pkgver}_aarch64.tar.gz")

pkg/publish-aur.sh

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Publish batdoc and batdoc-bin to AUR + Homebrew tap.
4+
#
5+
# Reads the version from Cargo.toml, downloads the release assets,
6+
# computes checksums, updates PKGBUILDs/.SRCINFOs/Formula, and pushes.
7+
#
8+
# Prerequisites:
9+
# - A GitHub release for the version must already exist
10+
# - SSH keys registered with aur.archlinux.org (or skip AUR)
11+
# - Push access to daemonp/homebrew-tap (or skip Homebrew)
12+
# - gh CLI authenticated
13+
#
14+
# Usage:
15+
# ./pkg/publish-aur.sh # uses version from Cargo.toml
16+
# ./pkg/publish-aur.sh 1.2.3 # explicit version override
17+
18+
set -euo pipefail
19+
20+
REPO="daemonp/batdoc"
21+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
22+
WORK="$(mktemp -d)"
23+
trap 'rm -rf "$WORK"' EXIT
24+
25+
# ---------------------------------------------------------------------------
26+
# Resolve version
27+
# ---------------------------------------------------------------------------
28+
if [[ ${1:-} ]]; then
29+
VERSION="$1"
30+
else
31+
VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' "$SCRIPT_DIR/../Cargo.toml")
32+
fi
33+
TAG="v$VERSION"
34+
35+
echo "==> Publishing batdoc $VERSION ($TAG)"
36+
37+
# ---------------------------------------------------------------------------
38+
# Verify the GitHub release exists
39+
# ---------------------------------------------------------------------------
40+
echo "--- Checking GitHub release $TAG ..."
41+
if ! gh release view "$TAG" --repo "$REPO" >/dev/null 2>&1; then
42+
echo "ERROR: GitHub release $TAG not found." >&2
43+
echo "Tag and push first: git tag $TAG && git push origin master $TAG" >&2
44+
exit 1
45+
fi
46+
47+
# ---------------------------------------------------------------------------
48+
# Download release assets & source tarball, compute checksums
49+
# ---------------------------------------------------------------------------
50+
echo "--- Downloading assets ..."
51+
52+
# Source tarball (for batdoc + homebrew)
53+
curl -sL "https://github.com/$REPO/archive/$TAG.tar.gz" -o "$WORK/source.tar.gz"
54+
55+
# Binary tarballs (for batdoc-bin)
56+
gh release download "$TAG" --repo "$REPO" \
57+
--pattern "batdoc_${VERSION}_x86_64.tar.gz" \
58+
--pattern "batdoc_${VERSION}_aarch64.tar.gz" \
59+
--dir "$WORK"
60+
61+
echo "--- Computing checksums ..."
62+
63+
SOURCE_B2=$(b2sum "$WORK/source.tar.gz" | awk '{print $1}')
64+
SOURCE_SHA256=$(sha256sum "$WORK/source.tar.gz" | awk '{print $1}')
65+
66+
BIN_X86_SHA256=$(sha256sum "$WORK/batdoc_${VERSION}_x86_64.tar.gz" | awk '{print $1}')
67+
BIN_ARM_SHA256=$(sha256sum "$WORK/batdoc_${VERSION}_aarch64.tar.gz" | awk '{print $1}')
68+
69+
echo " source b2sum: $SOURCE_B2"
70+
echo " source sha256: $SOURCE_SHA256"
71+
echo " bin x86_64 sha256: $BIN_X86_SHA256"
72+
echo " bin aarch64 sha256: $BIN_ARM_SHA256"
73+
74+
# ---------------------------------------------------------------------------
75+
# Helper: clone an AUR repo, apply changes, commit, push
76+
# ---------------------------------------------------------------------------
77+
aur_publish() {
78+
local pkg="$1" msg="$2"
79+
local aur_dir="$WORK/aur-$pkg"
80+
81+
echo "--- Updating AUR: $pkg ..."
82+
83+
if ! git clone "ssh://aur@aur.archlinux.org/$pkg.git" "$aur_dir" 2>/dev/null; then
84+
echo " WARNING: could not clone AUR repo (missing SSH key?) — skipping $pkg"
85+
return 0
86+
fi
87+
88+
# Copy updated files (caller must have written them to $WORK/$pkg/)
89+
cp "$WORK/$pkg/PKGBUILD" "$aur_dir/PKGBUILD"
90+
cp "$WORK/$pkg/.SRCINFO" "$aur_dir/.SRCINFO"
91+
92+
git -C "$aur_dir" add PKGBUILD .SRCINFO
93+
if git -C "$aur_dir" diff --cached --quiet; then
94+
echo " (no changes — skipping)"
95+
return
96+
fi
97+
git -C "$aur_dir" commit -m "$msg"
98+
git -C "$aur_dir" push origin master
99+
echo " pushed $pkg"
100+
}
101+
102+
# ---------------------------------------------------------------------------
103+
# 1. AUR: batdoc (build-from-source)
104+
# ---------------------------------------------------------------------------
105+
mkdir -p "$WORK/batdoc"
106+
107+
sed -e "s/^pkgver=.*/pkgver=$VERSION/" \
108+
-e "s/^pkgrel=.*/pkgrel=1/" \
109+
-e "s/^b2sums=.*/b2sums=('$SOURCE_B2')/" \
110+
"$SCRIPT_DIR/arch/PKGBUILD" > "$WORK/batdoc/PKGBUILD"
111+
112+
cat > "$WORK/batdoc/.SRCINFO" << EOF
113+
pkgbase = batdoc
114+
pkgdesc = cat(1) for doc, docx, xls, xlsx, pptx, and pdf -- renders to markdown with bat
115+
pkgver = $VERSION
116+
pkgrel = 1
117+
url = https://github.com/$REPO
118+
arch = x86_64
119+
license = MIT
120+
makedepends = cargo
121+
depends = gcc-libs
122+
depends = glibc
123+
source = batdoc-${VERSION}.tar.gz::https://github.com/$REPO/archive/$TAG.tar.gz
124+
b2sums = $SOURCE_B2
125+
126+
pkgname = batdoc
127+
EOF
128+
129+
aur_publish "batdoc" "batdoc ${VERSION}-1: update to $TAG"
130+
131+
# ---------------------------------------------------------------------------
132+
# 2. AUR: batdoc-bin (pre-compiled)
133+
# ---------------------------------------------------------------------------
134+
mkdir -p "$WORK/batdoc-bin"
135+
136+
sed -e "s/^pkgver=.*/pkgver=$VERSION/" \
137+
-e "s/^pkgrel=.*/pkgrel=1/" \
138+
-e "s/^sha256sums_x86_64=.*/sha256sums_x86_64=('$BIN_X86_SHA256')/" \
139+
-e "s/^sha256sums_aarch64=.*/sha256sums_aarch64=('$BIN_ARM_SHA256')/" \
140+
"$SCRIPT_DIR/arch-bin/PKGBUILD" > "$WORK/batdoc-bin/PKGBUILD"
141+
142+
cat > "$WORK/batdoc-bin/.SRCINFO" << EOF
143+
pkgbase = batdoc-bin
144+
pkgdesc = cat(1) for doc, docx, xls, xlsx, pptx, and pdf -- renders to markdown with bat. Pre-compiled.
145+
pkgver = $VERSION
146+
pkgrel = 1
147+
url = https://github.com/$REPO
148+
arch = x86_64
149+
arch = aarch64
150+
license = MIT
151+
provides = batdoc
152+
conflicts = batdoc
153+
conflicts = batdoc-debug
154+
options = !debug
155+
source_x86_64 = https://github.com/$REPO/releases/download/$TAG/batdoc_${VERSION}_x86_64.tar.gz
156+
sha256sums_x86_64 = $BIN_X86_SHA256
157+
source_aarch64 = https://github.com/$REPO/releases/download/$TAG/batdoc_${VERSION}_aarch64.tar.gz
158+
sha256sums_aarch64 = $BIN_ARM_SHA256
159+
160+
pkgname = batdoc-bin
161+
EOF
162+
163+
aur_publish "batdoc-bin" "batdoc-bin ${VERSION}-1: update to $TAG"
164+
165+
# ---------------------------------------------------------------------------
166+
# 3. Homebrew tap
167+
# ---------------------------------------------------------------------------
168+
echo "--- Updating Homebrew tap ..."
169+
TAP_DIR="$WORK/homebrew-tap"
170+
171+
if ! git clone "git@github.com:daemonp/homebrew-tap.git" "$TAP_DIR" 2>/dev/null; then
172+
echo " WARNING: could not clone homebrew-tap (missing credentials?) — skipping"
173+
else
174+
sed -e "s|url \".*\"|url \"https://github.com/$REPO/archive/refs/tags/$TAG.tar.gz\"|" \
175+
-e "s|sha256 \".*\"|sha256 \"$SOURCE_SHA256\"|" \
176+
"$SCRIPT_DIR/homebrew/batdoc.rb" > "$TAP_DIR/Formula/batdoc.rb"
177+
178+
git -C "$TAP_DIR" add Formula/batdoc.rb
179+
if git -C "$TAP_DIR" diff --cached --quiet; then
180+
echo " (no changes — skipping)"
181+
else
182+
git -C "$TAP_DIR" commit -m "batdoc $VERSION"
183+
git -C "$TAP_DIR" push origin main
184+
echo " pushed homebrew-tap"
185+
fi
186+
fi
187+
188+
# ---------------------------------------------------------------------------
189+
# Done
190+
# ---------------------------------------------------------------------------
191+
echo ""
192+
echo "==> Done publishing batdoc $VERSION"

0 commit comments

Comments
 (0)