spacewasm 0.7.1

A no_std WebAssembly 1.0 decoder, validator, and interpreter for on-board spacecraft use
Documentation
name: Release
on:
  push:
    tags:
      - "v[0-9]+.[0-9]+.[0-9]+*"

permissions:
  contents: write

jobs:
  publish:
    name: Publish to crates.io
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c # stable

      - name: Inject version from tag
        run: |
          tag_version="${GITHUB_REF_NAME#v}"
          echo "Releasing version: $tag_version"
          # Replace the 0.0.0 placeholder under [workspace.package] with the tag version.
          sed -i 's/^version = "0\.0\.0"$/version = "'"$tag_version"'"/' Cargo.toml
          # Pin spacewasm_c_api's dependency on spacewasm to the exact tag version.
          # Its manifest carries a `version = "=0.0.0"` placeholder for this.
          sed -i 's/version = "=0\.0\.0"/version = "='"$tag_version"'"/' crates/spacewasm_c_api/Cargo.toml
          # Fail if any placeholder was not found / not replaced.
          for pkg in spacewasm spacewasm_c_api; do
            crate_version=$(cargo metadata --no-deps --format-version 1 \
              | jq -r '.packages[] | select(.name == "'"$pkg"'") | .version')
            if [ "$crate_version" != "$tag_version" ]; then
              echo "::error::Failed to inject version for $pkg. Expected $tag_version but Cargo.toml resolves to $crate_version. Is the 0.0.0 placeholder still present?"
              exit 1
            fi
          done
          dep_version=$(cargo metadata --no-deps --format-version 1 \
            | jq -r '.packages[] | select(.name == "spacewasm_c_api") | .dependencies[] | select(.name == "spacewasm") | .req')
          if [ "$dep_version" != "=$tag_version" ]; then
            echo "::error::spacewasm_c_api's spacewasm dependency resolves to '$dep_version', expected '=$tag_version'. Is the =0.0.0 placeholder still present?"
            exit 1
          fi

      - name: Install WABT (WebAssembly Binary Toolkit)
        uses: ./.github/actions/install-wabt

      - name: Run tests
        run: cargo test --workspace --verbose

      - name: Publish spacewasm to crates.io
        # --allow-dirty: the injected version is an uncommitted working-tree change.
        run: cargo publish -p spacewasm --allow-dirty
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

      - name: Verify spacewasm_c_api packaging
        run: |
          cargo build -p spacewasm_c_api --release --verbose
          cargo package -p spacewasm_c_api --allow-dirty --no-verify

      - name: Publish spacewasm_c_api to crates.io
        # Published after spacewasm since it depends on the exact matching
        # release. cargo waits for the dependency to be available in the index.
        # --allow-dirty: the injected version is an uncommitted working-tree change.
        # --no-verify: skips cargo's verify build, which fails with "unwinding
        # panics are not supported without std" for this no_std `panic = "abort"`
        # staticlib/cdylib.
        run: cargo publish -p spacewasm_c_api --allow-dirty --no-verify
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

      - name: Create GitHub Release
        # Do NOT use an action that regenerates notes unconditionally: if the
        # release already exists (e.g. created from the GitHub UI, which also
        # creates the tag that triggers this workflow), generate_release_notes
        # *appends* a second copy of the changelog to the existing body
        # (softprops/action-gh-release#827). Generate notes only when creating a
        # brand-new release so the changelog is written exactly once.
        env:
          GH_TOKEN: ${{ github.token }}
        run: |
          set -euo pipefail
          tag="${GITHUB_REF_NAME}"
          if gh release view "$tag" >/dev/null 2>&1; then
            echo "Release $tag already exists; leaving its notes untouched."
          else
            gh release create "$tag" --generate-notes --verify-tag
          fi