2023-02-24 17:35:27 +00:00
|
|
|
name: Lintcheck
|
|
|
|
|
|
|
|
on: pull_request
|
|
|
|
|
|
|
|
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:
|
2024-06-22 12:33:51 +00:00
|
|
|
# Runs lintcheck on the PR's target branch and stores the results as an artifact
|
2023-02-24 17:35:27 +00:00
|
|
|
base:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- name: Checkout
|
|
|
|
uses: actions/checkout@v4
|
|
|
|
with:
|
|
|
|
fetch-depth: 2
|
|
|
|
|
|
|
|
# HEAD is the generated merge commit `refs/pull/N/merge` between the PR and `master`, `HEAD^`
|
|
|
|
# being the commit from `master` 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
|
|
|
|
|
2024-06-22 12:33:51 +00:00
|
|
|
- name: Cache lintcheck bin
|
|
|
|
id: cache-lintcheck-bin
|
|
|
|
uses: actions/cache@v4
|
|
|
|
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
|
|
|
|
|
2023-02-24 17:35:27 +00:00
|
|
|
- name: Create cache key
|
|
|
|
id: key
|
|
|
|
run: echo "key=lintcheck-base-${{ hashfiles('lintcheck/**') }}-$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
|
|
|
|
|
2024-06-22 12:33:51 +00:00
|
|
|
- name: Cache results JSON
|
|
|
|
id: cache-json
|
2023-02-24 17:35:27 +00:00
|
|
|
uses: actions/cache@v4
|
|
|
|
with:
|
2024-07-18 14:32:49 +00:00
|
|
|
path: lintcheck-logs/ci_crates_logs.json
|
2023-02-24 17:35:27 +00:00
|
|
|
key: ${{ steps.key.outputs.key }}
|
|
|
|
|
|
|
|
- name: Run lintcheck
|
2024-06-22 12:33:51 +00:00
|
|
|
if: steps.cache-json.outputs.cache-hit != 'true'
|
2024-08-03 12:10:28 +00:00
|
|
|
run: ./target/debug/lintcheck --format json --all-lints --crates-toml ./lintcheck/ci_crates.toml
|
2023-02-24 17:35:27 +00:00
|
|
|
|
2024-06-22 12:33:51 +00:00
|
|
|
- name: Upload base JSON
|
|
|
|
uses: actions/upload-artifact@v4
|
|
|
|
with:
|
|
|
|
name: base
|
2024-07-18 14:32:49 +00:00
|
|
|
path: lintcheck-logs/ci_crates_logs.json
|
2023-02-24 17:35:27 +00:00
|
|
|
|
2024-06-22 12:33:51 +00:00
|
|
|
# Runs lintcheck on the PR and stores the results as an artifact
|
2023-02-24 17:35:27 +00:00
|
|
|
head:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- name: Checkout
|
|
|
|
uses: actions/checkout@v4
|
|
|
|
|
2024-06-22 12:33:51 +00:00
|
|
|
- name: Cache lintcheck bin
|
|
|
|
id: cache-lintcheck-bin
|
2023-02-24 17:35:27 +00:00
|
|
|
uses: actions/cache@v4
|
|
|
|
with:
|
2024-06-22 12:33:51 +00:00
|
|
|
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
|
2023-02-24 17:35:27 +00:00
|
|
|
|
|
|
|
- name: Run lintcheck
|
2024-08-03 12:10:28 +00:00
|
|
|
run: ./target/debug/lintcheck --format json --all-lints --crates-toml ./lintcheck/ci_crates.toml
|
2023-02-24 17:35:27 +00:00
|
|
|
|
2024-06-22 12:33:51 +00:00
|
|
|
- name: Upload head JSON
|
|
|
|
uses: actions/upload-artifact@v4
|
|
|
|
with:
|
|
|
|
name: head
|
2024-07-18 14:32:49 +00:00
|
|
|
path: lintcheck-logs/ci_crates_logs.json
|
2023-02-24 17:35:27 +00:00
|
|
|
|
2024-06-22 12:33:51 +00:00
|
|
|
# Retrieves the head and base JSON results and prints the diff to the GH actions step summary
|
2023-02-24 17:35:27 +00:00
|
|
|
diff:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
needs: [base, head]
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- name: Checkout
|
|
|
|
uses: actions/checkout@v4
|
|
|
|
|
2024-06-22 12:33:51 +00:00
|
|
|
- name: Restore lintcheck bin
|
2023-02-24 17:35:27 +00:00
|
|
|
uses: actions/cache/restore@v4
|
|
|
|
with:
|
2024-06-22 12:33:51 +00:00
|
|
|
path: target/debug/lintcheck
|
|
|
|
key: lintcheck-bin-${{ hashfiles('lintcheck/**') }}
|
2023-02-24 17:35:27 +00:00
|
|
|
fail-on-cache-miss: true
|
|
|
|
|
2024-06-22 12:33:51 +00:00
|
|
|
- name: Download JSON
|
|
|
|
uses: actions/download-artifact@v4
|
2023-02-24 17:35:27 +00:00
|
|
|
|
|
|
|
- name: Diff results
|
2024-07-21 10:52:55 +00:00
|
|
|
# GH's summery has a maximum size of 1024k:
|
|
|
|
# https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-markdown-summary
|
|
|
|
# That's why we first log to file and then to the summary and logs
|
|
|
|
run: |
|
2024-07-21 12:55:46 +00:00
|
|
|
./target/debug/lintcheck diff {base,head}/ci_crates_logs.json --truncate >> truncated_diff.md
|
|
|
|
head -c 1024000 truncated_diff.md >> $GITHUB_STEP_SUMMARY
|
|
|
|
cat truncated_diff.md
|
2024-07-22 16:14:48 +00:00
|
|
|
./target/debug/lintcheck diff {base,head}/ci_crates_logs.json >> full_diff.md
|
2024-07-21 12:55:46 +00:00
|
|
|
|
|
|
|
- name: Upload full diff
|
|
|
|
uses: actions/upload-artifact@v4
|
|
|
|
with:
|
|
|
|
name: diff
|
2024-07-22 16:10:03 +00:00
|
|
|
if-no-files-found: ignore
|
|
|
|
path: |
|
|
|
|
full_diff.md
|
|
|
|
truncated_diff.md
|