Skip to content

Commit c59966b

Browse files
committed
release: add Homebrew tap publishing workflow
1 parent 4264d57 commit c59966b

File tree

3 files changed

+181
-5
lines changed

3 files changed

+181
-5
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
name: Release + Homebrew
2+
# Maintainer notes:
3+
# - Required secret in this repo: HOMEBREW_TAP_TOKEN
4+
# Token must be able to push to the tap repository.
5+
# - Optional repo variable: HOMEBREW_TAP_REPO (format: owner/repo)
6+
# - If HOMEBREW_TAP_REPO is unset, default tap is <repo-owner>/homebrew-capa.
7+
8+
on:
9+
release:
10+
types: [published]
11+
workflow_dispatch:
12+
inputs:
13+
version:
14+
description: "Version without leading v (e.g. 0.2.0)"
15+
required: true
16+
17+
permissions:
18+
contents: write
19+
20+
jobs:
21+
publish:
22+
runs-on: macos-15
23+
env:
24+
BIN_NAME: capa
25+
REPO_OWNER: ${{ github.repository_owner }}
26+
REPO_NAME: ${{ github.event.repository.name }}
27+
TAP_REPO: ${{ vars.HOMEBREW_TAP_REPO }}
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
32+
- name: Resolve version
33+
id: version
34+
shell: bash
35+
run: |
36+
set -euo pipefail
37+
if [[ "${{ github.event_name }}" == "release" ]]; then
38+
tag="${{ github.event.release.tag_name }}"
39+
version="${tag#v}"
40+
else
41+
version="${{ inputs.version }}"
42+
tag="v${version}"
43+
fi
44+
echo "tag=$tag" >> "$GITHUB_OUTPUT"
45+
echo "version=$version" >> "$GITHUB_OUTPUT"
46+
47+
- name: Build release binary
48+
shell: bash
49+
run: swift build -c release
50+
51+
- name: Validate CLI version matches release version
52+
shell: bash
53+
run: |
54+
set -euo pipefail
55+
expected="${{ steps.version.outputs.version }}"
56+
actual="$(.build/release/${BIN_NAME} --version | tr -d '[:space:]')"
57+
if [[ "$actual" != "$expected" ]]; then
58+
echo "Version mismatch: binary reports '$actual' but release expects '$expected'." >&2
59+
exit 1
60+
fi
61+
62+
- name: Package artifact
63+
id: package
64+
shell: bash
65+
run: |
66+
set -euo pipefail
67+
version="${{ steps.version.outputs.version }}"
68+
artifact="${BIN_NAME}-v${version}-macos-arm64.tar.gz"
69+
mkdir -p dist
70+
cp ".build/release/${BIN_NAME}" "dist/${BIN_NAME}"
71+
tar -C dist -czf "dist/${artifact}" "${BIN_NAME}"
72+
sha=$(shasum -a 256 "dist/${artifact}" | awk '{print $1}')
73+
echo "artifact=$artifact" >> "$GITHUB_OUTPUT"
74+
echo "sha256=$sha" >> "$GITHUB_OUTPUT"
75+
76+
- name: Upload release asset
77+
uses: softprops/action-gh-release@v2
78+
with:
79+
tag_name: ${{ steps.version.outputs.tag }}
80+
files: dist/${{ steps.package.outputs.artifact }}
81+
fail_on_unmatched_files: true
82+
generate_release_notes: false
83+
84+
- name: Select tap repo
85+
id: tap
86+
shell: bash
87+
run: |
88+
set -euo pipefail
89+
# Allow overriding the tap repo via Actions variable.
90+
tap_repo="${TAP_REPO}"
91+
if [[ -z "$tap_repo" ]]; then
92+
# Default tap naming convention for this project.
93+
tap_repo="${REPO_OWNER}/homebrew-capa"
94+
fi
95+
echo "repo=$tap_repo" >> "$GITHUB_OUTPUT"
96+
97+
- name: Update Homebrew tap formula
98+
shell: bash
99+
env:
100+
# PAT used to clone/push the tap repository.
101+
GH_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
102+
run: |
103+
set -euo pipefail
104+
if [[ -z "${GH_TOKEN}" ]]; then
105+
echo "HOMEBREW_TAP_TOKEN is not set; skipping tap update." >&2
106+
exit 1
107+
fi
108+
109+
tag="${{ steps.version.outputs.tag }}"
110+
version="${{ steps.version.outputs.version }}"
111+
artifact="${{ steps.package.outputs.artifact }}"
112+
sha="${{ steps.package.outputs.sha256 }}"
113+
tap_repo="${{ steps.tap.outputs.repo }}"
114+
asset_url="https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/download/${tag}/${artifact}"
115+
116+
temp_dir="$(mktemp -d)"
117+
trap 'rm -rf "$temp_dir"' EXIT
118+
119+
git clone "https://x-access-token:${GH_TOKEN}@github.com/${tap_repo}.git" "$temp_dir/tap"
120+
mkdir -p "$temp_dir/tap/Formula"
121+
122+
scripts/generate_homebrew_formula.sh "$version" "$asset_url" "$sha" > "$temp_dir/tap/Formula/capa.rb"
123+
124+
pushd "$temp_dir/tap" > /dev/null
125+
git config user.name "github-actions[bot]"
126+
git config user.email "github-actions[bot]@users.noreply.github.com"
127+
git add Formula/capa.rb
128+
if git diff --cached --quiet; then
129+
echo "No formula changes to commit."
130+
exit 0
131+
fi
132+
git commit -m "capa ${version}"
133+
git push origin HEAD
134+
popd > /dev/null

README.md

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ Capa is a native macOS screen recorder CLI that produces high-quality, QuickTime
1818
- Apple Silicon (recommended).
1919
- Swift 6.0+ toolchain.
2020

21-
### Build from Source
21+
### Homebrew
2222
```bash
23-
git clone https://github.com/a-hariti/capa.git
24-
cd capa
25-
swift build -c release
26-
cp .build/release/capa /usr/local/bin/capa
23+
brew tap a-hariti/homebrew-capa
24+
brew install capa
25+
```
26+
27+
Upgrade later with:
28+
```bash
29+
brew update
30+
brew upgrade capa
2731
```
2832

2933
## Usage
@@ -88,6 +92,15 @@ capa --project-name "Tutorial-01" --camera 0 --audio mic
8892

8993
## Development
9094

95+
### Build from Source
96+
97+
```bash
98+
git clone https://github.com/a-hariti/capa.git
99+
cd capa
100+
swift build -c release
101+
cp .build/release/capa /usr/local/bin/capa
102+
```
103+
91104
### Project Structure
92105
- `Sources/`:
93106
- `ScreencapWizard.swift`: TUI wizard and CLI entry point.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
if [[ $# -ne 3 ]]; then
5+
echo "Usage: $0 <version> <asset_url> <sha256>" >&2
6+
exit 1
7+
fi
8+
9+
version="$1"
10+
asset_url="$2"
11+
sha256="$3"
12+
13+
cat <<FORMULA
14+
class Capa < Formula
15+
desc "Native macOS screen recorder CLI"
16+
homepage "https://github.com/a-hariti/capa"
17+
url "${asset_url}"
18+
sha256 "${sha256}"
19+
version "${version}"
20+
21+
def install
22+
bin.install "capa"
23+
end
24+
25+
test do
26+
assert_match "Native macOS screen recorder", shell_output("#{bin}/capa --help")
27+
end
28+
end
29+
FORMULA

0 commit comments

Comments
 (0)