name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
tag:
description: 'Release tag (e.g. v0.6.1)'
required: true
permissions:
contents: write
jobs:
build:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: macos-latest
target: aarch64-apple-darwin
archive: tar
- os: macos-latest
target: x86_64-apple-darwin
archive: tar
- os: ubuntu-22.04
target: x86_64-unknown-linux-gnu
archive: tar
- os: windows-latest
target: x86_64-pc-windows-msvc
archive: zip
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-${{ matrix.target }}-${{ hashFiles('Cargo.lock') }}
- name: Build
run: cargo build --release --target ${{ matrix.target }} --features rest
- name: Package
shell: bash
run: |
TAG="${{ github.event.inputs.tag || github.ref_name }}"
BIN_DIR="target/${{ matrix.target }}/release"
if [ "${{ matrix.archive }}" = "zip" ]; then
ARCHIVE="afpay-${TAG}-${{ matrix.target }}.zip"
cd "$BIN_DIR" && 7z a "../../../$ARCHIVE" afpay.exe && cd -
else
ARCHIVE="afpay-${TAG}-${{ matrix.target }}.tar.gz"
tar -czf "$ARCHIVE" -C "$BIN_DIR" afpay
fi
echo "TAG=$TAG" >> "$GITHUB_ENV"
echo "ARCHIVE=$ARCHIVE" >> "$GITHUB_ENV"
- name: Upload to release
shell: bash
run: gh release upload "$TAG" "$ARCHIVE" --clobber
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
update-tap:
name: Update Homebrew tap
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout tap
uses: actions/checkout@v4
with:
repository: agentfirstkit/homebrew-tap
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
- name: Compute sha256 and update formula
shell: bash
run: |
TAG="${{ github.event.inputs.tag || github.ref_name }}"
VERSION="${TAG#v}"
BASE="https://github.com/agentfirstkit/agent-first-pay/releases/download/${TAG}"
SHA_AARCH64=$(curl -fsSL "${BASE}/afpay-${TAG}-aarch64-apple-darwin.tar.gz" | sha256sum | awk '{print $1}')
SHA_X86_DARWIN=$(curl -fsSL "${BASE}/afpay-${TAG}-x86_64-apple-darwin.tar.gz" | sha256sum | awk '{print $1}')
SHA_X86_LINUX=$(curl -fsSL "${BASE}/afpay-${TAG}-x86_64-unknown-linux-gnu.tar.gz" | sha256sum | awk '{print $1}')
python3 - "$VERSION" "$TAG" "$BASE" "$SHA_AARCH64" "$SHA_X86_DARWIN" "$SHA_X86_LINUX" <<'PYEOF'
import sys, os
version, tag, base, sha_aarch64, sha_x86_darwin, sha_x86_linux = sys.argv[1:7]
ruby_bin = "#{bin}"
formula = f"""class Afpay < Formula
desc "Agent-first cryptocurrency micropayment tool — multi-network wallet"
homepage "https://github.com/agentfirstkit/agent-first-pay"
version "{version}"
license "MIT"
on_macos do
on_arm do
url "{base}/afpay-{tag}-aarch64-apple-darwin.tar.gz"
sha256 "{sha_aarch64}"
end
on_intel do
url "{base}/afpay-{tag}-x86_64-apple-darwin.tar.gz"
sha256 "{sha_x86_darwin}"
end
end
on_linux do
on_intel do
url "{base}/afpay-{tag}-x86_64-unknown-linux-gnu.tar.gz"
sha256 "{sha_x86_linux}"
end
end
def install
bin.install "afpay"
end
test do
assert_match version.to_s, shell_output("{ruby_bin}/afpay --version")
end
end
"""
os.makedirs("Formula", exist_ok=True)
with open("Formula/afpay.rb", "w") as f:
f.write(formula)
print(f"Updated Formula/afpay.rb to {version}")
PYEOF
- name: Commit and push
shell: bash
run: |
TAG="${{ github.event.inputs.tag || github.ref_name }}"
git config user.email "github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git add Formula/afpay.rb
git diff --cached --quiet || git commit -m "afpay $TAG"
git push
update-scoop:
name: Update Scoop bucket
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout bucket
uses: actions/checkout@v4
with:
repository: agentfirstkit/scoop-bucket
token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
- name: Compute sha256 and update manifest
shell: bash
run: |
TAG="${{ github.event.inputs.tag || github.ref_name }}"
VERSION="${TAG#v}"
BASE="https://github.com/agentfirstkit/agent-first-pay/releases/download/${TAG}"
ARCHIVE="afpay-${TAG}-x86_64-pc-windows-msvc.zip"
SHA=$(curl -fsSL "${BASE}/${ARCHIVE}" | sha256sum | awk '{print $1}')
python3 - "$VERSION" "$TAG" "$BASE" "$ARCHIVE" "$SHA" <<'PYEOF'
import sys, json, os
version, tag, base, archive, sha = sys.argv[1:6]
manifest = {
"version": version,
"description": "Agent-first cryptocurrency micropayment tool — multi-network wallet",
"homepage": "https://github.com/agentfirstkit/agent-first-pay",
"license": "MIT",
"url": f"{base}/{archive}",
"hash": sha,
"bin": "afpay.exe"
}
os.makedirs("bucket", exist_ok=True)
with open("bucket/afpay.json", "w") as f:
json.dump(manifest, f, indent=2, ensure_ascii=False)
f.write("\n")
print(f"Updated bucket/afpay.json to {version}")
PYEOF
- name: Commit and push
shell: bash
run: |
TAG="${{ github.event.inputs.tag || github.ref_name }}"
git config user.email "github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git add bucket/afpay.json
git diff --cached --quiet || git commit -m "afpay $TAG"
git push