pddl-core 0.5.0

The types and the parser behind the pddl crate; depend on pddl instead
Documentation
---
name: Release

# Runs when `cargo release -p pddl-core -p pddl` pushes a vX.Y.Z tag (see
# pddl/release.toml). Publishes, each only if its version is not on crates.io
# yet: pddl-runtime, pddl-core, pddl-codegen, pddl-macros, then pddl, which
# re-exports them. pddl-core and pddl carry the same version; the others have
# their own. Only plain X.Y.Z versions are released; pre-release
# tags such as v1.0.0-rc.1 don't match.
on:
  push:
    tags:
      - 'v[0-9]+.[0-9]+.[0-9]+'

permissions: {}

env:
  CARGO_TERM_COLOR: always

# Both jobs can be re-run: an already published version and an existing
# GitHub Release are skipped, so "Re-run failed jobs" finishes a release.
jobs:
  publish:
    name: Publish to crates.io
    runs-on: ubuntu-latest
    # crates.io trusted publishing is configured for this workflow and environment.
    environment: release
    permissions:
      contents: read
      id-token: write
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          fetch-depth: 0
          persist-credentials: false
      - name: Install Rust
        run: |
          rustup toolchain install stable --profile minimal --no-self-update
          rustup default stable
      - name: Check that the tag matches the crate versions and is on main
        run: |
          metadata=$(cargo metadata --no-deps --format-version 1)
          version=$(jq -r '.packages[] | select(.name == "pddl") | .version' <<< "$metadata")
          core_version=$(jq -r '.packages[] | select(.name == "pddl-core") | .version' <<< "$metadata")
          if [ "v$version" != "$GITHUB_REF_NAME" ]; then
            echo "::error::Tag $GITHUB_REF_NAME does not match the version $version in pddl/Cargo.toml"
            exit 1
          fi
          if [ "$core_version" != "$version" ]; then
            echo "::error::pddl-core is at $core_version, but pddl is at $version; release them together"
            exit 1
          fi
          if ! git merge-base --is-ancestor "$GITHUB_SHA" origin/main; then
            echo "::error::Tag $GITHUB_REF_NAME points at a commit that is not on main"
            exit 1
          fi
      # The same feature combinations as the Rust CI workflow.
      - name: Run tests
        run: |
          cargo test --all-features
          cargo test --no-default-features
          cargo test --no-default-features --features pretty
          cargo test --no-default-features --features parser
          cargo test -p pddl --all-features
      # Re-runs skip crates whose version is already on crates.io, so a release
      # that published pddl-core but failed on pddl can be finished. The same
      # check publishes pddl-runtime, pddl-codegen and pddl-macros only when
      # their version is new.
      - name: Check which crates are already on crates.io
        id: crates-io
        run: |
          metadata=$(cargo metadata --no-deps --format-version 1)
          pending=""
          for crate in pddl-runtime pddl-core pddl-codegen pddl-macros pddl; do
            version=$(jq -r --arg crate "$crate" '.packages[] | select(.name == $crate) | .version' <<< "$metadata")
            response="$RUNNER_TEMP/crates-io-$crate.json"
            # --retry covers timeouts, 429 and 5xx; a 404 means "not published yet".
            status=$(curl -s --max-time 10 --retry 3 -o "$response" -w '%{http_code}' \
              -A "pddl-rs release workflow (https://github.com/sunsided/pddl-rs)" \
              "https://crates.io/api/v1/crates/$crate/$version")
            case "$status" in
              200)
                if [ "$(jq -r '.version.yanked' "$response")" != "false" ]; then
                  echo "::error::$crate $version is on crates.io but yanked; it can't be published again"
                  exit 1
                fi
                jq -r --arg crate "$crate" '"\($crate) \(.version.num) is already on crates.io (published \(.version.created_at), checksum \(.version.checksum)); skipping"' "$response"
                ;;
              404) pending="$pending $crate" ;;
              *) echo "::error::Unexpected HTTP $status from crates.io for $crate"; exit 1 ;;
            esac
          done
          echo "pending=${pending# }" >> "$GITHUB_OUTPUT"
      - name: Authenticate with crates.io
        if: steps.crates-io.outputs.pending != ''
        id: auth
        uses: rust-lang/crates-io-auth-action@3268eb413133e2960fa4ae0e963ca76380c54cd9 # v1.0.6
      - name: Publish
        if: steps.crates-io.outputs.pending != ''
        # In dependency order: pddl-core depends on pddl-runtime (codegen
        # feature), pddl-codegen on pddl-core, pddl-macros on both, pddl on all.
        run: |
          for crate in $PENDING; do
            cargo publish -p "$crate"
          done
        env:
          CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
          PENDING: ${{ steps.crates-io.outputs.pending }}

  github-release:
    name: Create GitHub Release
    needs: publish
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          persist-credentials: false
      - name: Extract release notes from CHANGELOG.md
        run: |
          version="${GITHUB_REF_NAME#v}"
          # The section from "## [X.Y.Z]" up to the next "## " heading, without
          # the heading itself and without link definitions like "[X.Y.Z]: https://...".
          awk -v heading="## [$version]" '
            index($0, heading) == 1 { found = 1; next }
            found && /^## / { exit }
            found && /^\[[^]]+\]: / { next }
            found { print }
          ' CHANGELOG.md > release-notes.md
      - name: Create the release
        run: |
          if gh release view "$GITHUB_REF_NAME" > /dev/null 2>&1; then
            echo "Release $GITHUB_REF_NAME already exists, skipping"
          elif grep -q '[^[:space:]]' release-notes.md; then
            gh release create "$GITHUB_REF_NAME" --verify-tag --title "$GITHUB_REF_NAME" --notes-file release-notes.md
          else
            gh release create "$GITHUB_REF_NAME" --verify-tag --title "$GITHUB_REF_NAME" --generate-notes
          fi
        env:
          GH_TOKEN: ${{ github.token }}