From 00bae41ebd0d8167040a7e3cfbe0863120d6b7e6 Mon Sep 17 00:00:00 2001 From: MegalithOfficial Date: Sat, 19 Sep 2026 17:47:15 +0200 Subject: [PATCH] Add CI and a workflow to sync the WIT submodule --- .github/workflows/main.yml | 62 ++++++++++++++++++++++++++++++ .github/workflows/update-wit.yml | 65 ++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/update-wit.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..51cc80e --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,62 @@ +name: Main +on: + push: + pull_request: + workflow_dispatch: + workflow_run: + types: + - completed + workflows: + - "Update WIT" + +permissions: + contents: read + +jobs: + main: + name: Build and test + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v6 + with: + submodules: true + + - name: Set up Zig + uses: mlugg/setup-zig@v2 + with: + version: 0.16.0 + + - name: Set up wasm-tools + uses: bytecodealliance/actions/wasm-tools/setup@v1 + with: + # The generated src/plugin.wit is printed by wasm-tools, keep this in + # sync with what `zig build gen` was last run with. + version: "1.259.0" + + - name: Format + run: zig fmt --check build.zig src tools example + + - name: Test + run: zig build test --summary all + + - name: Generated bindings are up to date + run: | + set -eux + zig build gen + git diff --exit-code -- src + + - name: Compile every binding + run: zig build check + + - name: Build example + run: | + set -eux + zig build + wasm-tools validate zig-out/pumpkin-plugin-example.wasm + + - name: Upload example + uses: actions/upload-artifact@v7 + with: + name: pumpkin-plugin-example + path: zig-out/pumpkin-plugin-example.wasm diff --git a/.github/workflows/update-wit.yml b/.github/workflows/update-wit.yml new file mode 100644 index 0000000..9278081 --- /dev/null +++ b/.github/workflows/update-wit.yml @@ -0,0 +1,65 @@ +name: Update WIT +on: + workflow_dispatch: + +permissions: + contents: write + +jobs: + update-wit: + name: Update WIT + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v6 + with: + submodules: true + + - name: Set up Zig + uses: mlugg/setup-zig@v2 + with: + version: 0.16.0 + + - name: Set up wasm-tools + uses: bytecodealliance/actions/wasm-tools/setup@v1 + with: + # The generated src/plugin.wit is printed by wasm-tools, keep this in + # sync with what `zig build gen` was last run with. + version: "1.259.0" + + - name: Update submodule + id: update_submodule + run: | + set -eux + + cd wit + git fetch origin master + git checkout FETCH_HEAD + + echo "wit_commit=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + + - name: Regenerate bindings + run: | + set -eux + + zig build gen + zig build test + zig build check + zig build + + - name: Commit + run: | + set -eux + + witCommit='${{ steps.update_submodule.outputs.wit_commit }}' + + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + + git add wit src + if git diff --cached --quiet; then + echo "already up to date" + exit 0 + fi + git commit -m "Sync to Pumpkin-MC/pumpkin-plugin-wit@${witCommit}" + git push