Skip to content

refactor(ci): migrate workflows to shared-workflows #2

refactor(ci): migrate workflows to shared-workflows

refactor(ci): migrate workflows to shared-workflows #2

Workflow file for this run

name: CI/CD
on:
push:
branches: [main]
tags:
- "v*.*.*"
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# ── Change Detection ──────────────────────────────────────────
changes:
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
rust: ${{ steps.filter.outputs.rust }}
web: ${{ steps.filter.outputs.web }}
ci: ${{ steps.filter.outputs.ci }}
steps:
- uses: actions/checkout@v6
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
rust:
- 'src/**'
- 'silkprint-wasm/**'
- 'Cargo.toml'
- 'Cargo.lock'
- 'themes/**'
- 'fonts/**'
- 'tests/**'
- 'deny.toml'
- 'rust-toolchain.toml'
web:
- 'web/**'
ci:
- '.github/workflows/**'
- 'justfile'
# ── CI (lint, test, audit) ────────────────────────────────────
ci:
needs: changes
if: >-
startsWith(github.ref, 'refs/tags/') ||
needs.changes.outputs.rust == 'true' ||
needs.changes.outputs.ci == 'true'
uses: hyperb1iss/shared-workflows/.github/workflows/rust-ci.yml@main
with:
change-detection: false
workspace: true
permissions:
contents: read
pull-requests: read
secrets: inherit
# ── WASM Build ────────────────────────────────────────────────
wasm:
name: WASM
needs: changes
if: >-
needs.changes.outputs.rust == 'true' ||
needs.changes.outputs.web == 'true' ||
needs.changes.outputs.ci == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Get wasm-bindgen version
id: wb-version
run: |
version=$(grep -A1 '^name = "wasm-bindgen"$' Cargo.lock | grep '^version' | head -1 | sed 's/.*"\(.*\)"/\1/')
if [ -z "$version" ]; then
echo "::error::Could not determine wasm-bindgen version from Cargo.lock"
exit 1
fi
echo "version=$version" >> "$GITHUB_OUTPUT"
- uses: taiki-e/install-action@v2
with:
tool: wasm-bindgen-cli@${{ steps.wb-version.outputs.version }}
- name: Build WASM
run: cargo build --release --locked -p silkprint-wasm --target wasm32-unknown-unknown
- name: Generate bindings
run: |
mkdir -p wasm-out
wasm-bindgen --out-dir wasm-out --target web \
target/wasm32-unknown-unknown/release/silkprint_wasm.wasm
# Patch import.meta.url so Turbopack doesn't resolve it statically
sed -i "s|new URL('silkprint_wasm_bg.wasm', import.meta.url)|'/wasm/silkprint_wasm_bg.wasm'|" \
wasm-out/silkprint_wasm.js
- name: Optimize WASM
run: |
curl -sL https://github.com/WebAssembly/binaryen/releases/download/version_122/binaryen-version_122-x86_64-linux.tar.gz \
| tar xz --strip-components=2 -C /usr/local/bin binaryen-version_122/bin/wasm-opt
wasm-opt -Oz \
--enable-sign-ext --enable-mutable-globals --enable-bulk-memory \
--enable-nontrapping-float-to-int --enable-multivalue --enable-reference-types \
wasm-out/silkprint_wasm_bg.wasm -o wasm-out/silkprint_wasm_bg.wasm
- uses: actions/upload-artifact@v4
with:
name: wasm
path: wasm-out/
retention-days: 1
# ── Web App ───────────────────────────────────────────────────
web:
name: Web
needs: [changes, wasm]
if: >-
needs.changes.outputs.rust == 'true' ||
needs.changes.outputs.web == 'true' ||
needs.changes.outputs.ci == 'true'
runs-on: ubuntu-latest
defaults:
run:
working-directory: web
steps:
- uses: actions/checkout@v6
- uses: actions/download-artifact@v4
with:
name: wasm
path: wasm-out/
- name: Install WASM artifacts and fonts
working-directory: .
run: |
mkdir -p web/src/lib/wasm web/public/wasm web/public/fonts
cp wasm-out/silkprint_wasm.js wasm-out/silkprint_wasm.d.ts web/src/lib/wasm/
cp wasm-out/silkprint_wasm_bg.wasm web/public/wasm/
cp -r fonts/core/* web/public/fonts/
- uses: pnpm/action-setup@v4
with:
package_json_file: web/package.json
- uses: actions/setup-node@v6
with:
node-version: 24
cache: pnpm
cache-dependency-path: web/pnpm-lock.yaml
- run: pnpm install --frozen-lockfile
- name: Typecheck
run: pnpm typecheck
- name: Lint
run: pnpm lint
- name: Build
run: pnpm build
# ── Deploy to GitHub Pages ────────────────────────────────────
deploy:
name: Deploy
needs: [changes, wasm, web]
if: >-
github.ref == 'refs/heads/main' &&
(needs.changes.outputs.rust == 'true' ||
needs.changes.outputs.web == 'true' ||
needs.changes.outputs.ci == 'true')
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
defaults:
run:
working-directory: web
steps:
- uses: actions/checkout@v6
- uses: actions/download-artifact@v4
with:
name: wasm
path: wasm-out/
- name: Install WASM artifacts and fonts
working-directory: .
run: |
mkdir -p web/src/lib/wasm web/public/wasm web/public/fonts
cp wasm-out/silkprint_wasm.js wasm-out/silkprint_wasm.d.ts web/src/lib/wasm/
cp wasm-out/silkprint_wasm_bg.wasm web/public/wasm/
cp -r fonts/core/* web/public/fonts/
- uses: pnpm/action-setup@v4
with:
package_json_file: web/package.json
- uses: actions/setup-node@v6
with:
node-version: 24
cache: pnpm
cache-dependency-path: web/pnpm-lock.yaml
- run: pnpm install --frozen-lockfile
- name: Build for Pages
env:
GITHUB_PAGES: 'true'
NEXT_PUBLIC_BASE_PATH: /silkprint
run: pnpm build
- uses: actions/configure-pages@v5
- uses: actions/upload-pages-artifact@v3
with:
path: web/out
- uses: actions/deploy-pages@v4
id: deployment
# ── Publish to crates.io ──────────────────────────────────────
publish:
if: startsWith(github.ref, 'refs/tags/')
needs: ci
uses: hyperb1iss/shared-workflows/.github/workflows/rust-publish.yml@main
permissions:
contents: read
id-token: write
secrets: inherit
# ── Create GitHub Release ─────────────────────────────────────
release:
if: startsWith(github.ref, 'refs/tags/')
needs: publish
uses: hyperb1iss/shared-workflows/.github/workflows/github-release.yml@main
permissions:
contents: write
actions: read
secrets: inherit