name: Release WASM & npm
on:
workflow_dispatch: inputs:
version:
description: "Version to release (without v prefix, e.g., 2.0.0). Leave empty to use Cargo.toml version."
required: false
type: string
publish_npm:
description: "Publish to npm"
required: true
type: boolean
default: true
workflow_call: inputs:
version:
description: "Version to release (without v prefix)"
required: false
type: string
publish_npm:
description: "Publish to npm"
required: false
type: boolean
default: true
env:
CARGO_TERM_COLOR: always
permissions:
contents: write
id-token: write
jobs:
version-check:
name: Version Check
uses: ./.github/workflows/version-check.yml
build-wasm:
name: Build WASM SDK
needs: version-check
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-cargo-wasm-${{ hashFiles('Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-wasm-
- name: Build WASM
run: |
cd crates/wasm
wasm-pack build --target web --out-dir ../../pkg --features openapi,odps-validation
- name: Set version
id: version
env:
INPUT_VERSION: ${{ inputs.version }}
VERIFIED_VERSION: ${{ needs.version-check.outputs.version }}
run: |
if [ -n "$INPUT_VERSION" ]; then
VERSION="$INPUT_VERSION"
elif [ -n "$VERIFIED_VERSION" ]; then
VERSION="$VERIFIED_VERSION"
else
VERSION=$(grep -A 10 '^\[package\]' Cargo.toml | grep '^version = ' | head -1 | sed 's/version = "\(.*\)"/\1/')
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Building WASM version: $VERSION"
- name: Update package.json
run: |
cd pkg
# Update version
npm version ${{ steps.version.outputs.version }} --no-git-tag-version --allow-same-version
# Update package name to scoped package (wasm-pack uses crate name: data-modelling-wasm)
sed -i 's/"name": "data-modelling-wasm"/"name": "@offenedatenmodellierung\/data-modelling-sdk"/' package.json
# Add repository info
cat package.json | jq '. + {
"repository": {
"type": "git",
"url": "git+https://github.com/OffeneDatenmodellierung/data-modelling-sdk.git"
},
"homepage": "https://github.com/OffeneDatenmodellierung/data-modelling-sdk#readme",
"bugs": {
"url": "https://github.com/OffeneDatenmodellierung/data-modelling-sdk/issues"
},
"keywords": ["wasm", "data-modelling", "odcs", "schema", "rust"]
}' > package.json.tmp && mv package.json.tmp package.json
echo "Updated package.json:"
cat package.json
- name: Create WASM archive
id: archive
run: |
ARCHIVE_NAME="data-modelling-sdk-wasm-v${{ steps.version.outputs.version }}.tar.gz"
tar -czf $ARCHIVE_NAME -C pkg .
echo "archive_name=$ARCHIVE_NAME" >> $GITHUB_OUTPUT
- name: Upload WASM archive artifact
uses: actions/upload-artifact@v4
with:
name: wasm-sdk
path: ${{ steps.archive.outputs.archive_name }}
retention-days: 30
- name: Upload npm package artifact
uses: actions/upload-artifact@v4
with:
name: npm-package
path: pkg/
retention-days: 30
publish-npm:
name: Publish to npm
needs: build-wasm
runs-on: ubuntu-latest
if: inputs.publish_npm
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
registry-url: "https://registry.npmjs.org"
- name: Download npm package artifact
uses: actions/download-artifact@v4
with:
name: npm-package
path: pkg/
- name: Verify package contents
run: |
echo "Package contents:"
ls -la pkg/
echo ""
echo "package.json:"
cat pkg/package.json
- name: Publish to npm
run: |
cd pkg
npm publish --access public --provenance
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
update-release:
name: Update GitHub Release
needs: build-wasm
runs-on: ubuntu-latest
steps:
- name: Get version info
id: version
run: |
VERSION="${{ needs.build-wasm.outputs.version }}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
# Check if this is a dev release
if [[ "$VERSION" == *"-dev"* ]]; then
echo "is_prerelease=true" >> $GITHUB_OUTPUT
else
echo "is_prerelease=false" >> $GITHUB_OUTPUT
fi
- name: Download WASM archive
uses: actions/download-artifact@v4
with:
name: wasm-sdk
path: artifacts/
- name: Create checksum
run: |
cd artifacts
sha256sum *.tar.gz > data-modelling-sdk-wasm-v${{ steps.version.outputs.version }}.tar.gz.sha256
- name: Upload to GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.version.outputs.version }}
name: v${{ steps.version.outputs.version }}
body: |
## WASM Release v${{ steps.version.outputs.version }}
**WebAssembly SDK:** data-modelling-sdk-wasm-v${{ steps.version.outputs.version }}.tar.gz
### npm Package
```bash
npm install @offenedatenmodellierung/data-modelling-sdk@${{ steps.version.outputs.version }}
```
files: |
artifacts/*.tar.gz
artifacts/*.sha256
fail_on_unmatched_files: false
prerelease: ${{ steps.version.outputs.is_prerelease }}