datahaven/.github/workflows/task-check-metadata.yml
Facundo Farall 935babe36a
ci: 👷 Add CI to check PAPI metadata (#107)
Add CI check for Polkadot-API metadata freshness

This PR adds a new CI workflow that ensures the Polkadot-API metadata
file (`test/.papi/metadata/datahaven.scale`)
   is kept up-to-date when runtime changes are made.

  Changes:

  - Added task-check-metadata.yml workflow that:
- Reuses the WASM artifact from the build-operator job (no duplicate
compilation)
    - Runs `bun x papi add` to regenerate metadata
    - Fails if the metadata file has uncommitted changes
- Integrated the check into `CI.yml` as a second-tier job alongside
`docker-build`

  Why:

- Prevents TypeScript type definitions from becoming out of sync with
the runtime
- Reminds developers to run `bun generate:types:fast` when making
runtime changes
  - Ensures consistent type safety across the codebase

The check provides clear error messages with instructions when metadata
is outdated.
2025-06-19 19:12:04 -03:00

96 lines
3.2 KiB
YAML

name: "Task: Check Metadata Freshness"
on:
workflow_dispatch:
inputs:
binary-hash:
description: "Hash of the binary artifact to use"
required: true
type: string
workflow_call:
inputs:
binary-hash:
description: "Hash of the binary artifact to use"
required: true
type: string
defaults:
run:
shell: bash
env:
RUST_BACKTRACE: "1"
jobs:
check-metadata:
name: Check metadata freshness
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.2.16
- name: Install dependencies
working-directory: test
run: bun install --frozen-lockfile
- name: Download WASM artifact
uses: actions/download-artifact@v4
with:
name: datahaven-wasm-${{ inputs.binary-hash }}
path: ./operator/target/release/wbuild/datahaven-stagenet-runtime
- name: Verify WASM download to target directory
run: |
echo "Target directory contents:"
find ./operator/target/release/wbuild/datahaven-stagenet-runtime -type f | head -20
# The WASM should be at this path in the artifact
WASM_PATH="./operator/target/release/wbuild/datahaven-stagenet-runtime/datahaven_stagenet_runtime.wasm"
if [ ! -f "$WASM_PATH" ]; then
echo "Error: WASM file not found at expected path: $WASM_PATH"
echo "Looking for WASM files in target directory:"
find ./operator/target/release/wbuild/datahaven-stagenet-runtime -name "*.wasm" -type f
exit 1
fi
echo "Found WASM at: $WASM_PATH"
echo "WASM size: $(du -h $WASM_PATH | cut -f1)"
- name: Generate metadata from WASM
working-directory: test
run: |
echo "Generating metadata from WASM..."
bun x papi add --wasm "../operator/target/release/wbuild/datahaven-stagenet-runtime/datahaven_stagenet_runtime.wasm" datahaven
- name: Check for metadata changes
run: |
# Check if the metadata file has changed
if git diff --exit-code test/.papi/metadata/datahaven.scale; then
echo "✅ Metadata is up to date!"
else
echo "❌ Metadata file has changed!"
echo ""
echo "The runtime metadata is out of date. Please run the following command and commit the changes:"
echo ""
echo " cd test && bun generate:types:fast"
echo ""
echo "This ensures that TypeScript types match the current runtime."
echo ""
echo "Diff of changes:"
git diff test/.papi/metadata/datahaven.scale | head -50
exit 1
fi
- name: Check for other papi changes
run: |
# Also check if polkadot-api.json changed (shouldn't happen, but good to verify)
if git diff --exit-code test/.papi/polkadot-api.json; then
echo "✅ polkadot-api.json is unchanged"
else
echo "⚠️ polkadot-api.json has changed - this is unexpected"
git diff test/.papi/polkadot-api.json
fi