forked from yfedoseev/pdf_oxide
-
Notifications
You must be signed in to change notification settings - Fork 0
513 lines (440 loc) · 16.8 KB
/
Copy pathrelease.yml
File metadata and controls
513 lines (440 loc) · 16.8 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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
name: Release
on:
push:
tags:
- 'v*.*.*'
workflow_dispatch:
inputs:
tag:
description: 'Tag to release (e.g., v0.1.1)'
required: true
type: string
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
jobs:
# Validate tag matches version
validate:
name: Validate Release
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v6
- name: Get version from Cargo.toml
id: version
run: |
VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Detected version: $VERSION"
- name: Validate tag matches version
run: |
TAG="${{ github.ref_name }}"
VERSION="${{ steps.version.outputs.version }}"
EXPECTED_TAG="v$VERSION"
if [ "$TAG" != "$EXPECTED_TAG" ]; then
echo "Error: Tag '$TAG' does not match Cargo.toml version '$VERSION'"
echo "Expected tag: $EXPECTED_TAG"
exit 1
fi
- name: Validate version consistency
run: |
CARGO_VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
PY_VERSION=$(grep '^version = ' pyproject.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
if [ "$CARGO_VERSION" != "$PY_VERSION" ]; then
echo "Error: Cargo.toml ($CARGO_VERSION) and pyproject.toml ($PY_VERSION) versions don't match"
exit 1
fi
echo "✓ Cargo.toml and pyproject.toml versions match: $CARGO_VERSION"
- name: Verify release is from main branch
run: |
# Fetch main branch
git fetch origin main
# Get the commit SHA the tag points to
TAG_SHA=$(git rev-parse HEAD)
# Check if this commit is reachable from main
if ! git merge-base --is-ancestor $TAG_SHA origin/main; then
echo "Error: Release tags must be created from commits on the main branch"
echo "Tag SHA: $TAG_SHA"
echo "Please merge your changes to main first, then create the release tag"
exit 1
fi
echo "✓ Verified: Tag points to a commit on main branch"
# Build binaries for all platforms
build-binaries:
name: Build ${{ matrix.target }}
needs: validate
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
# Linux x86_64 (glibc)
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact_name: pdf_oxide-linux-x86_64
use_cross: false
# Linux x86_64 (musl - static)
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
artifact_name: pdf_oxide-linux-x86_64-musl
use_cross: false
# Linux ARM64
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
artifact_name: pdf_oxide-linux-aarch64
use_cross: true
# macOS x86_64 (Intel)
- os: macos-latest
target: x86_64-apple-darwin
artifact_name: pdf_oxide-macos-x86_64
use_cross: false
# macOS ARM64 (Apple Silicon)
- os: macos-latest
target: aarch64-apple-darwin
artifact_name: pdf_oxide-macos-aarch64
use_cross: false
# Windows x86_64
- os: windows-latest
target: x86_64-pc-windows-msvc
artifact_name: pdf_oxide-windows-x86_64
use_cross: false
steps:
- uses: actions/checkout@v6
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Cache cargo registry
uses: actions/cache@v5
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-${{ matrix.target }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v5
with:
path: ~/.cargo/git
key: ${{ runner.os }}-${{ matrix.target }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Install musl tools (Linux musl)
if: matrix.target == 'x86_64-unknown-linux-musl'
run: sudo apt-get update && sudo apt-get install -y musl-tools
- 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: Build binaries
shell: bash
env:
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: ${{ matrix.target == 'aarch64-unknown-linux-gnu' && 'aarch64-linux-gnu-gcc' || '' }}
run: |
cargo build --release -p pdf_oxide_cli --target ${{ matrix.target }}
cargo build --release -p pdf_oxide_mcp --target ${{ matrix.target }}
- name: Build .deb package (Linux x86_64 glibc)
if: matrix.target == 'x86_64-unknown-linux-gnu'
run: |
cargo install cargo-deb
cargo deb -p pdf_oxide_cli --no-build --target x86_64-unknown-linux-gnu
- name: Upload .deb artifact
if: matrix.target == 'x86_64-unknown-linux-gnu'
uses: actions/upload-artifact@v7
with:
name: debian-package
path: target/x86_64-unknown-linux-gnu/debian/*.deb
retention-days: 7
- name: Create archive (Unix)
if: runner.os != 'Windows'
shell: bash
run: |
VERSION="${{ needs.validate.outputs.version }}"
mkdir -p dist
cd target/${{ matrix.target }}/release
tar czf ../../../dist/${{ matrix.artifact_name }}-${VERSION}.tar.gz pdf-oxide pdf-oxide-mcp
- name: Create archive (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$VERSION = "${{ needs.validate.outputs.version }}"
New-Item -ItemType Directory -Force -Path dist
Set-Location target/${{ matrix.target }}/release
Compress-Archive -Path @("pdf-oxide.exe", "pdf-oxide-mcp.exe") -DestinationPath ../../../dist/${{ matrix.artifact_name }}-${VERSION}.zip
- name: Upload artifact
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.artifact_name }}
path: dist/*
retention-days: 7
# Build WASM package
build-wasm:
name: Build WASM
needs: validate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- name: Cache cargo registry
uses: actions/cache@v5
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-wasm-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Build WASM binary
run: cargo build --lib --target wasm32-unknown-unknown --features wasm --release
- name: Install matching wasm-bindgen-cli
run: |
WASM_BINDGEN_VERSION=$(grep -A1 'name = "wasm-bindgen"' Cargo.lock | grep version | head -1 | sed 's/.*"\(.*\)"/\1/')
echo "Installing wasm-bindgen-cli@${WASM_BINDGEN_VERSION}"
cargo install wasm-bindgen-cli --version "$WASM_BINDGEN_VERSION"
- name: Generate bindings
run: |
wasm-bindgen --target nodejs --out-dir wasm-out/ \
target/wasm32-unknown-unknown/release/pdf_oxide.wasm
- name: Copy package files
run: |
cp wasm-pkg/package.json wasm-out/
cp wasm-pkg/README.md wasm-out/
- name: Upload WASM artifact
uses: actions/upload-artifact@v7
with:
name: wasm-package
path: wasm-out/
retention-days: 7
# Build Python wheels
build-python-wheels:
name: Build Python wheels (${{ matrix.target }})
needs: validate
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact_name: wheels-linux-x86_64
- os: macos-latest
target: x86_64-apple-darwin
artifact_name: wheels-macos-x86_64
- os: macos-latest
target: aarch64-apple-darwin
artifact_name: wheels-macos-aarch64
- os: windows-latest
target: x86_64-pc-windows-msvc
artifact_name: wheels-windows-x86_64
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.11'
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Install maturin
run: uv pip install --system maturin
# Generate .pyi stubs automatically using mypy stubgen
- name: Generate type stubs
run: |
uv run pip install mypy maturin
uv run maturin develop --features python
uv run stubgen -p pdf_oxide -o python
- name: Build wheels
run: maturin build --release --features python --target ${{ matrix.target }} --out dist
- name: Upload wheels
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.artifact_name }}
path: dist/*.whl
retention-days: 7
# Create GitHub Release
create-release:
name: Create GitHub Release
needs: [validate, build-binaries, build-python-wheels, build-wasm]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Download all artifacts
uses: actions/download-artifact@v8
with:
path: artifacts
- name: Organize release files
run: |
mkdir -p release-files
find artifacts -type f \( -name "*.tar.gz" -o -name "*.zip" -o -name "*.whl" -o -name "*.deb" \) -exec cp {} release-files/ \;
echo "=== Release files ==="
ls -lh release-files/
- name: Extract release notes from CHANGELOG
run: |
chmod +x .github/scripts/extract-release-notes.sh
.github/scripts/extract-release-notes.sh "${{ needs.validate.outputs.version }}"
- name: Read release title
id: title
run: echo "title=$(cat release-title.txt)" >> $GITHUB_OUTPUT
- name: Create release
uses: softprops/action-gh-release@v2
with:
name: ${{ steps.title.outputs.title }}
body_path: release-notes.md
files: release-files/*
draft: false
prerelease: ${{ contains(needs.validate.outputs.version, '-') }}
fail_on_unmatched_files: false
# Publish to crates.io (optional)
publish-crates:
name: Publish to crates.io
needs: [validate, create-release]
runs-on: ubuntu-latest
if: ${{ !contains(needs.validate.outputs.version, '-') }}
steps:
- uses: actions/checkout@v6
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Verify crates.io readiness
run: cargo publish -p pdf_oxide --dry-run
- name: Publish to crates.io
run: cargo publish -p pdf_oxide
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_TOKEN }}
- name: Publish CLI to crates.io
run: cargo publish -p pdf_oxide_cli
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_TOKEN }}
- name: Publish MCP server to crates.io
run: cargo publish -p pdf_oxide_mcp
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_TOKEN }}
# Publish to PyPI (optional)
publish-pypi:
name: Publish to PyPI
needs: [validate, build-python-wheels, create-release]
runs-on: ubuntu-latest
if: ${{ !contains(needs.validate.outputs.version, '-') }}
steps:
- name: Download wheel artifacts
uses: actions/download-artifact@v8
with:
path: wheels
pattern: wheels-*
merge-multiple: true
- name: List wheels
run: |
echo "=== Wheels to publish ==="
ls -lh wheels/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
packages-dir: wheels/
skip-existing: true
# Publish to npm
publish-npm:
name: Publish to npm
needs: [validate, build-wasm, create-release]
runs-on: ubuntu-latest
if: ${{ !contains(needs.validate.outputs.version, '-') }}
steps:
- name: Download WASM artifact
uses: actions/download-artifact@v8
with:
name: wasm-package
path: wasm-out
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: List package contents
run: |
echo "=== WASM package contents ==="
ls -lh wasm-out/
- name: Publish to npm
working-directory: wasm-out
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# Publish Homebrew formula and Scoop manifest
publish-packaging:
name: Publish Homebrew & Scoop
needs: [validate, create-release]
runs-on: ubuntu-latest
if: ${{ !contains(needs.validate.outputs.version, '-') }}
steps:
- uses: actions/checkout@v6
- name: Download release archives
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION="${{ needs.validate.outputs.version }}"
mkdir -p release-archives
cd release-archives
gh release download "v${VERSION}" \
--pattern "pdf_oxide-macos-aarch64-${VERSION}.tar.gz" \
--pattern "pdf_oxide-macos-x86_64-${VERSION}.tar.gz" \
--pattern "pdf_oxide-linux-x86_64-musl-${VERSION}.tar.gz" \
--pattern "pdf_oxide-windows-x86_64-${VERSION}.zip"
- name: Compute SHA256 hashes
id: hashes
run: |
VERSION="${{ needs.validate.outputs.version }}"
cd release-archives
echo "macos_arm=$(sha256sum pdf_oxide-macos-aarch64-${VERSION}.tar.gz | cut -d' ' -f1)" >> $GITHUB_OUTPUT
echo "macos_x86=$(sha256sum pdf_oxide-macos-x86_64-${VERSION}.tar.gz | cut -d' ' -f1)" >> $GITHUB_OUTPUT
echo "linux_x86=$(sha256sum pdf_oxide-linux-x86_64-musl-${VERSION}.tar.gz | cut -d' ' -f1)" >> $GITHUB_OUTPUT
echo "windows=$(sha256sum pdf_oxide-windows-x86_64-${VERSION}.zip | cut -d' ' -f1)" >> $GITHUB_OUTPUT
- name: Generate Homebrew formula
run: |
VERSION="${{ needs.validate.outputs.version }}"
sed \
-e "s/{{VERSION}}/${VERSION}/g" \
-e "s/{{SHA256_MACOS_ARM}}/${{ steps.hashes.outputs.macos_arm }}/g" \
-e "s/{{SHA256_MACOS_X86}}/${{ steps.hashes.outputs.macos_x86 }}/g" \
-e "s/{{SHA256_LINUX_X86}}/${{ steps.hashes.outputs.linux_x86 }}/g" \
.github/templates/pdf-oxide.rb > pdf-oxide.rb
echo "=== Generated Homebrew formula ==="
cat pdf-oxide.rb
- name: Generate Scoop manifest
run: |
VERSION="${{ needs.validate.outputs.version }}"
sed \
-e "s/{{VERSION}}/${VERSION}/g" \
-e "s/{{SHA256_WINDOWS}}/${{ steps.hashes.outputs.windows }}/g" \
.github/templates/pdf-oxide.json > pdf-oxide.json
echo "=== Generated Scoop manifest ==="
cat pdf-oxide.json
- name: Upload packaging artifacts
uses: actions/upload-artifact@v7
with:
name: packaging-manifests
path: |
pdf-oxide.rb
pdf-oxide.json
retention-days: 90
- name: Push to Homebrew tap
env:
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
run: |
git clone "https://x-access-token:${HOMEBREW_TAP_TOKEN}@github.com/yfedoseev/homebrew-tap.git" tap-repo
cp pdf-oxide.rb tap-repo/Formula/pdf-oxide.rb
cd tap-repo
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Formula/pdf-oxide.rb
git commit -m "Update pdf-oxide to ${{ needs.validate.outputs.version }}"
git push
- name: Push Scoop manifest
env:
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
run: |
git clone "https://x-access-token:${HOMEBREW_TAP_TOKEN}@github.com/yfedoseev/scoop-pdf-oxide.git" scoop-repo
cp pdf-oxide.json scoop-repo/pdf-oxide.json
cd scoop-repo
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add pdf-oxide.json
git commit -m "Update pdf-oxide to ${{ needs.validate.outputs.version }}"
git push