Skip to content

Commit

Permalink
feat(ci): cache registry baseline rustdoc JSON
Browse files Browse the repository at this point in the history
The latest release (v0.18) of `cargo semver-checks` includes a [feature](obi1kenobi/cargo-semver-checks#339) where the rustdoc JSON files for registry baselines is cached in `target/semver-checks/cache`. The rustdoc JSON files for released crates never changes as the source code on crates.io cannot be changed once a version is published. Thus, it is unnecessary to generate that JSON on every CI run.

We extract a separate action that installs `cargo semver-checks` for us and also sets up a cache. The cache is scoped to released version of the crate, meaning it automatically invalidates once we publish a new version.

This speeds up the `cargo semver-checks` step by 50% which is ~ 1 minute per job.

Pull-Request: #3469.
  • Loading branch information
thomaseizinger authored Feb 28, 2023
1 parent c1bb234 commit 7f5b40a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
28 changes: 28 additions & 0 deletions .github/actions/cargo-semver-checks/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: "Run cargo semver-checks"
description: "Install and run the cargo semver-checks tool"
inputs:
crate:
required: true
description: "The crate to run `cargo semver-checks` on."
runs:
using: "composite"
steps:
- run: wget -q -O- https://github.com/obi1kenobi/cargo-semver-checks/releases/download/v0.18.3/cargo-semver-checks-x86_64-unknown-linux-gnu.tar.gz | tar -xz -C ~/.cargo/bin
shell: bash

- name: Get released version
shell: bash
id: get-released-version
run: |
MAX_STABLE_VERSION=$(curl https://crates.io/api/v1/crates/${{ inputs.crate }} --silent | jq '.crate.max_stable_version')
echo "version=${MAX_STABLE_VERSION}" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
with:
path: ${{ github.workspace }}/target/semver-checks/cache
key: semver-checks-cache-${{ inputs.crate }}-${{ steps.get-released-version.outputs.version }}

- run: cargo semver-checks check-release --package ${{ inputs.crate }} --verbose
shell: bash
env:
CARGO_TERM_VERBOSE: "true"
3 changes: 0 additions & 3 deletions .github/workflows/cache-factory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,3 @@ jobs:

- name: Compile workspace with stable Rust
run: cargo test --all-features --all-targets --workspace --no-run

- name: Render docs
run: cargo doc --all-features --workspace
7 changes: 3 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ jobs:
echo "code=${RESPONSE_CODE}"
echo "code=${RESPONSE_CODE}" >> $GITHUB_OUTPUT
- name: Check public API for semver violations
- uses: ./.github/actions/cargo-semver-checks
if: steps.check-released.outputs.code == 200 # Workaround until https://github.com/obi1kenobi/cargo-semver-check/issues/146 is shipped.
run: |
wget -q -O- https://github.com/obi1kenobi/cargo-semver-checks/releases/download/v0.17.1/cargo-semver-checks-x86_64-unknown-linux-gnu.tar.gz | tar -xz -C ~/.cargo/bin
cargo semver-checks check-release -p ${{ matrix.crate }}
with:
crate: ${{ matrix.crate }}

- name: Enforce no dependency on meta crate
run: |
Expand Down

0 comments on commit 7f5b40a

Please sign in to comment.