|
| 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