Skip to content

CI & Release

CI & Release #40

Workflow file for this run

name: CI & Release
on:
push:
branches: ["main"]
tags:
- "v*.*.*"
pull_request:
branches: ["main"]
workflow_dispatch:
permissions:
contents: write
id-token: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
jobs:
build:
name: Build & Test (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: macos-latest
target: x86_64-apple-darwin
- os: macos-latest
target: aarch64-apple-darwin
- os: windows-latest
target: x86_64-pc-windows-msvc
steps:
- uses: actions/checkout@v4
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Build
run: cargo build --release --target ${{ matrix.target }} --features cli
- name: Run tests
run: cargo test --release --target ${{ matrix.target }}
- name: Upload binary artifact
uses: actions/upload-artifact@v4
with:
name: html2json-${{ matrix.target }}
path: target/${{ matrix.target }}/release/html2json*
if-no-files-found: error
wasm:
name: Build WASM
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install wasm-pack
run: cargo install wasm-pack
- name: Build WASM
run: wasm-pack build --release --target web --out-name html2json --scope qretaio -- --features wasm
- name: Add auto-init wrapper
run: |
cp scripts/wrapper.js pkg/index.js
# Update package.json to use wrapper as entry point
npm pkg set main="index.js" --prefix pkg
npm pkg set files[3]="index.js" --prefix pkg
- name: Upload WASM artifact
uses: actions/upload-artifact@v4
with:
name: html2json
path: pkg/*
if-no-files-found: error
release:
name: Release
runs-on: ubuntu-latest
needs: [build, wasm]
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "24"
registry-url: "https://registry.npmjs.org"
- name: Create archives
run: |
# List downloaded artifacts for debugging
echo "Downloaded artifacts:"
ls -la
cd artifacts
ls -la
# Create WASM archive (handle scoped package name)
if [ -d "html2json" ]; then
cd html2json
# Check if scoped package directory exists inside
if [ -d "@qretaio" ]; then
cd "@qretaio"
tar czf ../../../html2json-wasm.tar.gz html2json
else
tar czf ../../html2json-wasm.tar.gz .
fi
cd ..
fi
# Create binary archives
for dir in html2json-*/; do
target="${dir#html2json-}"
target="${target%/}"
cd "$dir"
if [[ "$target" == *"windows"* ]]; then
zip -q "../../html2json-$target.zip" html2json.exe
else
tar czf "../../html2json-$target.tar.gz" html2json
fi
cd ..
done
- name: Create release
uses: softprops/action-gh-release@v2
with:
files: |
html2json-*
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to npm
working-directory: artifacts/html2json
run: npm publish --access public
- name: Publish to crates.io
run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}