-
Notifications
You must be signed in to change notification settings - Fork 0
417 lines (361 loc) · 13.4 KB
/
release.yml
File metadata and controls
417 lines (361 loc) · 13.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
tag:
description: "Release tag (e.g., v0.1.0)"
required: true
env:
CARGO_TERM_COLOR: always
jobs:
# ==========================================================================
# Create release
# ==========================================================================
create-release:
name: Create Release
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
version: ${{ steps.get_version.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: Get version
id: get_version
run: |
if [ -n "${{ github.event.inputs.tag }}" ]; then
VERSION="${{ github.event.inputs.tag }}"
else
VERSION="${GITHUB_REF#refs/tags/}"
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "Version: ${VERSION}"
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.get_version.outputs.version }}
name: Release ${{ steps.get_version.outputs.version }}
draft: true
prerelease: ${{ contains(steps.get_version.outputs.version, '-') }}
generate_release_notes: true
# ==========================================================================
# Build binaries
# ==========================================================================
build-binaries:
name: Build (${{ matrix.target }})
needs: create-release
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
# Linux x86_64 (glibc)
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
archive: tar.gz
# Linux x86_64 (musl - static)
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
archive: tar.gz
# Linux ARM64
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
archive: tar.gz
# macOS x86_64
- target: x86_64-apple-darwin
os: macos-latest
archive: tar.gz
# macOS ARM64 (Apple Silicon)
- target: aarch64-apple-darwin
os: macos-latest
archive: tar.gz
# Windows x86_64
- target: x86_64-pc-windows-msvc
os: windows-latest
archive: zip
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross-compilation tools (Linux ARM64)
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
- name: Install musl tools
if: matrix.target == 'x86_64-unknown-linux-musl'
run: |
sudo apt-get update
sudo apt-get install -y musl-tools
- name: Cache cargo
uses: Swatinem/rust-cache@v2
with:
key: release-${{ matrix.target }}
- name: Build release binary
run: cargo build --release --target ${{ matrix.target }}
env:
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
- name: Prepare archive (Unix)
if: matrix.os != 'windows-latest'
run: |
ARCHIVE_NAME="apc-${{ needs.create-release.outputs.version }}-${{ matrix.target }}"
mkdir -p "${ARCHIVE_NAME}"
cp "target/${{ matrix.target }}/release/apc" "${ARCHIVE_NAME}/"
cp Readme.md LICENSE* "${ARCHIVE_NAME}/" 2>/dev/null || true
tar -czvf "${ARCHIVE_NAME}.tar.gz" "${ARCHIVE_NAME}"
echo "ARCHIVE_NAME=${ARCHIVE_NAME}.tar.gz" >> $GITHUB_ENV
- name: Prepare archive (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
$ARCHIVE_NAME = "apc-${{ needs.create-release.outputs.version }}-${{ matrix.target }}"
New-Item -ItemType Directory -Force -Path $ARCHIVE_NAME
Copy-Item "target/${{ matrix.target }}/release/apc.exe" -Destination "$ARCHIVE_NAME/"
Copy-Item "Readme.md" -Destination "$ARCHIVE_NAME/" -ErrorAction SilentlyContinue
Compress-Archive -Path $ARCHIVE_NAME -DestinationPath "$ARCHIVE_NAME.zip"
echo "ARCHIVE_NAME=$ARCHIVE_NAME.zip" >> $env:GITHUB_ENV
- name: Upload release asset
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.create-release.outputs.version }}
files: ${{ env.ARCHIVE_NAME }}
# ==========================================================================
# Build Python wheels
# ==========================================================================
build-wheels:
name: Build Wheels (${{ matrix.os }})
needs: create-release
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Install maturin
run: pip install maturin
- name: Build wheels
run: |
maturin build --release --strip
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.os }}
path: target/wheels/*.whl
# ==========================================================================
# Publish to PyPI
# ==========================================================================
publish-pypi:
name: Publish to PyPI
needs: [create-release, build-wheels]
runs-on: ubuntu-latest
environment: pypi
steps:
- name: Download wheels
uses: actions/download-artifact@v4
with:
pattern: wheels-*
merge-multiple: true
path: dist
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
skip-existing: true
# ==========================================================================
# Publish to crates.io
# ==========================================================================
publish-crates:
name: Publish to crates.io
needs: create-release
runs-on: ubuntu-latest
environment: crates-io
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Publish to crates.io
run: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
# ==========================================================================
# Publish to npm
# ==========================================================================
publish-npm:
name: Publish to npm
needs: [create-release, build-binaries]
runs-on: ubuntu-latest
environment: npm
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
registry-url: "https://registry.npmjs.org"
- name: Update package version
run: |
VERSION="${{ needs.create-release.outputs.version }}"
VERSION_NUM="${VERSION#v}"
npm version "${VERSION_NUM}" --no-git-tag-version --allow-same-version
- name: Publish to npm
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# ==========================================================================
# Update Homebrew
# ==========================================================================
update-homebrew:
name: Update Homebrew Formula
needs: [create-release, build-binaries]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Calculate checksums
run: |
VERSION="${{ needs.create-release.outputs.version }}"
BASE_URL="https://github.com/${{ github.repository }}/releases/download/${VERSION}"
# Download release assets and calculate checksums
for TARGET in x86_64-apple-darwin aarch64-apple-darwin x86_64-unknown-linux-gnu; do
ARCHIVE="apc-${VERSION}-${TARGET}.tar.gz"
curl -sL "${BASE_URL}/${ARCHIVE}" -o "${ARCHIVE}"
SHA=$(shasum -a 256 "${ARCHIVE}" | cut -d' ' -f1)
echo "${TARGET}_SHA256=${SHA}" >> $GITHUB_ENV
done
- name: Generate Homebrew formula
run: |
VERSION="${{ needs.create-release.outputs.version }}"
VERSION_NUM="${VERSION#v}"
cat > agent-precommit.rb << EOF
class AgentPrecommit < Formula
desc "Smart pre-commit hooks for humans and AI coding agents"
homepage "https://github.com/${{ github.repository }}"
version "${VERSION_NUM}"
license "MIT"
on_macos do
if Hardware::CPU.arm?
url "https://github.com/${{ github.repository }}/releases/download/${VERSION}/apc-${VERSION}-aarch64-apple-darwin.tar.gz"
sha256 "${{ env.aarch64-apple-darwin_SHA256 }}"
else
url "https://github.com/${{ github.repository }}/releases/download/${VERSION}/apc-${VERSION}-x86_64-apple-darwin.tar.gz"
sha256 "${{ env.x86_64-apple-darwin_SHA256 }}"
end
end
on_linux do
url "https://github.com/${{ github.repository }}/releases/download/${VERSION}/apc-${VERSION}-x86_64-unknown-linux-gnu.tar.gz"
sha256 "${{ env.x86_64-unknown-linux-gnu_SHA256 }}"
end
def install
bin.install "apc"
end
test do
system "#{bin}/apc", "--version"
end
end
EOF
cat agent-precommit.rb
- name: Upload formula
uses: actions/upload-artifact@v4
with:
name: homebrew-formula
path: agent-precommit.rb
# ==========================================================================
# Generate install script
# ==========================================================================
generate-install-script:
name: Generate Install Script
needs: create-release
runs-on: ubuntu-latest
steps:
- name: Generate install.sh
run: |
VERSION="${{ needs.create-release.outputs.version }}"
cat > install.sh << 'SCRIPT'
#!/bin/sh
set -e
# agent-precommit installer
# Usage: curl -fsSL https://agent-precommit.dev/install.sh | sh
VERSION="${1:-latest}"
REPO="agent-precommit/agent-precommit"
INSTALL_DIR="${HOME}/.local/bin"
# Detect OS and architecture
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case "${OS}" in
linux)
case "${ARCH}" in
x86_64) TARGET="x86_64-unknown-linux-gnu" ;;
aarch64) TARGET="aarch64-unknown-linux-gnu" ;;
*) echo "Unsupported architecture: ${ARCH}"; exit 1 ;;
esac
;;
darwin)
case "${ARCH}" in
x86_64) TARGET="x86_64-apple-darwin" ;;
arm64) TARGET="aarch64-apple-darwin" ;;
*) echo "Unsupported architecture: ${ARCH}"; exit 1 ;;
esac
;;
*)
echo "Unsupported OS: ${OS}"
exit 1
;;
esac
# Get latest version if not specified
if [ "${VERSION}" = "latest" ]; then
VERSION=$(curl -sL "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
fi
echo "Installing agent-precommit ${VERSION} for ${TARGET}..."
# Download and extract
ARCHIVE="apc-${VERSION}-${TARGET}.tar.gz"
URL="https://github.com/${REPO}/releases/download/${VERSION}/${ARCHIVE}"
mkdir -p "${INSTALL_DIR}"
curl -fsSL "${URL}" | tar -xz -C "${INSTALL_DIR}" --strip-components=1 apc-${VERSION}-${TARGET}/apc
chmod +x "${INSTALL_DIR}/apc"
echo ""
echo "✓ Installed apc to ${INSTALL_DIR}/apc"
echo ""
echo "Make sure ${INSTALL_DIR} is in your PATH:"
echo ' export PATH="${HOME}/.local/bin:${PATH}"'
echo ""
echo "Get started:"
echo " apc init"
echo " apc install"
SCRIPT
chmod +x install.sh
- name: Upload install script
uses: actions/upload-artifact@v4
with:
name: install-script
path: install.sh
# ==========================================================================
# Finalize release
# ==========================================================================
finalize-release:
name: Finalize Release
needs:
- create-release
- build-binaries
- publish-pypi
- publish-crates
- publish-npm
- update-homebrew
- generate-install-script
runs-on: ubuntu-latest
steps:
- name: Publish release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.create-release.outputs.version }}
draft: false