diff --git a/.github/actions/cargo-cache/action.yml b/.github/actions/cargo-cache/action.yml new file mode 100644 index 0000000..5c75bf0 --- /dev/null +++ b/.github/actions/cargo-cache/action.yml @@ -0,0 +1,41 @@ +name: "Cargo Cache" + +inputs: + key: + description: "Unique cache key component" + required: true + + lockfiles: + description: "Paths to Cargo.lock files" + required: true + default: "Cargo.lock" + + targets: + description: "Paths to target directories" + required: true + default: "target" + +runs: + using: "composite" + steps: + # https://doc.rust-lang.org/1.77.2/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci + - name: Cargo cache (home) + uses: actions/cache@v4 + with: + path: |- + /home/runner/.cargo/.crates.toml + /home/runner/.cargo/.crates2.json + /home/runner/.cargo/registry/index/ + /home/runner/.cargo/registry/cache/ + /home/runner/.cargo/git/db/ + key: cargo-home-${{ inputs.key }}-${{ hashFiles(inputs.lockfiles) }} + restore-keys: | + cargo-home-${{ inputs.key }}- + + - name: Cargo cache (build) + uses: actions/cache@v4 + with: + path: ${{ inputs.targets }} + key: cargo-target-${{ inputs.key }}-${{ runner.os }}-${{ hashFiles(inputs.lockfiles) }} + restore-keys: | + cargo-target-${{ inputs.key }}-${{ runner.os }}- diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 63983fd..3d31089 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,6 +48,11 @@ jobs: with: toolchain: stable + - name: Cache Rust + uses: ./.github/actions/cargo-cache + with: + key: assets + - name: Convert assets to Rust run: cargo xtask assets @@ -86,24 +91,10 @@ jobs: toolchain: ${{ matrix.rust }} components: rustfmt, clippy - # https://doc.rust-lang.org/1.77.2/cargo/guide/cargo-home.html#caching-the-cargo-home-in-ci - - name: Cargo cache (platform-independent) - uses: actions/cache@v4 - with: - path: |- - /home/runner/.cargo/.crates.toml - /home/runner/.cargo/.crates2.json - /home/runner/.cargo/registry/index/ - /home/runner/.cargo/registry/cache/ - /home/runner/.cargo/git/db/ - key: cargo-home-${{ matrix.rust }} - - - name: Cargo cache (build) - uses: actions/cache@v4 + - name: Cache Rust + uses: ./.github/actions/cargo-cache with: - path: |- - target - key: cargo-build-${{ runner.os }}-${{ matrix.rust }} + key: build-${{ matrix.rust }} - name: Build code run: cargo build @@ -130,6 +121,23 @@ jobs: name: assets path: src/html + - name: Install Rust + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + components: rustfmt, clippy + + - name: Cache Rust + uses: ./.github/actions/cargo-cache + with: + key: check + lockfiles: |- + Cargo.lock + conformance/Cargo.lock + targets: |- + target + conformance/target + - name: Download binary uses: actions/download-artifact@v4 with: @@ -144,13 +152,6 @@ jobs: echo "${MARGO_BINARY}" "${MARGO_BINARY}" --help - - name: Cargo cache (build conformance) - uses: actions/cache@v4 - with: - path: |- - conformance/target - key: cargo-build-conformance-${{ runner.os }}-${{ matrix.rust }} - - name: Format code run: cargo fmt --all -- --check