* chore(release): unify package versions * fix(release): harden version synchronization
116 lines
4.3 KiB
YAML
116 lines
4.3 KiB
YAML
name: Publish WebAssembly package
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
paths: ['wasm/Cargo.toml']
|
|
workflow_dispatch:
|
|
|
|
permissions:
|
|
contents: read
|
|
id-token: write
|
|
|
|
env:
|
|
CARGO_TERM_COLOR: always
|
|
|
|
jobs:
|
|
check-version:
|
|
name: Check version change
|
|
if: github.ref == 'refs/heads/main'
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
changed: ${{ steps.check.outputs.changed }}
|
|
package_exists: ${{ steps.check.outputs.package_exists }}
|
|
published: ${{ steps.check.outputs.published }}
|
|
version: ${{ steps.check.outputs.version }}
|
|
steps:
|
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
with:
|
|
fetch-depth: 2
|
|
|
|
- name: Check package version sync
|
|
run: python3 scripts/version.py --check
|
|
|
|
- name: Check package version
|
|
id: check
|
|
run: |
|
|
NEW_VERSION=$(python3 -c 'import pathlib, tomllib; print(tomllib.loads(pathlib.Path("wasm/Cargo.toml").read_text())["package"]["version"])')
|
|
echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
|
|
|
|
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
|
echo "changed=true" >> "$GITHUB_OUTPUT"
|
|
elif git cat-file -e HEAD~1:wasm/Cargo.toml 2>/dev/null; then
|
|
OLD_VERSION=$(git show HEAD~1:wasm/Cargo.toml | python3 -c 'import sys, tomllib; print(tomllib.loads(sys.stdin.read())["package"]["version"])')
|
|
if [ "$NEW_VERSION" = "$OLD_VERSION" ]; then
|
|
echo "changed=false" >> "$GITHUB_OUTPUT"
|
|
echo "published=false" >> "$GITHUB_OUTPUT"
|
|
exit 0
|
|
fi
|
|
echo "changed=true" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "changed=true" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
if ! npm view "@firecrawl/pdf-inspector-wasm" name >/dev/null 2>&1; then
|
|
echo "package_exists=false" >> "$GITHUB_OUTPUT"
|
|
echo "published=false" >> "$GITHUB_OUTPUT"
|
|
echo "The initial package must be published once before trusted publishing can be configured."
|
|
exit 0
|
|
fi
|
|
|
|
echo "package_exists=true" >> "$GITHUB_OUTPUT"
|
|
if npm view "@firecrawl/pdf-inspector-wasm@$NEW_VERSION" version >/dev/null 2>&1; then
|
|
echo "published=true" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "published=false" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
publish:
|
|
name: Build and publish
|
|
needs: check-version
|
|
if: needs.check-version.outputs.changed == 'true' && needs.check-version.outputs.package_exists == 'true' && needs.check-version.outputs.published == 'false'
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
id-token: write
|
|
steps:
|
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
|
|
- name: Install Rust
|
|
uses: dtolnay/rust-toolchain@4cda84d5c5c54efe2404f9d843567869ab1699d4 # stable
|
|
with:
|
|
toolchain: stable
|
|
targets: wasm32-unknown-unknown
|
|
|
|
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
|
|
with:
|
|
node-version: '24'
|
|
registry-url: 'https://registry.npmjs.org'
|
|
|
|
- name: Install wasm-pack
|
|
run: cargo install wasm-pack --version 0.15.0 --locked
|
|
|
|
- name: Build browser package
|
|
run: wasm-pack build wasm --target web --scope firecrawl --out-dir pkg --release
|
|
|
|
- name: Prepare package metadata
|
|
run: |
|
|
node -e '
|
|
const fs = require("fs")
|
|
const path = "wasm/pkg/package.json"
|
|
const pkg = JSON.parse(fs.readFileSync(path, "utf8"))
|
|
pkg.name = "@firecrawl/pdf-inspector-wasm"
|
|
pkg.description = "Browser WebAssembly bindings for the pdf-inspector Rust PDF parser"
|
|
pkg.keywords = ["pdf", "pdf-parser", "webassembly", "wasm", "markdown", "rust", "firecrawl"]
|
|
pkg.repository = { type: "git", url: "https://github.com/firecrawl/pdf-inspector" }
|
|
pkg.homepage = "https://github.com/firecrawl/pdf-inspector/tree/main/wasm"
|
|
pkg.publishConfig = { access: "public" }
|
|
fs.writeFileSync(path, JSON.stringify(pkg, null, 2) + "\n")
|
|
'
|
|
|
|
- name: Inspect package contents
|
|
run: npm pack --dry-run ./wasm/pkg
|
|
|
|
- name: Publish package
|
|
run: npm publish ./wasm/pkg --provenance --access public
|