trustfall_rustdoc 0.39.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
  # The below settings are based on advice from:
  # https://corrode.dev/blog/tips-for-faster-ci-builds/
  CARGO_INCREMENTAL: 0
  CARGO_PROFILE_TEST_DEBUG: 0

jobs:
  ci-everything:
    name: All CI stages
    runs-on: ubuntu-latest
    needs:
      - lint
      - rust-tests
      - templated-code
    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 }}"
          echo "templated-code: ${{ needs.templated-code.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@v7
        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

  templated-code:
    name: Ensure templated code is up-to-date
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v7
        with:
          persist-credentials: false

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

      # Our strategy: re-run the code generation, and assert that nothing has changed.
      - name: Ensure templated code is up-to-date
        run: |
          set -euxo pipefail
          ./scripts/regenerate_templated_code.sh
          git status | tee /tmp/status.log

          set +e
          grep 'nothing to commit, working tree clean' /tmp/status.log
          result=$?
          set -e

          if [[ "$result" != "0" ]]; then
            git diff
            echo ""
            echo "Running code generation on the templated code produced changes."
            echo "Please update the checked in code to match what the automation generates."
            exit 1
          fi

  rust-tests:
    name: Run tests
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v7
        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 v56
        run: cargo test --no-default-features --features v56

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

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

      # This line is a marker for our version-updating automation.
      # All per-feature tests must be added above this line.
      #
      # 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'
    permissions:
      id-token: write     # Required for OIDC token exchange (Trusted Publishing)
    steps:
      - name: Checkout
        uses: actions/checkout@v7
        with:
          persist-credentials: false

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

      # For Trusted Publishing:
      # https://crates.io/docs/trusted-publishing
      - uses: rust-lang/crates-io-auth-action@v1
        id: auth

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

  tag-version:
    name: Tag the version
    runs-on: ubuntu-latest
    needs:
      - should-publish
      - publish
    if: needs.should-publish.outputs.is_new_version == 'yes' && github.ref == 'refs/heads/main'
    steps:
      - name: Checkout
        uses: actions/checkout@v7
        with:
          persist-credentials: true

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

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

  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@v7
        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@v7
        with:
          persist-credentials: false

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