blob: 1168bf48f52d7a262803d7295d8dd07b850f5f7e [file]
name: Lintcheck
on:
pull_request:
paths-ignore:
- 'book/**'
- 'util/**'
- 'tests/**'
- '*.md'
permissions: {}
env:
RUST_BACKTRACE: 1
CARGO_INCREMENTAL: 0
concurrency:
# For a given workflow, if we push to the same PR, cancel all previous builds on that PR.
group: "${{ github.workflow }}-${{ github.event.pull_request.number}}"
cancel-in-progress: true
jobs:
# Runs lintcheck on the PR's target branch and stores the results as an artifact
base:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 2
# Unsetting this would make so that any malicious package could get our Github Token
persist-credentials: false
# HEAD is the generated merge commit `refs/pull/N/merge` between the PR and `main`, `HEAD^`
# being the commit from `main` that is the base of the merge
- name: Checkout base
run: git checkout HEAD^
# Use the lintcheck from the PR to generate the JSON in case the PR modifies lintcheck in some
# way
- name: Checkout current lintcheck
run: |
rm -rf lintcheck
git checkout "${GITHUB_SHA}" -- lintcheck
env:
GITHUB_SHA: ${{ github.sha }}
- name: Cache lintcheck bin
id: cache-lintcheck-bin
uses: actions/cache@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
with:
path: target/debug/lintcheck
key: lintcheck-bin-${{ hashfiles('lintcheck/**') }}
- name: Build lintcheck
if: steps.cache-lintcheck-bin.outputs.cache-hit != 'true'
run: cargo build --manifest-path=lintcheck/Cargo.toml
- name: Create cache key
id: key
run: echo "key=lintcheck-base-${LINTCHECK_FILES_HASH}-$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
env:
LINTCHECK_FILES_HASH: ${{ hashfiles('lintcheck/**') }}
- name: Cache results JSON
id: cache-json
uses: actions/cache@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
with:
path: lintcheck-logs/ci_crates_logs.json
key: ${{ steps.key.outputs.key }}
- name: Run lintcheck
if: steps.cache-json.outputs.cache-hit != 'true'
run: env CLIPPY_CONF_DIR="$PWD/lintcheck/ci-config" ./target/debug/lintcheck --format json --all-lints --crates-toml ./lintcheck/ci_crates.toml
- name: Upload base JSON
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: base
path: lintcheck-logs/ci_crates_logs.json
# Runs lintcheck on the PR and stores the results as an artifact
head:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# Unsetting this would make so that any malicious package could get our Github Token
persist-credentials: false
- name: Cache lintcheck bin
id: cache-lintcheck-bin
uses: actions/cache@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
with:
path: target/debug/lintcheck
key: lintcheck-bin-${{ hashfiles('lintcheck/**') }}
- name: Build lintcheck
if: steps.cache-lintcheck-bin.outputs.cache-hit != 'true'
run: cargo build --manifest-path=lintcheck/Cargo.toml
- name: Run lintcheck
run: env CLIPPY_CONF_DIR="$PWD/lintcheck/ci-config" ./target/debug/lintcheck --format json --all-lints --crates-toml ./lintcheck/ci_crates.toml
- name: Upload head JSON
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: head
path: lintcheck-logs/ci_crates_logs.json
# Retrieves the head and base JSON results and prints the diff to the GH actions step summary
diff:
runs-on: ubuntu-latest
needs: [base, head]
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# Unsetting this would make so that any malicious package could get our Github Token
persist-credentials: false
- name: Restore lintcheck bin
uses: actions/cache/restore@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
with:
path: target/debug/lintcheck
key: lintcheck-bin-${{ hashfiles('lintcheck/**') }}
fail-on-cache-miss: true
- name: Download JSON
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
- name: Store PR number
run: echo "${GITHUB_PR_NUMBER}" > pr.txt
env:
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
- name: Diff results
# GH's summery has a maximum size of 1MiB:
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#step-isolation-and-limits
# We upload the full diff as an artifact in case it's truncated
run: |
./target/debug/lintcheck diff {base,head}/ci_crates_logs.json --truncate | head -c 1M > $GITHUB_STEP_SUMMARY
./target/debug/lintcheck diff {base,head}/ci_crates_logs.json --write-summary summary.json > full_diff.md
- name: Upload full diff
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: full_diff
path: full_diff.md
- name: Upload summary
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: summary
path: |
summary.json
pr.txt