Skip to content

Test lintcheck bin cache #24

Test lintcheck bin cache

Test lintcheck bin cache #24

Workflow file for this run

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:
build-lintcheck:
runs-on: ubuntu-latest
outputs:
key: ${{ steps.cache.outputs.cache-primary-key }}
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/cache@v4
id: cache
with:
path: target/debug/lintcheck
key: lintcheck-bin-${{ hashfiles('lintcheck/**') }}
- name: Build lintcheck
if: steps.cache.outputs.cache-hit != true
run: cargo build --manifest-path=lintcheck/Cargo.toml
# Generates `lintcheck-logs/base.json` and stores it in a cache
base:
runs-on: ubuntu-latest
needs: [build-lintcheck]
outputs:
key: ${{ steps.key.outputs.key }}
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^
- name: Create cache key
id: key
run: echo "key=lintcheck-base-${{ needs.build-lintcheck.outputs.key }}-$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- name: Cache base JSON
id: cache
uses: actions/cache@v4
with:
path: lintcheck-logs/base.json
key: ${{ steps.key.outputs.key }}
- name: Download lintcheck binary
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/cache/restore@v4
with:
key: ${{ needs.build-lintcheck.outputs.key }}
path: target/debug/lintcheck
fail-on-cache-miss: true
- name: Run lintcheck
if: steps.cache.outputs.cache-hit != 'true'
run: target/debug/lintcheck --format json
- name: Rename JSON file
if: steps.cache.outputs.cache-hit != 'true'
run: mv lintcheck-logs/lintcheck_crates_logs.json lintcheck-logs/base.json
# Generates `lintcheck-logs/head.json` and stores it in a cache
head:
runs-on: ubuntu-latest
needs: [build-lintcheck]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download lintcheck binary
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/cache/restore@v4
with:
key: ${{ needs.build-lintcheck.outputs.key }}
path: target/debug/lintcheck
fail-on-cache-miss: true
- name: Run lintcheck
run: ./target/debug/lintcheck --format json
- name: Rename JSON file
run: mv lintcheck-logs/lintcheck_crates_logs.json lintcheck-logs/head.json
- name: Save head JSON
uses: actions/cache/save@v4
with:
key: lintcheck-head-${{ github.sha }}
path: lintcheck-logs/head.json
# Retrieves `lintcheck-logs/base.json` and `lintcheck-logs/head.json` from the cache and prints
# the diff to the GH actions step summary
diff:
runs-on: ubuntu-latest
needs: [build-lintcheck, base, head]
steps:
- name: Download lintcheck binary
if: steps.cache.outputs.cache-hit != 'true'
uses: actions/cache/restore@v4
with:
key: ${{ needs.build-lintcheck.outputs.key }}
path: target/debug/lintcheck
fail-on-cache-miss: true
- name: Restore base JSON
uses: actions/cache/restore@v4
with:
key: ${{ needs.base.outputs.key }}
path: lintcheck-logs/base.json
fail-on-cache-miss: true
- name: Restore head JSON
uses: actions/cache/restore@v4
with:
key: lintcheck-head-${{ github.sha }}
path: lintcheck-logs/head.json
fail-on-cache-miss: true
- name: Diff results
run: ./target/debug/lintcheck diff lintcheck-logs/base.json lintcheck-logs/head.json >> $GITHUB_STEP_SUMMARY