trustfall_rustdoc 0.15.0

Run Trustfall queries across multiple rustdoc JSON format versions.
Documentation
name: CI

on:
  pull_request:
  push:
    branches:
      - main

env:
  RUST_BACKTRACE: 1
  CARGO_TERM_COLOR: always

jobs:
  ci-everything:
    name: All CI stages
    runs-on: ubuntu-latest
    needs:
      - lint
      - rust-tests
    if: ${{ success() || failure() }}  # Run this job even if a dependency has failed.
    steps:
      - name: Job outcomes
        run: |
          echo "lint: ${{ needs.lint.result }}"
          echo "rust-tests: ${{ needs.rust-tests.result }}"

      # Fail this required job if any of its dependent jobs have failed.
      #
      # Do not attempt to consolidate these steps into one step, it won't work.
      # Multi-line `if` clauses are not evaluated properly: see the intermediate commits in
      # https://github.com/obi1kenobi/cargo-semver-checks/pull/405
      - if: ${{ needs.lint.result != 'success' }}
        run: exit 1
      - if: ${{ needs.rust-tests.result != 'success' }}
        run: exit 1

  lint:
    name: Check lint and rustfmt
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          persist-credentials: false

      - name: Install rust + caching
        uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          components: rustfmt, clippy
          rustflags: ""

      - name: cargo clippy
        run: cargo clippy --workspace --all-features --all-targets -- -D warnings -Dclippy::print_stdout -Dclippy::print_stderr -Dclippy::dbg_macro --allow deprecated

      - name: cargo fmt
        run: cargo fmt -- --check

      - name: cargo doc
        env:
          RUSTDOCFLAGS: -D warnings
        run: cargo doc --workspace --all-features --no-deps --document-private-items

  rust-tests:
    name: Run tests
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          persist-credentials: false

      - name: Install rust + caching
        uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          rustflags: ""

      # Compile all features all at once
      - name: compile all features
        run: cargo test --no-run --all-features

      # Test features individually
      - name: test rustdoc v27
        run: cargo test --no-default-features --features v27

      - name: test rustdoc v28
        run: cargo test --no-default-features --features v28

      - name: test rustdoc v29
        run: cargo test --no-default-features --features v29

      # Test all features at once; keep this last for caching purposes.
      - name: test all features
        run: cargo test --all-features

  publish:
    name: Publish to crates.io
    runs-on: ubuntu-latest
    needs:
      - should-publish
      - ci-everything
      - pre-publish-checks
    if: needs.should-publish.outputs.is_new_version == 'yes' && github.ref == 'refs/heads/main'
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          persist-credentials: true

      - name: Install rust + caching
        uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          rustflags: ""

      - name: Tag the version
        run: |
          set -euxo pipefail
          export CURRENT_VERSION="$(./scripts/get_current_version.sh trustfall_rustdoc)"
          git tag "v$CURRENT_VERSION"
          git push origin "v$CURRENT_VERSION"

      - name: Publish
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        run: cargo publish

  should-publish:
    name: Check if version changed
    runs-on: ubuntu-latest
    outputs:
      is_new_version: ${{ steps.check.outputs.is_new_version }}
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          persist-credentials: false

      - id: check
        run: |
          set +e
          ./scripts/is_version_already_uploaded.sh trustfall_rustdoc
          export EXIT_CODE="$?"
          set -e
          if [[ "$EXIT_CODE" == "7" ]]; then
            echo "is_new_version=no" >> $GITHUB_OUTPUT
          elif [[ "$EXIT_CODE" == "0" ]]; then
            echo "is_new_version=yes" >> $GITHUB_OUTPUT
          else
            # Unexpected outcome, indicates a bug.
            exit "$EXIT_CODE"
          fi

  pre-publish-checks:
    name: Check for semver compliance
    runs-on: ubuntu-latest
    needs:
      - ci-everything
      - should-publish
    if: needs.should-publish.outputs.is_new_version == 'yes'
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          persist-credentials: false

      - name: Check semver
        uses: obi1kenobi/cargo-semver-checks-action@v2