antlr-rust-runtime 0.9.2

High performance Rust runtime and target support for ANTLR v4 generated parsers
Documentation
name: Publish Crate

on:
  release:
    types:
      - published

concurrency:
  group: ${{ github.workflow }}
  cancel-in-progress: true

permissions:
  contents: write
  id-token: write
  repository-projects: write

env:
  CARGO_TERM_COLOR: always

jobs:
  publish:
    name: Publish to crates.io
    runs-on: ubuntu-latest
    environment: release

    steps:
      - name: Generate GitHub App token
        id: app-token
        uses: actions/create-github-app-token@v3
        with:
          app-id: ${{ vars.APP_ID }}
          private-key: ${{ secrets.APP_PRIVATE_KEY }}

      - name: Checkout
        uses: actions/checkout@v7
        with:
          fetch-depth: 0
          token: ${{ steps.app-token.outputs.token }}

      - name: Install stable Rust
        run: |
          rustup toolchain install stable --profile minimal --no-self-update
          rustup default stable

      - name: Install cargo-edit
        uses: taiki-e/cache-cargo-install-action@v3
        with:
          tool: cargo-edit
          git: https://github.com/killercup/cargo-edit
          rev: 98d58b713cb9a7715c01053dbd36cb84f3be1e4f # v0.13.11
      - name: Extract version from release tag
        id: version
        run: |
          TAG="${{ github.event.release.tag_name }}"
          VERSION="${TAG#v}"
          MAJOR_MINOR="$(echo "$VERSION" | cut -d. -f1,2)"
          echo "version=$VERSION" >> $GITHUB_OUTPUT
          echo "major_minor=$MAJOR_MINOR" >> $GITHUB_OUTPUT
          echo "Release version: $VERSION (README requirement: $MAJOR_MINOR)"

      - name: Update Cargo.toml, Cargo.lock, and README
        run: |
          cargo set-version ${{ steps.version.outputs.version }}
          MAJOR_MINOR="${{ steps.version.outputs.major_minor }}"
          sed -i -E "s/^antlr-rust-runtime = \".*\"/antlr-rust-runtime = \"${MAJOR_MINOR}\"/" README.md
          if ! grep -q "^antlr-rust-runtime = \"${MAJOR_MINOR}\"" README.md; then
            echo "::error::README.md dependency line not updated to \"${MAJOR_MINOR}\" — the expected 'antlr-rust-runtime = \"...\"' line was not found. Update the sed pattern in publish.yml." >&2
            exit 1
          fi
          git diff Cargo.toml Cargo.lock README.md

      - name: Commit and push version updates
        env:
          GH_TOKEN: ${{ steps.app-token.outputs.token }}
        run: |
          git config user.name "ophiarch[bot]"
          git config user.email "ophiarch[bot]@users.noreply.github.com"
          git add Cargo.toml Cargo.lock README.md
          git commit -m "chore: bump version to ${{ steps.version.outputs.version }}"
          git push origin HEAD:${{ github.event.release.target_commitish }}

      - name: Verify package
        run: cargo publish --dry-run

      - name: Authenticate with crates.io
        id: auth
        uses: rust-lang/crates-io-auth-action@v1.0.5

      - name: Publish to crates.io
        run: cargo publish --locked
        env:
          CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}