mirror of
https://github.com/Swatinem/rust-cache.git
synced 2026-04-21 15:10:26 +00:00
Compare commits
57 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d9a6aef83 | ||
|
|
13b62626e8 | ||
|
|
bd17f4a47e | ||
|
|
469cb0e247 | ||
|
|
3a556350bd | ||
|
|
22de9d98ab | ||
|
|
ed5e89b8ff | ||
|
|
f51f967e15 | ||
|
|
85fb4247b7 | ||
|
|
5084d130b2 | ||
|
|
bc1860267c | ||
|
|
d7ac6f694d | ||
|
|
e18b497796 | ||
|
|
c19371144d | ||
|
|
781e8d91ab | ||
|
|
3d1fa4654a | ||
|
|
c676846f29 | ||
|
|
bf71d02c11 | ||
|
|
8a02ed5e29 | ||
|
|
390157d487 | ||
|
|
68500c182e | ||
|
|
1a8384176d | ||
|
|
11da8522bc | ||
|
|
5e4a767433 | ||
|
|
0aa729bb7a | ||
|
|
6cda4ba16e | ||
|
|
e73b99eeb0 | ||
|
|
42c55942cf | ||
|
|
73cfdf196a | ||
|
|
151eeee51b | ||
|
|
779680da71 | ||
|
|
2ea64efb25 | ||
|
|
8930d9c33e | ||
|
|
c071727fc9 | ||
|
|
f2a41b7c11 | ||
|
|
e306f83d21 | ||
|
|
c9119007a1 | ||
|
|
3aaed5547e | ||
|
|
972b315a82 | ||
|
|
07caf06f7a | ||
|
|
a84bfdc502 | ||
|
|
7ec422fc69 | ||
|
|
b28feea9c9 | ||
|
|
54f69366a5 | ||
|
|
27f6075dd2 | ||
|
|
94162284cf | ||
|
|
2245981121 | ||
|
|
51dda28b91 | ||
|
|
20d8423432 | ||
|
|
b08fc8f955 | ||
|
|
bf8c594800 | ||
|
|
a1f94902a6 | ||
|
|
eb57cd6af8 | ||
|
|
90fd0618bc | ||
|
|
2a0d153b42 | ||
|
|
14cb63c99f | ||
|
|
7bd5339b5b |
34
.github/workflows/binstall.yml
vendored
Normal file
34
.github/workflows/binstall.yml
vendored
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
name: binstall
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
binstall:
|
||||||
|
if: github.repository == 'Swatinem/rust-cache'
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
|
|
||||||
|
name: Test `cargo binstall` on ${{ matrix.os }}
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
|
env:
|
||||||
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- run: rustup toolchain install stable --profile minimal --no-self-update
|
||||||
|
|
||||||
|
- uses: cargo-bins/cargo-binstall@v1.18.1
|
||||||
|
|
||||||
|
- uses: ./
|
||||||
|
|
||||||
|
- run: cargo binstall -y cargo-deny
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
6
.github/workflows/buildjet.yml
vendored
6
.github/workflows/buildjet.yml
vendored
@@ -2,6 +2,8 @@ name: buildjet
|
|||||||
|
|
||||||
on: [push, pull_request]
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
buildjet:
|
buildjet:
|
||||||
if: github.repository == 'Swatinem/rust-cache'
|
if: github.repository == 'Swatinem/rust-cache'
|
||||||
@@ -17,7 +19,9 @@ jobs:
|
|||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
- run: rustup toolchain install stable --profile minimal --no-self-update
|
- run: rustup toolchain install stable --profile minimal --no-self-update
|
||||||
|
|
||||||
|
|||||||
16
.github/workflows/check-dist.yml
vendored
16
.github/workflows/check-dist.yml
vendored
@@ -11,17 +11,21 @@ on:
|
|||||||
- "**.md"
|
- "**.md"
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
check-dist:
|
check-dist:
|
||||||
if: github.repository == 'Swatinem/rust-cache'
|
if: github.repository == 'Swatinem/rust-cache'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
|
||||||
- name: Setup Node.js 20.x
|
|
||||||
uses: actions/setup-node@v5
|
|
||||||
with:
|
with:
|
||||||
node-version: 20.x
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: Setup Node.js 24.x
|
||||||
|
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
|
||||||
|
with:
|
||||||
|
node-version: 24.x
|
||||||
cache: npm
|
cache: npm
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
@@ -39,7 +43,7 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
id: diff
|
id: diff
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v4
|
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||||
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
|
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
|
||||||
with:
|
with:
|
||||||
name: dist
|
name: dist
|
||||||
|
|||||||
10
.github/workflows/coverage.yml
vendored
10
.github/workflows/coverage.yml
vendored
@@ -2,6 +2,8 @@ name: coverage
|
|||||||
|
|
||||||
on: [push, pull_request]
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
coverage:
|
coverage:
|
||||||
if: github.repository == 'Swatinem/rust-cache'
|
if: github.repository == 'Swatinem/rust-cache'
|
||||||
@@ -17,11 +19,15 @@ jobs:
|
|||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
- run: rustup toolchain install stable --profile minimal --component llvm-tools-preview --no-self-update
|
- run: rustup toolchain install stable --profile minimal --component llvm-tools-preview --no-self-update
|
||||||
|
|
||||||
- uses: taiki-e/install-action@cargo-llvm-cov
|
- uses: taiki-e/install-action@055f5df8c3f65ea01cd41e9dc855becd88953486 # v2.75.18
|
||||||
|
with:
|
||||||
|
tool: cargo-llvm-cov
|
||||||
|
|
||||||
- uses: ./
|
- uses: ./
|
||||||
with:
|
with:
|
||||||
|
|||||||
16
.github/workflows/dependabot.yml
vendored
16
.github/workflows/dependabot.yml
vendored
@@ -3,23 +3,25 @@
|
|||||||
name: Dependabot Automation
|
name: Dependabot Automation
|
||||||
on: pull_request
|
on: pull_request
|
||||||
|
|
||||||
permissions:
|
permissions: {}
|
||||||
contents: write
|
|
||||||
pull-requests: write
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
automerge:
|
automerge:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: write # for pushing commits
|
||||||
|
pull-requests: write # for merging PRs
|
||||||
if: github.event.pull_request.user.login == 'dependabot[bot]' && github.repository == 'Swatinem/rust-cache'
|
if: github.event.pull_request.user.login == 'dependabot[bot]' && github.repository == 'Swatinem/rust-cache'
|
||||||
steps:
|
steps:
|
||||||
- name: Fetch metadata
|
- name: Fetch metadata
|
||||||
id: metadata
|
id: metadata
|
||||||
uses: dependabot/fetch-metadata@v2
|
uses: dependabot/fetch-metadata@25dd0e34f4fe68f24cc83900b1fe3fe149efef98 # v3.1.0
|
||||||
with:
|
with:
|
||||||
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
with:
|
with:
|
||||||
fetch-depth: 2
|
fetch-depth: 2
|
||||||
|
persist-credentials: false
|
||||||
if: steps.metadata.outputs.update-type == 'version-update:semver-patch'
|
if: steps.metadata.outputs.update-type == 'version-update:semver-patch'
|
||||||
- name: Check if package-lock.json has been changed
|
- name: Check if package-lock.json has been changed
|
||||||
if: steps.metadata.outputs.update-type == 'version-update:semver-patch'
|
if: steps.metadata.outputs.update-type == 'version-update:semver-patch'
|
||||||
@@ -35,9 +37,9 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
- name: Setup node if necessary
|
- name: Setup node if necessary
|
||||||
if: steps.npm.outputs.changed != ''
|
if: steps.npm.outputs.changed != ''
|
||||||
uses: actions/setup-node@v5
|
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
|
||||||
with:
|
with:
|
||||||
node-version: 20.x
|
node-version: 24.x
|
||||||
cache: npm
|
cache: npm
|
||||||
- name: Re-generate and commit dist/ if changed
|
- name: Re-generate and commit dist/ if changed
|
||||||
id: amend
|
id: amend
|
||||||
|
|||||||
6
.github/workflows/git-registry.yml
vendored
6
.github/workflows/git-registry.yml
vendored
@@ -2,6 +2,8 @@ name: git-registry
|
|||||||
|
|
||||||
on: [push, pull_request]
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
git-registry:
|
git-registry:
|
||||||
if: github.repository == 'Swatinem/rust-cache'
|
if: github.repository == 'Swatinem/rust-cache'
|
||||||
@@ -18,7 +20,9 @@ jobs:
|
|||||||
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: git
|
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: git
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
- run: rustup toolchain install stable --profile minimal --no-self-update
|
- run: rustup toolchain install stable --profile minimal --no-self-update
|
||||||
|
|
||||||
|
|||||||
6
.github/workflows/install.yml
vendored
6
.github/workflows/install.yml
vendored
@@ -2,6 +2,8 @@ name: install
|
|||||||
|
|
||||||
on: [push, pull_request]
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
install:
|
install:
|
||||||
if: github.repository == 'Swatinem/rust-cache'
|
if: github.repository == 'Swatinem/rust-cache'
|
||||||
@@ -17,7 +19,9 @@ jobs:
|
|||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
- run: rustup toolchain install stable --profile minimal --no-self-update
|
- run: rustup toolchain install stable --profile minimal --no-self-update
|
||||||
|
|
||||||
|
|||||||
74
.github/workflows/multi-job-cache.yml
vendored
Normal file
74
.github/workflows/multi-job-cache.yml
vendored
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
name: multi-job-cache
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
multi-job-cache-1:
|
||||||
|
if: github.repository == 'Swatinem/rust-cache'
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
|
|
||||||
|
name: Test multi-job cache (1) on ${{ matrix.os }}
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
|
env:
|
||||||
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: checkout
|
||||||
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: install rust toolchain
|
||||||
|
run: rustup toolchain install stable --profile minimal --target wasm32-unknown-unknown --no-self-update
|
||||||
|
|
||||||
|
- name: cache
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
workspaces: |
|
||||||
|
tests
|
||||||
|
add-job-id-key: "false"
|
||||||
|
add-rust-environment-hash-key: "false"
|
||||||
|
|
||||||
|
- name: cargo check (tests)
|
||||||
|
working-directory: tests
|
||||||
|
run: cargo check
|
||||||
|
|
||||||
|
multi-job-cache-2:
|
||||||
|
if: github.repository == 'Swatinem/rust-cache'
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
|
|
||||||
|
name: Test multi-job cache (2) on ${{ matrix.os }}
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
|
env:
|
||||||
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: checkout
|
||||||
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: install rust toolchain
|
||||||
|
run: rustup toolchain install stable --profile minimal --target wasm32-unknown-unknown --no-self-update
|
||||||
|
|
||||||
|
- name: cache
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
workspaces: |
|
||||||
|
tests/wasm-workspace
|
||||||
|
add-job-id-key: "false"
|
||||||
|
add-rust-environment-hash-key: "false"
|
||||||
|
|
||||||
|
- name: cargo check (tests/wasm-workspace)
|
||||||
|
working-directory: tests/wasm-workspace
|
||||||
|
run: cargo check
|
||||||
33
.github/workflows/nix.yml
vendored
Normal file
33
.github/workflows/nix.yml
vendored
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
name: nix
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
nix:
|
||||||
|
if: github.repository == 'Swatinem/rust-cache'
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, macos-latest]
|
||||||
|
|
||||||
|
name: Test Nix on ${{ matrix.os }}
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- uses: cachix/install-nix-action@616559265b40713947b9c190a8ff4b507b5df49b # v31.10.4
|
||||||
|
|
||||||
|
- uses: ./
|
||||||
|
with:
|
||||||
|
workspaces: tests
|
||||||
|
cmd-format: nix develop ./tests -c {0}
|
||||||
|
|
||||||
|
- run: |
|
||||||
|
nix develop -c cargo check
|
||||||
|
nix develop -c cargo test
|
||||||
|
working-directory: tests
|
||||||
6
.github/workflows/simple.yml
vendored
6
.github/workflows/simple.yml
vendored
@@ -2,6 +2,8 @@ name: simple
|
|||||||
|
|
||||||
on: [push, pull_request]
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
simple:
|
simple:
|
||||||
if: github.repository == 'Swatinem/rust-cache'
|
if: github.repository == 'Swatinem/rust-cache'
|
||||||
@@ -17,7 +19,9 @@ jobs:
|
|||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
- run: rustup toolchain install stable --profile minimal --no-self-update
|
- run: rustup toolchain install stable --profile minimal --no-self-update
|
||||||
|
|
||||||
|
|||||||
6
.github/workflows/target-dir.yml
vendored
6
.github/workflows/target-dir.yml
vendored
@@ -2,6 +2,8 @@ name: target-dir
|
|||||||
|
|
||||||
on: [push, pull_request]
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
target-dir:
|
target-dir:
|
||||||
if: github.repository == 'Swatinem/rust-cache'
|
if: github.repository == 'Swatinem/rust-cache'
|
||||||
@@ -17,7 +19,9 @@ jobs:
|
|||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
- run: rustup toolchain install stable --profile minimal --no-self-update
|
- run: rustup toolchain install stable --profile minimal --no-self-update
|
||||||
|
|
||||||
|
|||||||
6
.github/workflows/workspaces.yml
vendored
6
.github/workflows/workspaces.yml
vendored
@@ -2,6 +2,8 @@ name: workspaces
|
|||||||
|
|
||||||
on: [push, pull_request]
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
workspaces:
|
workspaces:
|
||||||
if: github.repository == 'Swatinem/rust-cache'
|
if: github.repository == 'Swatinem/rust-cache'
|
||||||
@@ -17,7 +19,9 @@ jobs:
|
|||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
- run: rustup toolchain install stable --profile minimal --target wasm32-unknown-unknown --no-self-update
|
- run: rustup toolchain install stable --profile minimal --target wasm32-unknown-unknown --no-self-update
|
||||||
|
|
||||||
|
|||||||
24
.github/workflows/zizmor.yml
vendored
Normal file
24
.github/workflows/zizmor.yml
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
name: GitHub Actions Security Analysis with zizmor 🌈
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: ["main"]
|
||||||
|
pull_request:
|
||||||
|
branches: ["**"]
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
zizmor:
|
||||||
|
name: Run zizmor 🌈
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
security-events: write # for uploading results to the Security tab
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: Run zizmor 🌈
|
||||||
|
uses: zizmorcore/zizmor-action@b1d7e1fb5de872772f31590499237e7cce841e8e # v0.5.3
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,5 +1,6 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
target/
|
target/
|
||||||
|
src/*.js
|
||||||
|
|
||||||
# Editors
|
# Editors
|
||||||
.idea/
|
.idea/
|
||||||
|
|||||||
15
CHANGELOG.md
15
CHANGELOG.md
@@ -1,5 +1,20 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2.9.1
|
||||||
|
|
||||||
|
- Fix regression in hash calculation
|
||||||
|
|
||||||
|
## 2.9.0
|
||||||
|
|
||||||
|
- Update to `node24`
|
||||||
|
- Support running from within a `nix` shell
|
||||||
|
- Consider all installed toolchains for cache key
|
||||||
|
- Use case-insensitive comparison to determine exact cache hit
|
||||||
|
|
||||||
|
## 2.8.2
|
||||||
|
|
||||||
|
- Don't overwrite env for cargo-metadata call
|
||||||
|
|
||||||
## 2.8.1
|
## 2.8.1
|
||||||
|
|
||||||
- Set empty `CARGO_ENCODED_RUSTFLAGS` when retrieving metadata
|
- Set empty `CARGO_ENCODED_RUSTFLAGS` when retrieving metadata
|
||||||
|
|||||||
35
README.md
35
README.md
@@ -28,6 +28,16 @@ sensible defaults.
|
|||||||
# default: empty
|
# default: empty
|
||||||
key: ""
|
key: ""
|
||||||
|
|
||||||
|
# If the automatic `job`-based cache key should include the job id.
|
||||||
|
# default: "true"
|
||||||
|
add-job-id-key: ""
|
||||||
|
|
||||||
|
# Whether the a hash of the rust environment should be included in the cache key.
|
||||||
|
# This includes a hash of all Cargo.toml/Cargo.lock files, rust-toolchain files,
|
||||||
|
# and .cargo/config.toml files (if present), as well as the specified 'env-vars'.
|
||||||
|
# default: "true"
|
||||||
|
add-rust-environment-hash-key: ""
|
||||||
|
|
||||||
# A whitespace separated list of env-var *prefixes* who's value contributes
|
# A whitespace separated list of env-var *prefixes* who's value contributes
|
||||||
# to the environment cache key.
|
# to the environment cache key.
|
||||||
# The env-vars are matched by *prefix*, so the default `RUST` var will
|
# The env-vars are matched by *prefix*, so the default `RUST` var will
|
||||||
@@ -89,6 +99,16 @@ sensible defaults.
|
|||||||
# Determines whether to cache the ~/.cargo/bin directory.
|
# Determines whether to cache the ~/.cargo/bin directory.
|
||||||
# default: "true"
|
# default: "true"
|
||||||
cache-bin: ""
|
cache-bin: ""
|
||||||
|
|
||||||
|
# A format string used to format commands to be run, i.e. `rustc` and `cargo`.
|
||||||
|
# Must contain exactly one occurance of `{0}`, which is the formatting fragment
|
||||||
|
# that will be replaced with the `rustc` or `cargo` command. This is necessary
|
||||||
|
# when using Nix or other setup that requires running these commands within a
|
||||||
|
# specific shell, otherwise the system `rustc` and `cargo` will be run.
|
||||||
|
# default: "{0}"
|
||||||
|
cmd-format: ""
|
||||||
|
# To run within a Nix shell (using the default dev shell of a flake in the repo root):
|
||||||
|
cmd-format: nix develop -c {0}
|
||||||
```
|
```
|
||||||
|
|
||||||
Further examples are available in the [.github/workflows](./.github/workflows/) directory.
|
Further examples are available in the [.github/workflows](./.github/workflows/) directory.
|
||||||
@@ -121,12 +141,15 @@ This action currently caches the following files/directories:
|
|||||||
|
|
||||||
This cache is automatically keyed by:
|
This cache is automatically keyed by:
|
||||||
|
|
||||||
- the github [`job_id`](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_id),
|
- the github [`job_id`](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_id)
|
||||||
- the rustc release / host / hash,
|
(if `add-job-id-key` is `"true"`),
|
||||||
- the value of some compiler-specific environment variables (eg. RUSTFLAGS, etc), and
|
- the rustc release / host / hash (for all installed toolchains when
|
||||||
- a hash of all `Cargo.lock` / `Cargo.toml` files found anywhere in the repository (if present).
|
available),
|
||||||
- a hash of all `rust-toolchain` / `rust-toolchain.toml` files in the root of the repository (if present).
|
- the following values, if `add-rust-environment-hash-key` is `"true"`:
|
||||||
- a hash of all `.cargo/config.toml` files in the root of the repository (if present).
|
- the value of some compiler-specific environment variables (eg. RUSTFLAGS, etc), and
|
||||||
|
- a hash of all `Cargo.lock` / `Cargo.toml` files found anywhere in the repository (if present).
|
||||||
|
- a hash of all `rust-toolchain` / `rust-toolchain.toml` files in the root of the repository (if present).
|
||||||
|
- a hash of all `.cargo/config.toml` files in the root of the repository (if present).
|
||||||
|
|
||||||
An additional input `key` can be provided if the builtin keys are not sufficient.
|
An additional input `key` can be provided if the builtin keys are not sufficient.
|
||||||
|
|
||||||
|
|||||||
14
action.yml
14
action.yml
@@ -12,6 +12,14 @@ inputs:
|
|||||||
key:
|
key:
|
||||||
description: "An additional cache key that is added alongside the automatic `job`-based cache key and can be used to further differentiate jobs."
|
description: "An additional cache key that is added alongside the automatic `job`-based cache key and can be used to further differentiate jobs."
|
||||||
required: false
|
required: false
|
||||||
|
add-job-id-key:
|
||||||
|
description: "If the automatic `job`-based cache key should include the job id. Defaults to true."
|
||||||
|
required: false
|
||||||
|
default: "true"
|
||||||
|
add-rust-environment-hash-key:
|
||||||
|
description: "Weather the a hash of the rust environment should be included in the cache key. This includes a hash of all Cargo.toml/Cargo.lock files, rust-toolchain files, and .cargo/config.toml files (if present), as well as the specified 'env-vars'. Defaults to true."
|
||||||
|
required: false
|
||||||
|
default: "true"
|
||||||
env-vars:
|
env-vars:
|
||||||
description: "Additional environment variables to include in the cache key, separated by spaces."
|
description: "Additional environment variables to include in the cache key, separated by spaces."
|
||||||
required: false
|
required: false
|
||||||
@@ -52,11 +60,15 @@ inputs:
|
|||||||
description: "Check if a cache entry exists without downloading the cache"
|
description: "Check if a cache entry exists without downloading the cache"
|
||||||
required: false
|
required: false
|
||||||
default: "false"
|
default: "false"
|
||||||
|
cmd-format:
|
||||||
|
description: "A format string used to format commands to be run, i.e. `rustc` and `cargo`."
|
||||||
|
required: false
|
||||||
|
default: "{0}"
|
||||||
outputs:
|
outputs:
|
||||||
cache-hit:
|
cache-hit:
|
||||||
description: "A boolean value that indicates an exact match was found."
|
description: "A boolean value that indicates an exact match was found."
|
||||||
runs:
|
runs:
|
||||||
using: "node20"
|
using: "node24"
|
||||||
main: "dist/restore/index.js"
|
main: "dist/restore/index.js"
|
||||||
post: "dist/save/index.js"
|
post: "dist/save/index.js"
|
||||||
post-if: "success() || env.CACHE_ON_FAILURE == 'true'"
|
post-if: "success() || env.CACHE_ON_FAILURE == 'true'"
|
||||||
|
|||||||
138286
dist/restore/index.js
vendored
138286
dist/restore/index.js
vendored
File diff suppressed because one or more lines are too long
138314
dist/save/index.js
vendored
138314
dist/save/index.js
vendored
File diff suppressed because one or more lines are too long
625
package-lock.json
generated
625
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
20
package.json
20
package.json
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"name": "rust-cache",
|
"name": "rust-cache",
|
||||||
"version": "2.8.1",
|
"version": "2.9.1",
|
||||||
"description": "A GitHub Action that implements smart caching for rust/cargo projects with sensible defaults.",
|
"description": "A GitHub Action that implements smart caching for rust/cargo projects with sensible defaults.",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"actions",
|
"actions",
|
||||||
@@ -24,18 +24,18 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/buildjet-cache": "npm:github-actions.cache-buildjet@0.2.0",
|
"@actions/buildjet-cache": "npm:github-actions.cache-buildjet@0.2.0",
|
||||||
"@actions/warpbuild-cache": "npm:github-actions.warp-cache@1.4.7",
|
"@actions/warpbuild-cache": "npm:github-actions.warp-cache@1.4.7",
|
||||||
"@actions/cache": "^4.0.5",
|
"@actions/cache": "^6.0.0",
|
||||||
"@actions/core": "^1.11.1",
|
"@actions/core": "^3.0.0",
|
||||||
"@actions/exec": "^1.1.1",
|
"@actions/exec": "^3.0.0",
|
||||||
"@actions/glob": "^0.5.0",
|
"@actions/glob": "^0.6.1",
|
||||||
"@actions/io": "^1.1.3",
|
"@actions/io": "^3.0.2",
|
||||||
"smol-toml": "^1.4.2"
|
"smol-toml": "^1.6.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^24.3.0",
|
"@types/node": "^25.6.0",
|
||||||
"@vercel/ncc": "^0.38.3",
|
"@vercel/ncc": "^0.38.4",
|
||||||
"linefix": "^0.1.1",
|
"linefix": "^0.1.1",
|
||||||
"typescript": "5.9.2"
|
"typescript": "6.0.3"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepare": "ncc build --target es2020 -o dist/restore src/restore.ts && ncc build --target es2020 -o dist/save src/save.ts && linefix dist"
|
"prepare": "ncc build --target es2020 -o dist/restore src/restore.ts && ncc build --target es2020 -o dist/save src/save.ts && linefix dist"
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ async function cleanProfileTarget(profileDir: string, packages: Packages, checkT
|
|||||||
let keepProfile = new Set(["build", ".fingerprint", "deps"]);
|
let keepProfile = new Set(["build", ".fingerprint", "deps"]);
|
||||||
await rmExcept(profileDir, keepProfile);
|
await rmExcept(profileDir, keepProfile);
|
||||||
|
|
||||||
const keepPkg = new Set(packages.map((p) => p.name));
|
const keepPkg = new Set(packages.flatMap((p) => [p.name, ...p.targets.map((t) => t.replace(/-/g, "_"))]));
|
||||||
await rmExcept(path.join(profileDir, "build"), keepPkg, checkTimestamp);
|
await rmExcept(path.join(profileDir, "build"), keepPkg, checkTimestamp);
|
||||||
await rmExcept(path.join(profileDir, ".fingerprint"), keepPkg, checkTimestamp);
|
await rmExcept(path.join(profileDir, ".fingerprint"), keepPkg, checkTimestamp);
|
||||||
|
|
||||||
@@ -77,16 +77,16 @@ async function cleanProfileTarget(profileDir: string, packages: Packages, checkT
|
|||||||
|
|
||||||
export async function getCargoBins(): Promise<Set<string>> {
|
export async function getCargoBins(): Promise<Set<string>> {
|
||||||
const bins = new Set<string>();
|
const bins = new Set<string>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { installs }: { installs: { [key: string]: { bins: Array<string> } } } = JSON.parse(
|
const dir = await fs.promises.opendir(path.join(CARGO_HOME, "bin"));
|
||||||
await fs.promises.readFile(path.join(CARGO_HOME, ".crates2.json"), "utf8"),
|
for await (const dirent of dir) {
|
||||||
);
|
if (dirent.isFile()) {
|
||||||
for (const pkg of Object.values(installs)) {
|
bins.add(dirent.name);
|
||||||
for (const bin of pkg.bins) {
|
|
||||||
bins.add(bin);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {}
|
} catch {}
|
||||||
|
|
||||||
return bins;
|
return bins;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,15 +97,11 @@ export async function getCargoBins(): Promise<Set<string>> {
|
|||||||
* @param oldBins The binaries that existed when the action started.
|
* @param oldBins The binaries that existed when the action started.
|
||||||
*/
|
*/
|
||||||
export async function cleanBin(oldBins: Array<string>) {
|
export async function cleanBin(oldBins: Array<string>) {
|
||||||
const bins = await getCargoBins();
|
const binsToRemove = new Set<string>(oldBins);
|
||||||
|
|
||||||
for (const bin of oldBins) {
|
|
||||||
bins.delete(bin);
|
|
||||||
}
|
|
||||||
|
|
||||||
const dir = await fs.promises.opendir(path.join(CARGO_HOME, "bin"));
|
const dir = await fs.promises.opendir(path.join(CARGO_HOME, "bin"));
|
||||||
for await (const dirent of dir) {
|
for await (const dirent of dir) {
|
||||||
if (dirent.isFile() && !bins.has(dirent.name)) {
|
if (dirent.isFile() && binsToRemove.has(dirent.name)) {
|
||||||
await rm(dir.path, dirent);
|
await rm(dir.path, dirent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
263
src/config.ts
263
src/config.ts
@@ -1,8 +1,8 @@
|
|||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import * as glob from "@actions/glob";
|
import * as glob from "@actions/glob";
|
||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
import fs from "fs";
|
import fs from "fs/promises";
|
||||||
import fs_promises from "fs/promises";
|
import { createReadStream } from "fs";
|
||||||
import os from "os";
|
import os from "os";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import * as toml from "smol-toml";
|
import * as toml from "smol-toml";
|
||||||
@@ -18,6 +18,9 @@ const STATE_CONFIG = "RUST_CACHE_CONFIG";
|
|||||||
const HASH_LENGTH = 8;
|
const HASH_LENGTH = 8;
|
||||||
|
|
||||||
export class CacheConfig {
|
export class CacheConfig {
|
||||||
|
/** A format string for running commands */
|
||||||
|
public cmdFormat: string = "";
|
||||||
|
|
||||||
/** All the paths we want to cache */
|
/** All the paths we want to cache */
|
||||||
public cachePaths: Array<string> = [];
|
public cachePaths: Array<string> = [];
|
||||||
/** The primary cache key */
|
/** The primary cache key */
|
||||||
@@ -37,7 +40,7 @@ export class CacheConfig {
|
|||||||
/** The prefix portion of the cache key */
|
/** The prefix portion of the cache key */
|
||||||
private keyPrefix = "";
|
private keyPrefix = "";
|
||||||
/** The rust version considered for the cache key */
|
/** The rust version considered for the cache key */
|
||||||
private keyRust = "";
|
private keyRust: Array<string> = [];
|
||||||
/** The environment variables considered for the cache key */
|
/** The environment variables considered for the cache key */
|
||||||
private keyEnvs: Array<string> = [];
|
private keyEnvs: Array<string> = [];
|
||||||
/** The files considered for the cache key */
|
/** The files considered for the cache key */
|
||||||
@@ -53,6 +56,17 @@ export class CacheConfig {
|
|||||||
static async new(): Promise<CacheConfig> {
|
static async new(): Promise<CacheConfig> {
|
||||||
const self = new CacheConfig();
|
const self = new CacheConfig();
|
||||||
|
|
||||||
|
let cmdFormat = core.getInput("cmd-format");
|
||||||
|
if (cmdFormat) {
|
||||||
|
const placeholderMatches = cmdFormat.match(/\{0\}/g);
|
||||||
|
if (!placeholderMatches || placeholderMatches.length !== 1) {
|
||||||
|
cmdFormat = "{0}";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cmdFormat = "{0}";
|
||||||
|
}
|
||||||
|
self.cmdFormat = cmdFormat;
|
||||||
|
|
||||||
// Construct key prefix:
|
// Construct key prefix:
|
||||||
// This uses either the `shared-key` input,
|
// This uses either the `shared-key` input,
|
||||||
// or the `key` input combined with the `job` key.
|
// or the `key` input combined with the `job` key.
|
||||||
@@ -69,7 +83,7 @@ export class CacheConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const job = process.env.GITHUB_JOB;
|
const job = process.env.GITHUB_JOB;
|
||||||
if (job) {
|
if (job && core.getInput("add-job-id-key").toLowerCase() == "true") {
|
||||||
key += `-${job}`;
|
key += `-${job}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,14 +103,16 @@ export class CacheConfig {
|
|||||||
// resulting environment hash.
|
// resulting environment hash.
|
||||||
|
|
||||||
let hasher = crypto.createHash("sha1");
|
let hasher = crypto.createHash("sha1");
|
||||||
const rustVersion = await getRustVersion();
|
const rustVersions = Array.from(await getRustVersions(cmdFormat));
|
||||||
|
// Doesn't matter how they're sorted, just as long as it's deterministic.
|
||||||
|
rustVersions.sort();
|
||||||
|
|
||||||
let keyRust = `${rustVersion.release} ${rustVersion.host}`;
|
for (const rustVersion of rustVersions) {
|
||||||
hasher.update(keyRust);
|
const { release, host, "commit-hash": commitHash } = rustVersion;
|
||||||
hasher.update(rustVersion["commit-hash"]);
|
const keyRust = `${release} ${host} ${commitHash}`;
|
||||||
|
hasher.update(keyRust);
|
||||||
keyRust += ` (${rustVersion["commit-hash"]})`;
|
self.keyRust.push(keyRust);
|
||||||
self.keyRust = keyRust;
|
}
|
||||||
|
|
||||||
// these prefixes should cover most of the compiler / rust / cargo keys
|
// these prefixes should cover most of the compiler / rust / cargo keys
|
||||||
const envPrefixes = ["CARGO", "CC", "CFLAGS", "CXX", "CMAKE", "RUST"];
|
const envPrefixes = ["CARGO", "CC", "CFLAGS", "CXX", "CMAKE", "RUST"];
|
||||||
@@ -116,7 +132,10 @@ export class CacheConfig {
|
|||||||
|
|
||||||
self.keyEnvs = keyEnvs;
|
self.keyEnvs = keyEnvs;
|
||||||
|
|
||||||
key += `-${digest(hasher)}`;
|
// Add job hash suffix if 'add-rust-environment-hash-key' is true
|
||||||
|
if (core.getInput("add-rust-environment-hash-key").toLowerCase() == "true") {
|
||||||
|
key += `-${digest(hasher)}`;
|
||||||
|
}
|
||||||
|
|
||||||
self.restoreKey = key;
|
self.restoreKey = key;
|
||||||
|
|
||||||
@@ -139,111 +158,115 @@ export class CacheConfig {
|
|||||||
}
|
}
|
||||||
self.workspaces = workspaces;
|
self.workspaces = workspaces;
|
||||||
|
|
||||||
let keyFiles = await globFiles(".cargo/config.toml\nrust-toolchain\nrust-toolchain.toml");
|
// Add hash suffix of all rust environment lockfiles + manifests if
|
||||||
const parsedKeyFiles = []; // keyFiles that are parsed, pre-processed and hashed
|
// 'add-rust-environment-hash-key' is true
|
||||||
|
if (core.getInput("add-rust-environment-hash-key").toLowerCase() == "true") {
|
||||||
|
let keyFiles = await globFiles(".cargo/config.toml\nrust-toolchain\nrust-toolchain.toml");
|
||||||
|
const parsedKeyFiles = []; // keyFiles that are parsed, pre-processed and hashed
|
||||||
|
|
||||||
hasher = crypto.createHash("sha1");
|
hasher = crypto.createHash("sha1");
|
||||||
|
|
||||||
for (const workspace of workspaces) {
|
for (const workspace of workspaces) {
|
||||||
const root = workspace.root;
|
const root = workspace.root;
|
||||||
keyFiles.push(
|
keyFiles.push(
|
||||||
...(await globFiles(
|
...(await globFiles(
|
||||||
`${root}/**/.cargo/config.toml\n${root}/**/rust-toolchain\n${root}/**/rust-toolchain.toml`,
|
`${root}/**/.cargo/config.toml\n${root}/**/rust-toolchain\n${root}/**/rust-toolchain.toml`,
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
|
|
||||||
const workspaceMembers = await workspace.getWorkspaceMembers();
|
const workspaceMembers = await workspace.getWorkspaceMembers(cmdFormat);
|
||||||
|
|
||||||
const cargo_manifests = sort_and_uniq(workspaceMembers.map((member) => path.join(member.path, "Cargo.toml")));
|
const cargo_manifests = sort_and_uniq(workspaceMembers.map((member) => path.join(member.path, "Cargo.toml")));
|
||||||
|
|
||||||
for (const cargo_manifest of cargo_manifests) {
|
for (const cargo_manifest of cargo_manifests) {
|
||||||
try {
|
try {
|
||||||
const content = await fs_promises.readFile(cargo_manifest, { encoding: "utf8" });
|
const content = await fs.readFile(cargo_manifest, { encoding: "utf8" });
|
||||||
// Use any since TomlPrimitive is not exposed
|
// Use any since TomlPrimitive is not exposed
|
||||||
const parsed = toml.parse(content) as { [key: string]: any };
|
const parsed = toml.parse(content) as { [key: string]: any };
|
||||||
|
|
||||||
if ("package" in parsed) {
|
if ("package" in parsed) {
|
||||||
const pack = parsed.package;
|
const pack = parsed.package;
|
||||||
if ("version" in pack) {
|
if ("version" in pack) {
|
||||||
pack["version"] = "0.0.0";
|
pack["version"] = "0.0.0";
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const prefix of ["", "build-", "dev-"]) {
|
|
||||||
const section_name = `${prefix}dependencies`;
|
|
||||||
if (!(section_name in parsed)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const deps = parsed[section_name];
|
|
||||||
|
|
||||||
for (const key of Object.keys(deps)) {
|
|
||||||
const dep = deps[key];
|
|
||||||
|
|
||||||
try {
|
|
||||||
if ("path" in dep) {
|
|
||||||
dep.version = "0.0.0";
|
|
||||||
dep.path = "";
|
|
||||||
}
|
|
||||||
} catch (_e) {
|
|
||||||
// Not an object, probably a string (version),
|
|
||||||
// continue.
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const prefix of ["", "build-", "dev-"]) {
|
||||||
|
const section_name = `${prefix}dependencies`;
|
||||||
|
if (!(section_name in parsed)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const deps = parsed[section_name];
|
||||||
|
|
||||||
|
for (const key of Object.keys(deps)) {
|
||||||
|
const dep = deps[key];
|
||||||
|
|
||||||
|
try {
|
||||||
|
if ("path" in dep) {
|
||||||
|
dep.version = "0.0.0";
|
||||||
|
dep.path = "";
|
||||||
|
}
|
||||||
|
} catch (_e) {
|
||||||
|
// Not an object, probably a string (version),
|
||||||
|
// continue.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hasher.update(JSON.stringify(parsed));
|
||||||
|
|
||||||
|
parsedKeyFiles.push(cargo_manifest);
|
||||||
|
} catch (e) {
|
||||||
|
// Fallback to caching them as regular file
|
||||||
|
core.warning(`Error parsing Cargo.toml manifest, fallback to caching entire file: ${e}`);
|
||||||
|
keyFiles.push(cargo_manifest);
|
||||||
}
|
}
|
||||||
|
|
||||||
hasher.update(JSON.stringify(parsed));
|
|
||||||
|
|
||||||
parsedKeyFiles.push(cargo_manifest);
|
|
||||||
} catch (e) {
|
|
||||||
// Fallback to caching them as regular file
|
|
||||||
core.warning(`Error parsing Cargo.toml manifest, fallback to caching entire file: ${e}`);
|
|
||||||
keyFiles.push(cargo_manifest);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const cargo_lock = path.join(workspace.root, "Cargo.lock");
|
const cargo_lock = path.join(workspace.root, "Cargo.lock");
|
||||||
if (await exists(cargo_lock)) {
|
if (await exists(cargo_lock)) {
|
||||||
try {
|
try {
|
||||||
const content = await fs_promises.readFile(cargo_lock, { encoding: "utf8" });
|
const content = await fs.readFile(cargo_lock, { encoding: "utf8" });
|
||||||
const parsed = toml.parse(content);
|
const parsed = toml.parse(content);
|
||||||
|
|
||||||
if ((parsed.version !== 3 && parsed.version !== 4) || !("package" in parsed)) {
|
if ((parsed.version !== 3 && parsed.version !== 4) || !("package" in parsed)) {
|
||||||
// Fallback to caching them as regular file since this action
|
// Fallback to caching them as regular file since this action
|
||||||
// can only handle Cargo.lock format version 3
|
// can only handle Cargo.lock format version 3
|
||||||
core.warning("Unsupported Cargo.lock format, fallback to caching entire file");
|
core.warning("Unsupported Cargo.lock format, fallback to caching entire file");
|
||||||
|
keyFiles.push(cargo_lock);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Package without `[[package]].source` and `[[package]].checksum`
|
||||||
|
// are the one with `path = "..."` to crates within the workspace.
|
||||||
|
const packages = (parsed.package as any[]).filter((p: any) => "source" in p || "checksum" in p);
|
||||||
|
|
||||||
|
hasher.update(JSON.stringify(packages));
|
||||||
|
|
||||||
|
parsedKeyFiles.push(cargo_lock);
|
||||||
|
} catch (e) {
|
||||||
|
// Fallback to caching them as regular file
|
||||||
|
core.warning(`Error parsing Cargo.lock manifest, fallback to caching entire file: ${e}`);
|
||||||
keyFiles.push(cargo_lock);
|
keyFiles.push(cargo_lock);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Package without `[[package]].source` and `[[package]].checksum`
|
|
||||||
// are the one with `path = "..."` to crates within the workspace.
|
|
||||||
const packages = (parsed.package as any[]).filter((p: any) => "source" in p || "checksum" in p);
|
|
||||||
|
|
||||||
hasher.update(JSON.stringify(packages));
|
|
||||||
|
|
||||||
parsedKeyFiles.push(cargo_lock);
|
|
||||||
} catch (e) {
|
|
||||||
// Fallback to caching them as regular file
|
|
||||||
core.warning(`Error parsing Cargo.lock manifest, fallback to caching entire file: ${e}`);
|
|
||||||
keyFiles.push(cargo_lock);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
keyFiles = sort_and_uniq(keyFiles);
|
||||||
keyFiles = sort_and_uniq(keyFiles);
|
|
||||||
|
|
||||||
for (const file of keyFiles) {
|
for (const file of keyFiles) {
|
||||||
for await (const chunk of fs.createReadStream(file)) {
|
for await (const chunk of createReadStream(file)) {
|
||||||
hasher.update(chunk);
|
hasher.update(chunk);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
keyFiles.push(...parsedKeyFiles);
|
||||||
|
self.keyFiles = sort_and_uniq(keyFiles);
|
||||||
|
|
||||||
|
let lockHash = digest(hasher);
|
||||||
|
key += `-${lockHash}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
let lockHash = digest(hasher);
|
|
||||||
|
|
||||||
keyFiles.push(...parsedKeyFiles);
|
|
||||||
self.keyFiles = sort_and_uniq(keyFiles);
|
|
||||||
|
|
||||||
key += `-${lockHash}`;
|
|
||||||
self.cacheKey = key;
|
self.cacheKey = key;
|
||||||
|
|
||||||
self.cachePaths = [path.join(CARGO_HOME, "registry"), path.join(CARGO_HOME, "git")];
|
self.cachePaths = [path.join(CARGO_HOME, "registry"), path.join(CARGO_HOME, "git")];
|
||||||
@@ -314,7 +337,10 @@ export class CacheConfig {
|
|||||||
core.info(`.. Prefix:`);
|
core.info(`.. Prefix:`);
|
||||||
core.info(` - ${this.keyPrefix}`);
|
core.info(` - ${this.keyPrefix}`);
|
||||||
core.info(`.. Environment considered:`);
|
core.info(`.. Environment considered:`);
|
||||||
core.info(` - Rust Version: ${this.keyRust}`);
|
core.info(` - Rust Versions:`);
|
||||||
|
for (const rust of this.keyRust) {
|
||||||
|
core.info(` - ${rust}`);
|
||||||
|
}
|
||||||
for (const env of this.keyEnvs) {
|
for (const env of this.keyEnvs) {
|
||||||
core.info(` - ${env}`);
|
core.info(` - ${env}`);
|
||||||
}
|
}
|
||||||
@@ -359,9 +385,33 @@ interface RustVersion {
|
|||||||
"commit-hash": string;
|
"commit-hash": string;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getRustVersion(): Promise<RustVersion> {
|
async function getRustVersions(cmdFormat: string): Promise<Set<RustVersion>> {
|
||||||
const stdout = await getCmdOutput("rustc", ["-vV"]);
|
const versions = new Set<RustVersion>();
|
||||||
let splits = stdout
|
|
||||||
|
versions.add(parseRustVersion(await getCmdOutput(cmdFormat, "rustc -vV")));
|
||||||
|
|
||||||
|
const stdout = await (async () => {
|
||||||
|
try {
|
||||||
|
return await getCmdOutput(cmdFormat, "rustup toolchain list --quiet");
|
||||||
|
} catch (e) {
|
||||||
|
core.warning(`Error running rustup toolchain list, falling back to default toolchain only: ${e}`);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
if (stdout !== undefined) {
|
||||||
|
for (const toolchain of stdout.split(/[\n\r]+/)) {
|
||||||
|
const trimmed = toolchain.trim();
|
||||||
|
if (!trimmed) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
versions.add(parseRustVersion(await getCmdOutput(cmdFormat, `rustup run ${toolchain} rustc -vV`)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return versions;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseRustVersion(stdout: string): RustVersion {
|
||||||
|
const splits = stdout
|
||||||
.split(/[\n\r]+/)
|
.split(/[\n\r]+/)
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.map((s) => s.split(":").map((s) => s.trim()))
|
.map((s) => s.split(":").map((s) => s.trim()))
|
||||||
@@ -373,10 +423,17 @@ async function globFiles(pattern: string): Promise<string[]> {
|
|||||||
const globber = await glob.create(pattern, {
|
const globber = await glob.create(pattern, {
|
||||||
followSymbolicLinks: false,
|
followSymbolicLinks: false,
|
||||||
});
|
});
|
||||||
// fs.statSync resolve the symbolic link and returns stat for the
|
// fs.stat resolve the symbolic link and returns stat for the
|
||||||
// file it pointed to, so isFile would make sure the resolved
|
// file it pointed to, so isFile would make sure the resolved
|
||||||
// file is actually a regular file.
|
// file is actually a regular file.
|
||||||
return (await globber.glob()).filter((file) => fs.statSync(file).isFile());
|
const files = [];
|
||||||
|
for (const file of await globber.glob()) {
|
||||||
|
const stats = await fs.stat(file);
|
||||||
|
if (stats.isFile()) {
|
||||||
|
files.push(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sort_and_uniq(a: string[]) {
|
function sort_and_uniq(a: string[]) {
|
||||||
|
|||||||
@@ -42,7 +42,9 @@ async function run() {
|
|||||||
lookupOnly,
|
lookupOnly,
|
||||||
});
|
});
|
||||||
if (restoreKey) {
|
if (restoreKey) {
|
||||||
const match = restoreKey === key;
|
const match = restoreKey.localeCompare(key, undefined, {
|
||||||
|
sensitivity: "accent"
|
||||||
|
}) === 0;
|
||||||
core.info(`${lookupOnly ? "Found" : "Restored from"} cache key "${restoreKey}" full match: ${match}.`);
|
core.info(`${lookupOnly ? "Found" : "Restored from"} cache key "${restoreKey}" full match: ${match}.`);
|
||||||
if (!match) {
|
if (!match) {
|
||||||
// pre-clean the target directory on cache mismatch
|
// pre-clean the target directory on cache mismatch
|
||||||
|
|||||||
@@ -39,9 +39,9 @@ async function run() {
|
|||||||
const workspaceCrates = core.getInput("cache-workspace-crates").toLowerCase() || "false";
|
const workspaceCrates = core.getInput("cache-workspace-crates").toLowerCase() || "false";
|
||||||
const allPackages = [];
|
const allPackages = [];
|
||||||
for (const workspace of config.workspaces) {
|
for (const workspace of config.workspaces) {
|
||||||
const packages = await workspace.getPackagesOutsideWorkspaceRoot();
|
const packages = await workspace.getPackagesOutsideWorkspaceRoot(config.cmdFormat);
|
||||||
if (workspaceCrates === "true") {
|
if (workspaceCrates === "true") {
|
||||||
const wsMembers = await workspace.getWorkspaceMembers();
|
const wsMembers = await workspace.getWorkspaceMembers(config.cmdFormat);
|
||||||
packages.push(...wsMembers);
|
packages.push(...wsMembers);
|
||||||
}
|
}
|
||||||
allPackages.push(...packages);
|
allPackages.push(...packages);
|
||||||
|
|||||||
@@ -16,14 +16,15 @@ export function reportError(e: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getCmdOutput(
|
export async function getCmdOutput(
|
||||||
|
cmdFormat: string,
|
||||||
cmd: string,
|
cmd: string,
|
||||||
args: Array<string> = [],
|
|
||||||
options: exec.ExecOptions = {},
|
options: exec.ExecOptions = {},
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
|
cmd = cmdFormat.replace("{0}", cmd);
|
||||||
let stdout = "";
|
let stdout = "";
|
||||||
let stderr = "";
|
let stderr = "";
|
||||||
try {
|
try {
|
||||||
await exec.exec(cmd, args, {
|
await exec.exec(cmd, [], {
|
||||||
silent: true,
|
silent: true,
|
||||||
listeners: {
|
listeners: {
|
||||||
stdout(data) {
|
stdout(data) {
|
||||||
@@ -37,7 +38,7 @@ export async function getCmdOutput(
|
|||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
(e as any).commandFailed = {
|
(e as any).commandFailed = {
|
||||||
command: `${cmd} ${args.join(" ")}`,
|
command: cmd,
|
||||||
stderr,
|
stderr,
|
||||||
};
|
};
|
||||||
throw e;
|
throw e;
|
||||||
|
|||||||
@@ -3,19 +3,20 @@ import path from "path";
|
|||||||
|
|
||||||
import { getCmdOutput } from "./utils";
|
import { getCmdOutput } from "./utils";
|
||||||
|
|
||||||
const SAVE_TARGETS = new Set(["lib", "proc-macro"]);
|
const SAVE_TARGETS = new Set(["lib", "cdylib", "dylib", "rlib", "staticlib", "proc-macro"]);
|
||||||
|
|
||||||
export class Workspace {
|
export class Workspace {
|
||||||
constructor(public root: string, public target: string) {}
|
constructor(public root: string, public target: string) {}
|
||||||
|
|
||||||
async getPackages(filter: (p: Meta["packages"][0]) => boolean, ...extraArgs: string[]): Promise<Packages> {
|
async getPackages(cmdFormat: string, filter: (p: Meta["packages"][0]) => boolean, extraArgs?: string): Promise<Packages> {
|
||||||
|
const cmd = "cargo metadata --all-features --format-version 1" + (extraArgs ? ` ${extraArgs}` : "");
|
||||||
let packages: Packages = [];
|
let packages: Packages = [];
|
||||||
try {
|
try {
|
||||||
core.debug(`collecting metadata for "${this.root}"`);
|
core.debug(`collecting metadata for "${this.root}"`);
|
||||||
const meta: Meta = JSON.parse(
|
const meta: Meta = JSON.parse(
|
||||||
await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1", ...extraArgs], {
|
await getCmdOutput(cmdFormat, cmd, {
|
||||||
cwd: this.root,
|
cwd: this.root,
|
||||||
env: { "CARGO_ENCODED_RUSTFLAGS": "" },
|
env: { ...process.env, "CARGO_ENCODED_RUSTFLAGS": "" },
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
core.debug(`workspace "${this.root}" has ${meta.packages.length} packages`);
|
core.debug(`workspace "${this.root}" has ${meta.packages.length} packages`);
|
||||||
@@ -29,12 +30,12 @@ export class Workspace {
|
|||||||
return packages;
|
return packages;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getPackagesOutsideWorkspaceRoot(): Promise<Packages> {
|
public async getPackagesOutsideWorkspaceRoot(cmdFormat: string): Promise<Packages> {
|
||||||
return await this.getPackages((pkg) => !pkg.manifest_path.startsWith(this.root));
|
return await this.getPackages(cmdFormat, (pkg) => !pkg.manifest_path.startsWith(this.root));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getWorkspaceMembers(): Promise<Packages> {
|
public async getWorkspaceMembers(cmdFormat: string): Promise<Packages> {
|
||||||
return await this.getPackages((_) => true, "--no-deps");
|
return await this.getPackages(cmdFormat, (_) => true, "--no-deps");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
31
tests/flake.nix
Normal file
31
tests/flake.nix
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
|
||||||
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
|
rust-overlay = {
|
||||||
|
url = "github:oxalica/rust-overlay";
|
||||||
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = inputs @ { self, nixpkgs, flake-utils, rust-overlay, ... }:
|
||||||
|
flake-utils.lib.eachDefaultSystem (
|
||||||
|
system: let
|
||||||
|
overlays = [ (import rust-overlay) ];
|
||||||
|
pkgs = import nixpkgs { inherit system overlays; };
|
||||||
|
in {
|
||||||
|
devShells.default = with pkgs; mkShell {
|
||||||
|
buildInputs = [
|
||||||
|
autoconf
|
||||||
|
gcc
|
||||||
|
gnumake
|
||||||
|
openssl
|
||||||
|
pkg-config
|
||||||
|
rust-bin.stable.latest.minimal
|
||||||
|
];
|
||||||
|
CARGO_TERM_COLOR = "always";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user