Files
pdf-inspector/.github/workflows/publish.yml
T
Abimael MartellandClaude Opus 4.6 9154085e2c fix publish: generate platform packages manually, add optionalDependencies
Skip napi prepublish/artifacts commands that require GitHub API auth.
Instead, create platform package.json files and copy binaries directly.
Add optionalDependencies to main package so npm/bun auto-selects the
right binary.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 11:52:12 -07:00

132 lines
3.8 KiB
YAML

name: Publish npm package
on:
push:
tags: ['v*']
permissions:
contents: read
packages: write
jobs:
build:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: macos-14
target: aarch64-apple-darwin
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
napi/target/
key: ${{ runner.os }}-cargo-napi-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-napi-
- name: Install dependencies
working-directory: napi
run: bun install
- name: Build native addon
working-directory: napi
run: bunx napi build --platform --release
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: bindings-${{ matrix.target }}
path: napi/*.node
if-no-files-found: error
publish:
name: Publish to GitHub Packages
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies
working-directory: napi
run: bun install
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: napi/artifacts
- name: Prepare and publish
working-directory: napi
run: |
echo "//npm.pkg.github.com/:_authToken=${{ secrets.GITHUB_TOKEN }}" > .npmrc
echo "@firecrawl:registry=https://npm.pkg.github.com" >> .npmrc
VERSION=$(node -p "require('./package.json').version")
# Create platform package dirs and package.json files
mkdir -p npm/linux-x64-gnu npm/darwin-arm64
cat > npm/linux-x64-gnu/package.json << PKGEOF
{
"name": "@firecrawl/pdf-inspector-js-linux-x64-gnu",
"version": "${VERSION}",
"os": ["linux"],
"cpu": ["x64"],
"main": "pdf-inspector.linux-x64-gnu.node",
"files": ["pdf-inspector.linux-x64-gnu.node"],
"license": "MIT",
"repository": { "type": "git", "url": "https://github.com/firecrawl/pdf-inspector" },
"publishConfig": { "registry": "https://npm.pkg.github.com", "access": "public" }
}
PKGEOF
cat > npm/darwin-arm64/package.json << PKGEOF
{
"name": "@firecrawl/pdf-inspector-js-darwin-arm64",
"version": "${VERSION}",
"os": ["darwin"],
"cpu": ["arm64"],
"main": "pdf-inspector.darwin-arm64.node",
"files": ["pdf-inspector.darwin-arm64.node"],
"license": "MIT",
"repository": { "type": "git", "url": "https://github.com/firecrawl/pdf-inspector" },
"publishConfig": { "registry": "https://npm.pkg.github.com", "access": "public" }
}
PKGEOF
# Move binaries into platform dirs
cp artifacts/bindings-x86_64-unknown-linux-gnu/*.node npm/linux-x64-gnu/
cp artifacts/bindings-aarch64-apple-darwin/*.node npm/darwin-arm64/
echo "=== Package contents ==="
ls -R npm/
# Publish platform packages first, then main package
for dir in npm/*/; do
echo "Publishing $dir"
(cd "$dir" && npm publish --access public)
done
echo "Publishing main package"
npm publish --access public