Files
tsunagi/.github/workflows/release.yml
T
Aleksandr Bogomiakov 21b8381fa3 Restore Homebrew publication after stable GitHub releases
The v1.0.2 build published a valid macOS archive, but its release workflow lacked the Homebrew job that published v1.0.0. Restore the job, updater, tests and setup notes from a707076 alongside the existing Arch and OpenArtifact jobs.

Verify the Apple Silicon archive against the published GitHub digest before updating the CLI formula and GUI cask in one tap commit. Skip prereleases and older versions, and retry from the current tap head after a concurrent push. Use the existing HOMEBREW_TAP_TOKEN with the same tap and branch.

On macOS, all three updater tests passed. Exercised the workflow shell with the real v1.0.2 archive, mocked release transport and a local Git remote, including checksum rejection, concurrent updates and retries. Actionlint and ShellCheck passed with the old actionlint runner list exception for ubuntu-26.04. Workspace formatting and strict Clippy passed. All 568 default tests passed with three ignored after enabling loopback for the test run. No live workflow was triggered.
2026-11-25 01:11:33 +02:00

583 lines
23 KiB
YAML

name: Release
# Desktop builds mirror .gitea/workflows/release.yml. GitHub also builds and
# signs the Android APK and attaches all platform packages to the tag with gh.
#
# Every job is gated on `github.server_url == 'https://github.com'`, so this file
# runs only on GitHub. Gitea runs its own copy in .gitea/workflows (which pins
# the older @v3 artifact actions it supports); should a Gitea instance also read
# .github/workflows, the guard skips these jobs there so they never fail on the
# artifact backend or `gh`.
on:
push:
tags: ["v*"]
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
CARGO_NET_RETRY: "10"
jobs:
build:
name: ${{ matrix.asset }}
if: ${{ github.server_url == 'https://github.com' }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-26.04
target: x86_64-unknown-linux-musl
asset: tsunagi-linux-x86_64
archive: tar.gz
zig: true
deb: true
deb_arch: amd64
pkg_arch: x86_64
gnu_target: x86_64-unknown-linux-gnu
- os: ubuntu-latest
target: aarch64-unknown-linux-musl
asset: tsunagi-linux-aarch64
archive: tar.gz
zig: true
deb: true
deb_arch: arm64
pkg_arch: aarch64
# 32-bit ARM with hardware float (ARMv7, `v7l`): single-board and edge
# devices. Statically linked like the others.
- os: ubuntu-latest
target: armv7-unknown-linux-musleabihf
asset: tsunagi-linux-armv7
archive: tar.gz
zig: true
deb: true
deb_arch: armhf
pkg_arch: armv7h
- os: macos-latest
target: aarch64-apple-darwin
asset: tsunagi-macos-aarch64
archive: tar.gz
zig: false
- os: windows-latest
target: x86_64-pc-windows-msvc
asset: tsunagi-windows-x86_64
archive: zip
zig: false
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
# aws-lc-sys (iroh's rustls backend) and the bundled sqlite are C, and the
# musl targets have no prebuilt bindings, so bindgen needs libclang and the
# C build needs cmake. zig is the cross C compiler cargo-zigbuild drives.
- name: Install musl build and packaging tooling
if: matrix.zig
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends cmake clang libclang-dev libarchive-tools zstd
- name: Install zig
if: matrix.zig
uses: mlugg/setup-zig@v2
with:
# Pin a real, archived Zig release. Left unpinned the action resolves
# to the newest version it knows of (a yet-unreleased 0.16.0-dev),
# whose tarball 404s on ziglang.org while the community mirrors flake.
version: 0.14.1
- name: Install cargo-zigbuild
if: matrix.zig
uses: taiki-e/install-action@v2
with:
tool: cargo-zigbuild
- name: Build
shell: bash
run: |
set -euo pipefail
if [[ "${{ matrix.zig }}" == "true" ]]; then
# zig's linker ignores the `-O1` GNU-ld optimization flag Rust passes
# and says so on stderr, which rustc now surfaces as a linker_messages
# warning. It is cosmetic — the binary is correct — so quiet just that
# one lint to keep the musl build log clean. A real link error still
# fails the build.
export RUSTFLAGS="${RUSTFLAGS:-} -A linker_messages"
cargo zigbuild --release --locked --target "${{ matrix.target }}" --bin tsng
else
cargo build --release --locked --target "${{ matrix.target }}" --bin tsng
fi
# The tray GUI. On Linux it is built against glibc (an old baseline for
# portability), not musl: a GUI must dlopen libGL/X11/Wayland at runtime,
# which a static musl binary cannot. macOS and Windows build it natively.
- name: Build the tray GUI
shell: bash
run: |
set -euo pipefail
if [[ "${{ runner.os }}" == "Linux" ]]; then
if [[ -n "${{ matrix.gnu_target }}" ]]; then
# tray-icon links GTK and libappindicator through pkg-config, which
# has no cross story under zig, so the Linux GUI is built natively
# (x86_64 only) against the runner's glibc.
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
libgtk-3-dev libayatana-appindicator3-dev
cargo build --release --locked \
--target "${{ matrix.gnu_target }}" --bin tsunagi-tray
else
echo "no GUI build for ${{ matrix.target }}"
fi
else
cargo build --release --locked --target "${{ matrix.target }}" --bin tsunagi-tray
fi
- name: Package
shell: bash
run: |
set -euo pipefail
version="${GITHUB_REF_NAME#v}"
stage="dist/pkg/${{ matrix.asset }}"
mkdir -p "$stage"
bin="tsng"
[[ "${{ runner.os }}" == "Windows" ]] && bin="tsng.exe"
cp "target/${{ matrix.target }}/release/${bin}" "$stage/"
# The tray GUI alongside it, where it was built (Linux: x86_64 only).
tray="tsunagi-tray"
[[ "${{ runner.os }}" == "Windows" ]] && tray="tsunagi-tray.exe"
if [[ "${{ runner.os }}" == "Linux" ]]; then
if [[ -n "${{ matrix.gnu_target }}" ]]; then
cp "target/${{ matrix.gnu_target }}/release/${tray}" "$stage/"
fi
else
cp "target/${{ matrix.target }}/release/${tray}" "$stage/"
fi
# The top-level README, plus the per-OS install notes and integration
# files, so the archive carries what the platform needs to set up.
cp README.md "$stage/"
case "${{ runner.os }}" in
Linux)
cp dist/linux/tsunagi.service dist/linux/install.sh \
dist/linux/50-tsunagi-resolved.rules "$stage/"
cp dist/linux/README.md "$stage/INSTALL.md"
;;
macOS)
cp dist/macos/cy.hexor.tsunagi.plist "$stage/"
cp dist/macos/README.md "$stage/INSTALL.md"
# The tray as an application bundle, for the Homebrew cask.
bash dist/macos/build-app.sh \
"target/${{ matrix.target }}/release/tsunagi-tray" \
"$version" "$stage/Tsunagi.app"
;;
Windows)
cp dist/windows/README.md "$stage/INSTALL.md"
;;
esac
archive="${{ matrix.asset }}-${version}.${{ matrix.archive }}"
if [[ "${{ matrix.archive }}" == "zip" ]]; then
(cd dist/pkg && 7z a "../../${archive}" "${{ matrix.asset }}")
else
tar -C dist/pkg -czf "${archive}" "${{ matrix.asset }}"
fi
# The Windows installer: the agent as a service, Wintun, the tray and the
# PATH entry in one setup program. Wintun is the signed library from
# wintun.net, pinned by hash so a changed download fails the build.
- name: Build the Windows installer
if: runner.os == 'Windows'
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$version = $env:GITHUB_REF_NAME.TrimStart('v')
Invoke-WebRequest -Uri https://www.wintun.net/builds/wintun-0.14.1.zip -OutFile wintun.zip
$hash = (Get-FileHash wintun.zip -Algorithm SHA256).Hash
if ($hash -ne '07C256185D6EE3652E09FA55C0B673E2624B565E02C4B9091C79CA7D2F24EF51') {
throw "wintun.zip has an unexpected hash: $hash"
}
Expand-Archive wintun.zip -DestinationPath wintun-dl
choco install innosetup -y --no-progress
$iscc = Join-Path ${env:ProgramFiles(x86)} 'Inno Setup 6\ISCC.exe'
$stage = Join-Path $PWD 'dist/pkg/${{ matrix.asset }}'
& $iscc "/DAppVersion=$version" "/DSourceDir=$stage" `
"/DWintunDir=$(Join-Path $PWD 'wintun-dl/wintun/bin/amd64')" `
"/O$PWD" dist/windows/tsunagi.iss
if ($LASTEXITCODE -ne 0) { throw "ISCC failed with $LASTEXITCODE" }
# A dependency-free .deb for the x86_64 and aarch64 Linux builds: it drops
# the static binary, the systemd service and the polkit rule. Built with
# dpkg-deb (present on the runner); see dist/deb/build-deb.sh.
- name: Build the Debian package
if: matrix.deb
shell: bash
run: |
set -euo pipefail
version="${GITHUB_REF_NAME#v}"
bash dist/deb/build-deb.sh \
"target/${{ matrix.target }}/release/tsng" \
"${{ matrix.deb_arch }}" \
"$version" \
"tsunagi_${version}_${{ matrix.deb_arch }}.deb"
# A dependency-free Arch package (.pkg.tar.zst), assembled with bsdtar and
# zstd (no makepkg); same binary, service and polkit rule. See
# dist/arch/build-pkg.sh.
- name: Build the Arch package
if: matrix.pkg_arch
shell: bash
run: |
set -euo pipefail
version="${GITHUB_REF_NAME#v}"
pkgver="${version//-/}"
bash dist/arch/build-pkg.sh \
"target/${{ matrix.target }}/release/tsng" \
"${{ matrix.pkg_arch }}" \
"$version" \
"tsunagi-${pkgver}-1-${{ matrix.pkg_arch }}.pkg.tar.zst"
# The GUI variants: the same agent plus the tray binary and a desktop
# launcher, named tsunagi-gui (conflicting with the headless packages).
- name: Build the GUI packages
if: matrix.gnu_target
shell: bash
run: |
set -euo pipefail
version="${GITHUB_REF_NAME#v}"
pkgver="${version//-/}"
tray="target/${{ matrix.gnu_target }}/release/tsunagi-tray"
bash dist/deb/build-deb.sh \
"target/${{ matrix.target }}/release/tsng" \
"${{ matrix.deb_arch }}" "$version" \
"tsunagi-gui_${version}_${{ matrix.deb_arch }}.deb" "$tray"
bash dist/arch/build-pkg.sh \
"target/${{ matrix.target }}/release/tsng" \
"${{ matrix.pkg_arch }}" "$version" \
"tsunagi-gui-${pkgver}-1-${{ matrix.pkg_arch }}.pkg.tar.zst" "$tray"
- name: Upload the build outputs as run artifacts
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.asset }}
path: |
${{ matrix.asset }}-*.*
*.deb
*.pkg.tar.zst
tsunagi-setup-*.exe
if-no-files-found: error
android:
name: Android ARM64 APK
if: ${{ github.server_url == 'https://github.com' }}
runs-on: ubuntu-24.04
permissions:
contents: read
env:
NDK_VERSION: '30.0.16248370'
BUILD_TOOLS_VERSION: '36.0.0'
steps:
- uses: actions/checkout@v5
with:
persist-credentials: false
- uses: actions/setup-java@v5
with:
distribution: temurin
java-version: '21'
- uses: dtolnay/rust-toolchain@stable
with:
targets: aarch64-linux-android
- uses: Swatinem/rust-cache@v2
with:
key: android-arm64-${{ env.NDK_VERSION }}
- name: Install Android build tools
run: |
"$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" \
'platforms;android-35' "build-tools;$BUILD_TOOLS_VERSION" "ndk;$NDK_VERSION"
echo "ANDROID_NDK_HOME=$ANDROID_HOME/ndk/$NDK_VERSION" >> "$GITHUB_ENV"
cargo install --locked --version 4.1.2 cargo-ndk
- name: Build the ARM64 release APK
run: |
android/gradlew -p android --no-daemon :app:assembleRelease \
"-PtsunagiVersionName=${GITHUB_REF_NAME#v}" "-PtsunagiVersionCode=$GITHUB_RUN_NUMBER"
- name: Sign the APK
id: sign
env:
ANDROID_KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }}
ANDROID_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
run: |
set -euo pipefail
: "${ANDROID_KEYSTORE_BASE64:?Set the ANDROID_KEYSTORE_BASE64 Actions secret}"
: "${ANDROID_KEYSTORE_PASSWORD:?Set the ANDROID_KEYSTORE_PASSWORD Actions secret}"
umask 077
keystore=$(mktemp "$RUNNER_TEMP/tsunagi-keystore.XXXXXXXX")
trap 'rm -f "$keystore"' EXIT
printf '%s' "$ANDROID_KEYSTORE_BASE64" | base64 --decode > "$keystore"
apk="$RUNNER_TEMP/tsunagi-android-${GITHUB_REF_NAME#v}-arm64-v8a.apk"
"$ANDROID_HOME/build-tools/$BUILD_TOOLS_VERSION/apksigner" sign \
--ks "$keystore" --ks-pass env:ANDROID_KEYSTORE_PASSWORD --key-pass env:ANDROID_KEYSTORE_PASSWORD \
--v4-signing-enabled false --out "$apk" android/app/build/outputs/apk/release/app-release-unsigned.apk
echo "apk=$apk" >> "$GITHUB_OUTPUT"
- name: Test the signed APK
env:
APK: ${{ steps.sign.outputs.apk }}
run: |
bash android/test-release-apk.sh "$APK" "${GITHUB_REF_NAME#v}" "$GITHUB_RUN_NUMBER" \
"$ANDROID_HOME/build-tools/$BUILD_TOOLS_VERSION"
- uses: actions/upload-artifact@v7
with:
name: tsunagi-android
path: ${{ steps.sign.outputs.apk }}
if-no-files-found: error
publish:
name: Publish release
needs: [build, android]
if: ${{ github.server_url == 'https://github.com' }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download every build artifact
uses: actions/download-artifact@v8
with:
path: artifacts
- name: Show what was collected
run: find artifacts -type f
- name: Create the release and upload the archives
shell: bash
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ github.ref_name }}
run: |
set -euo pipefail
# download-artifact nests each artifact under its own directory, so
# the archives are artifacts/<asset>/<file>.
mapfile -t files < <(find artifacts -type f \( -name '*.tar.gz' -o -name '*.zip' -o -name '*.deb' -o -name '*.pkg.tar.zst' -o -name 'tsunagi-setup-*.exe' \))
apk="artifacts/tsunagi-android/tsunagi-android-${TAG#v}-arm64-v8a.apk"
[[ -s "$apk" ]] || { echo "::error::Missing release APK at $apk"; exit 1; }
files+=("$apk")
printf 'asset: %s\n' "${files[@]}"
prerelease=()
case "$TAG" in *-*) prerelease=(--prerelease) ;; esac
# Create the release on the first run; on a re-run, add/replace assets
# on the release that is already there.
if gh release view "$TAG" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
gh release upload "$TAG" "${files[@]}" --repo "$GITHUB_REPOSITORY" --clobber
else
gh release create "$TAG" "${files[@]}" \
--repo "$GITHUB_REPOSITORY" \
--title "tsunagi $TAG" \
--generate-notes \
--verify-tag \
"${prerelease[@]}"
fi
notify-arch-repository:
name: Publish packages to the Arch repository
needs: publish
if: ${{ github.server_url == 'https://github.com' }}
runs-on: ubuntu-latest
permissions: {}
steps:
- name: Notify arch_repo of the completed release
shell: bash
env:
GH_TOKEN: ${{ secrets.ARCH_REPO_TOKEN }}
RELEASE_TAG: ${{ github.ref_name }}
run: |
set -euo pipefail
if [[ -z "$GH_TOKEN" ]]; then
echo '::error::Set the ARCH_REPO_TOKEN Actions secret with Contents: write access to house-of-vanity/arch_repo.'
exit 1
fi
jq -n --arg repository "$GITHUB_REPOSITORY" --arg tag "$RELEASE_TAG" \
'{event_type: "new_package", client_payload: {repository: $repository, tag: $tag}}' \
| gh api --method POST repos/house-of-vanity/arch_repo/dispatches --input -
update-homebrew:
name: Update the Homebrew tap
needs: publish
if: github.server_url == 'https://github.com' && github.repository == 'house-of-vanity/tsunagi'
runs-on: ubuntu-latest
permissions:
contents: read
env:
RELEASE_TAG: ${{ github.ref_name }}
steps:
- name: Check the release tag and tap credentials
id: stable
env:
TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
run: |
set -euo pipefail
if [[ ! "$RELEASE_TAG" =~ ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]; then
echo "Skipping Homebrew for non-stable tag $RELEASE_TAG"
exit 0
fi
if [[ -z "$TAP_TOKEN" ]]; then
echo '::error::Set HOMEBREW_TAP_TOKEN with Contents: write access to house-of-vanity/homebrew-tap.'
exit 1
fi
echo "publish=true" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v5
if: steps.stable.outputs.publish == 'true'
with:
persist-credentials: false
- name: Verify the published macOS archive
if: steps.stable.outputs.publish == 'true'
id: archive
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
archive="tsunagi-macos-aarch64-${RELEASE_TAG#v}.tar.gz"
digest=$(gh api "repos/$GITHUB_REPOSITORY/releases/tags/$RELEASE_TAG" \
| jq -er --arg archive "$archive" '
select(.draft == false and .prerelease == false)
| .assets[] | select(.name == $archive and .state == "uploaded")
| .digest | select(type == "string" and test("^sha256:[0-9a-f]{64}$"))
')
gh release download "$RELEASE_TAG" --repo "$GITHUB_REPOSITORY" \
--pattern "$archive" --dir "$RUNNER_TEMP"
hash="${digest#sha256:}"
actual=$(sha256sum "$RUNNER_TEMP/$archive")
if [[ "${actual%% *}" != "$hash" ]]; then
echo "::error::SHA-256 mismatch for $archive."
exit 1
fi
echo "hash=$hash" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v5
if: steps.stable.outputs.publish == 'true'
with:
repository: house-of-vanity/homebrew-tap
ref: main
path: homebrew-tap
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
- name: Update and push the formula and cask
if: steps.stable.outputs.publish == 'true'
env:
ARCHIVE_SHA256: ${{ steps.archive.outputs.hash }}
run: |
set -euo pipefail
# Retry from the latest tap state if another publisher pushes first.
for attempt in 1 2 3; do
git -C homebrew-tap fetch origin main
git -C homebrew-tap checkout --detach --force FETCH_HEAD
python3 .github/scripts/update_homebrew.py homebrew-tap "$RELEASE_TAG" "$ARCHIVE_SHA256"
cd homebrew-tap
ruby -c Formula/tsunagi.rb
ruby -c Casks/tsunagi-gui.rb
if git diff --quiet -- Formula/tsunagi.rb Casks/tsunagi-gui.rb; then
exit 0
fi
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
git add -- Formula/tsunagi.rb Casks/tsunagi-gui.rb
git commit -m "tsunagi ${RELEASE_TAG#v}"
if git push origin HEAD:main; then
exit 0
fi
echo "Push to the Homebrew tap failed on attempt $attempt of 3." >&2
cd ..
done
echo '::error::Could not push the updated formula and cask to the tap.'
exit 1
publish-openartifact:
name: Publish APT and pacman packages
needs: publish
if: github.server_url == 'https://github.com'
runs-on: ubuntu-26.04
permissions:
contents: read
id-token: write
env:
OA_SERVER: https://repo.hexor.cy
APT_SUITE: resolute
steps:
- name: Download packages attached to this release
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release download "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" \
--pattern '*.deb' --pattern '*.pkg.tar.zst' --dir packages
- name: Publish packages
shell: bash
run: |
set -euo pipefail
id_token=$(curl -fsS -G --data-urlencode "audience=$OA_SERVER" \
-H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
"$ACTIONS_ID_TOKEN_REQUEST_URL" | jq -er '.value')
oa_token=$(jq -n --arg token "$id_token" \
'{token:$token,policy:"github-tsunagi-release"}' | \
curl -fsS --json @- "$OA_SERVER/api/v1/auth/oidc/exchange" | jq -er '.access_token')
echo "::add-mask::$oa_token"
auth=(-H "Authorization: Bearer $oa_token")
for file in packages/*.deb packages/*.pkg.tar.zst; do
[[ -f "$file" ]] || { echo "Missing release artifact: $file"; exit 1; }
name=${file##*/}
case "$name" in
*.deb)
arch=$(dpkg-deb -f "$file" Architecture)
status=$(curl -sS -o "$RUNNER_TEMP/oa-upload.json" -w '%{http_code}' \
"${auth[@]}" -F "file=@$file" -F "distribution=$APT_SUITE" -F component=main \
"$OA_SERVER/api/v1/repositories/hexor-apt/debs")
;;
*.pkg.tar.zst)
# Release asset names omit the epoch. OpenArtifact matches the
# upload path against the full version recorded in .PKGINFO.
pkginfo=$(tar --zstd -xOf "$file" .PKGINFO)
pkg=$(sed -n 's/^pkgname = //p' <<< "$pkginfo")
version=$(sed -n 's/^pkgver = //p' <<< "$pkginfo")
arch=$(sed -n 's/^arch = //p' <<< "$pkginfo")
: "${pkg:?missing pkgname}" "${version:?missing pkgver}" "${arch:?missing arch}"
url="$OA_SERVER/repos/hexor-pacman/os/$arch/$pkg-$version-$arch.pkg.tar.zst"
status=$(curl -sS -o "$RUNNER_TEMP/oa-upload.json" -w '%{http_code}' \
"${auth[@]}" -T "$file" "$url")
;;
esac
case "$status" in
2??) echo "Published $name" ;;
409)
# An immutable version may already exist after a partial run.
digest=$(sha256sum "$file" | cut -d ' ' -f1)
if [[ "$name" == *.deb ]]; then
index="$OA_SERVER/repos/hexor-apt/dists/$APT_SUITE/main/binary-$arch/Packages"
curl -fsS "${auth[@]}" "$index" | grep -Fx "SHA256: $digest" >/dev/null || {
echo "Existing $name has different contents or is outside $APT_SUITE" >&2
exit 1
}
else
remote=$(curl -fsS "${auth[@]}" "$url" | sha256sum | cut -d ' ' -f1)
[[ "$remote" == "$digest" ]] || { echo "Different bytes for $name"; exit 1; }
fi
echo "Already published with matching SHA-256: $name"
;;
*) echo "Upload of $name returned HTTP $status" >&2; exit 1 ;;
esac
done