mirror of
https://github.com/Swatinem/rust-cache
synced 2026-11-02 21:13:59 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d1527c8f67 | ||
|
|
f0fca6fc1c | ||
|
|
b49b17f980 | ||
|
|
6a7bc3ebce | ||
|
|
4ece996238 | ||
|
|
8103aff431 | ||
|
|
0e361f3528 | ||
|
|
f0d9c38877 | ||
|
|
ccd9742ce3 | ||
|
|
258712b0b7 | ||
|
|
a45951ff88 | ||
|
|
b882611972 | ||
|
|
6323deb102 | ||
|
|
b16e8d71b2 | ||
|
|
3bf42ac996 | ||
|
|
6e5b278ead | ||
|
|
5adc05f6aa | ||
|
|
66b1e95261 | ||
|
|
72d126e709 | ||
|
|
48968d2131 | ||
|
|
9f151aca7c | ||
|
|
0e24e5dcec | ||
|
|
7e35be21c2 | ||
|
|
0b5b468d98 | ||
|
|
a31add9f17 | ||
|
|
6dfd3c5062 | ||
|
|
b88d7b9a78 | ||
|
|
cb96ac76d8 | ||
|
|
3cd715cd54 | ||
|
|
2903027c68 | ||
|
|
7e2fe4383b | ||
|
|
baf1a810e9 | ||
|
|
f27557af97 | ||
|
|
c106961fee | ||
|
|
1fe0a60026 | ||
|
|
be9aa033ee | ||
|
|
874b06e0d3 | ||
|
|
8ba370a790 | ||
|
|
65012b4902 | ||
|
|
faada81aeb | ||
|
|
77fc9855f4 | ||
|
|
919333daf4 | ||
|
|
455db766b8 | ||
|
|
174de315c6 | ||
|
|
91cad52c87 | ||
|
|
3d9a6aef83 | ||
|
|
13b62626e8 | ||
|
|
bd17f4a47e | ||
|
|
469cb0e247 | ||
|
|
3a556350bd | ||
|
|
22de9d98ab | ||
|
|
ed5e89b8ff | ||
|
|
f51f967e15 | ||
|
|
85fb4247b7 | ||
|
|
5084d130b2 | ||
|
|
bc1860267c | ||
|
|
d7ac6f694d | ||
|
|
e18b497796 | ||
|
|
c19371144d | ||
|
|
781e8d91ab | ||
|
|
3d1fa4654a |
@@ -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@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- run: rustup toolchain install stable --profile minimal --no-self-update
|
||||||
|
|
||||||
|
- uses: cargo-bins/cargo-binstall@3be4ad2b146f3302f92e5956c54fedbb6ae8cccc # v1.25.3
|
||||||
|
|
||||||
|
- uses: ./
|
||||||
|
|
||||||
|
- run: cargo binstall -y cargo-deny
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
@@ -18,12 +18,12 @@ jobs:
|
|||||||
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@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
- name: Setup Node.js 24.x
|
- name: Setup Node.js 24.x
|
||||||
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
|
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
|
||||||
with:
|
with:
|
||||||
node-version: 24.x
|
node-version: 24.x
|
||||||
cache: npm
|
cache: npm
|
||||||
@@ -43,7 +43,7 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
id: diff
|
id: diff
|
||||||
|
|
||||||
- uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
|
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
|
||||||
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
|
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
|
||||||
with:
|
with:
|
||||||
name: dist
|
name: dist
|
||||||
|
|||||||
@@ -19,13 +19,13 @@ jobs:
|
|||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
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@64c5c20c872907b6f7cd50994ac189e7274160f2 # v2.68.26
|
- uses: taiki-e/install-action@8cca0918f8471c33515202b73f56ab27f2bed283 # v2.87.29
|
||||||
with:
|
with:
|
||||||
tool: cargo-llvm-cov
|
tool: cargo-llvm-cov
|
||||||
|
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Fetch metadata
|
- name: Fetch metadata
|
||||||
id: metadata
|
id: metadata
|
||||||
uses: dependabot/fetch-metadata@21025c705c08248db411dc16f3619e6b5f9ea21a # v2.5.0
|
uses: dependabot/fetch-metadata@25dd0e34f4fe68f24cc83900b1fe3fe149efef98 # v3.1.0
|
||||||
with:
|
with:
|
||||||
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
fetch-depth: 2
|
fetch-depth: 2
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
@@ -37,7 +37,7 @@ 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@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
|
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
|
||||||
with:
|
with:
|
||||||
node-version: 24.x
|
node-version: 24.x
|
||||||
cache: npm
|
cache: npm
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ jobs:
|
|||||||
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: git
|
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: git
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ jobs:
|
|||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: checkout
|
- name: checkout
|
||||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: checkout
|
- name: checkout
|
||||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
|
|||||||
@@ -16,11 +16,11 @@ jobs:
|
|||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
- uses: cachix/install-nix-action@1ca7d21a94afc7c957383a2d217460d980de4934 # v31.10.1
|
- uses: cachix/install-nix-action@448cde739abec1eaf0646249e3d25bb8d9bc7702 # v31.11.2
|
||||||
|
|
||||||
- uses: ./
|
- uses: ./
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
name: save-restore
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
save:
|
||||||
|
if: github.repository == 'Swatinem/rust-cache'
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
|
|
||||||
|
name: Save a new cache on ${{ matrix.os }}
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
|
env:
|
||||||
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- run: rustup toolchain install stable --profile minimal --no-self-update
|
||||||
|
|
||||||
|
# Use a per-run key so this job always exercises the post-step save path.
|
||||||
|
- uses: ./
|
||||||
|
with:
|
||||||
|
workspaces: tests
|
||||||
|
shared-key: save-restore-${{ matrix.os }}-${{ github.run_id }}-${{ github.run_attempt }}
|
||||||
|
|
||||||
|
- run: cargo check
|
||||||
|
working-directory: tests
|
||||||
|
|
||||||
|
restore:
|
||||||
|
if: github.repository == 'Swatinem/rust-cache'
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
|
|
||||||
|
name: Restore the newly saved cache on ${{ matrix.os }}
|
||||||
|
needs: save
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
|
env:
|
||||||
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- run: rustup toolchain install stable --profile minimal --no-self-update
|
||||||
|
|
||||||
|
- id: cache
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
workspaces: tests
|
||||||
|
shared-key: save-restore-${{ matrix.os }}-${{ github.run_id }}-${{ github.run_attempt }}
|
||||||
|
save-if: "false"
|
||||||
|
|
||||||
|
- name: Verify exact cache hit
|
||||||
|
if: steps.cache.outputs.cache-hit != 'true'
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
echo "The cache created by the save job could not be restored." >&2
|
||||||
|
exit 1
|
||||||
@@ -19,7 +19,7 @@ jobs:
|
|||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ jobs:
|
|||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
|
|||||||
@@ -1,25 +1,25 @@
|
|||||||
name: buildjet
|
name: warpbuild
|
||||||
|
|
||||||
on: [push, pull_request]
|
on: [push, pull_request]
|
||||||
|
|
||||||
permissions: {}
|
permissions: {}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
buildjet:
|
warpbuild:
|
||||||
if: github.repository == 'Swatinem/rust-cache'
|
if: github.repository == 'Swatinem/rust-cache'
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
|
|
||||||
name: Test buildjet provider on ${{ matrix.os }}
|
name: Test warpbuild provider on ${{ matrix.os }}
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
env:
|
env:
|
||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ jobs:
|
|||||||
- uses: ./
|
- uses: ./
|
||||||
with:
|
with:
|
||||||
workspaces: tests
|
workspaces: tests
|
||||||
cache-provider: buildjet
|
cache-provider: warpbuild
|
||||||
|
|
||||||
- run: |
|
- run: |
|
||||||
cargo check
|
cargo check
|
||||||
@@ -19,7 +19,7 @@ jobs:
|
|||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ jobs:
|
|||||||
security-events: write # for uploading results to the Security tab
|
security-events: write # for uploading results to the Security tab
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
with:
|
with:
|
||||||
persist-credentials: false
|
persist-credentials: false
|
||||||
|
|
||||||
- name: Run zizmor 🌈
|
- name: Run zizmor 🌈
|
||||||
uses: zizmorcore/zizmor-action@71321a20a9ded102f6e9ce5718a2fcec2c4f70d8 # v0.5.2
|
uses: zizmorcore/zizmor-action@85b2b9fb8e3325e7a23d7d0a9d7ba5ae0f999e3e # v0.7.1
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
target/
|
target/
|
||||||
src/*.js
|
src/*.js
|
||||||
|
.build
|
||||||
|
|
||||||
# Editors
|
# Editors
|
||||||
.idea/
|
.idea/
|
||||||
|
|||||||
@@ -1,5 +1,29 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2.9.3
|
||||||
|
|
||||||
|
- Fix timestamp based pruning
|
||||||
|
- Add missing `await`s
|
||||||
|
- Do not emit warning on missing `rustup`
|
||||||
|
|
||||||
|
## 2.9.2
|
||||||
|
|
||||||
|
- Fix `credentials.toml` cleanup
|
||||||
|
- Improvements to cleanup, preserving more valid targets
|
||||||
|
- Improvements to `cargo install` handling
|
||||||
|
- Correctly sort/dedupe Rust versions
|
||||||
|
|
||||||
|
## 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
|
## 2.8.2
|
||||||
|
|
||||||
- Don't overwrite env for cargo-metadata call
|
- Don't overwrite env for cargo-metadata call
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ sensible defaults.
|
|||||||
## Example usage
|
## Example usage
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
# selecting a toolchain either by action or manual `rustup` calls should happen
|
# selecting a toolchain either by action or manual `rustup` calls should happen
|
||||||
# before the plugin, as the cache uses the current rustc version as its cache key
|
# before the plugin, as the cache uses the current rustc version as its cache key
|
||||||
@@ -32,7 +32,7 @@ sensible defaults.
|
|||||||
# default: "true"
|
# default: "true"
|
||||||
add-job-id-key: ""
|
add-job-id-key: ""
|
||||||
|
|
||||||
# Weather the a hash of the rust environment should be included in the cache 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,
|
# 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'.
|
# and .cargo/config.toml files (if present), as well as the specified 'env-vars'.
|
||||||
# default: "true"
|
# default: "true"
|
||||||
@@ -92,7 +92,7 @@ sensible defaults.
|
|||||||
lookup-only: ""
|
lookup-only: ""
|
||||||
|
|
||||||
# Specifies what to use as the backend providing cache
|
# Specifies what to use as the backend providing cache
|
||||||
# Can be set to "github", "buildjet", or "warpbuild"
|
# Can be set to "github", or "warpbuild"
|
||||||
# default: "github"
|
# default: "github"
|
||||||
cache-provider: ""
|
cache-provider: ""
|
||||||
|
|
||||||
@@ -142,7 +142,7 @@ 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)
|
||||||
(if `add-job-id-key` is `"true"`),
|
(if `add-job-id-key` is `"true"`),
|
||||||
- the rustc release / host / hash (for all installed toolchains when
|
- the rustc release / host / hash (for all installed toolchains when
|
||||||
available),
|
available),
|
||||||
- the following values, if `add-rust-environment-hash-key` is `"true"`:
|
- the following values, if `add-rust-environment-hash-key` is `"true"`:
|
||||||
@@ -210,5 +210,5 @@ to see those details as well as further details related to caching operations.
|
|||||||
- The cache cleaning process currently removes all the files from `~/.cargo/bin`
|
- The cache cleaning process currently removes all the files from `~/.cargo/bin`
|
||||||
that were present before the action ran (for example `rustc`), by default.
|
that were present before the action ran (for example `rustc`), by default.
|
||||||
This can be an issue on long-running self-hosted runners, where such state
|
This can be an issue on long-running self-hosted runners, where such state
|
||||||
is expected to be preserved across runs. You can work around this by setting
|
is expected to be preserved across runs. You can work around this by setting
|
||||||
`cache-bin: "false"`.
|
`cache-bin: "false"`.
|
||||||
|
|||||||
+3
-3
@@ -49,7 +49,7 @@ inputs:
|
|||||||
required: false
|
required: false
|
||||||
default: "true"
|
default: "true"
|
||||||
cache-provider:
|
cache-provider:
|
||||||
description: "Determines which provider to use for caching. Options are github, buildjet, or warpbuild. Defaults to github."
|
description: "Determines which provider to use for caching. Options are github, or warpbuild. Defaults to github."
|
||||||
required: false
|
required: false
|
||||||
default: "github"
|
default: "github"
|
||||||
cache-bin:
|
cache-bin:
|
||||||
@@ -69,8 +69,8 @@ outputs:
|
|||||||
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: "node24"
|
using: "node24"
|
||||||
main: "dist/restore/index.js"
|
main: "dist/restore.js"
|
||||||
post: "dist/save/index.js"
|
post: "dist/save.js"
|
||||||
post-if: "success() || env.CACHE_ON_FAILURE == 'true'"
|
post-if: "success() || env.CACHE_ON_FAILURE == 'true'"
|
||||||
branding:
|
branding:
|
||||||
icon: "archive"
|
icon: "archive"
|
||||||
|
|||||||
Vendored
+249202
File diff suppressed because one or more lines are too long
Vendored
+47696
File diff suppressed because it is too large
Load Diff
Vendored
+35702
File diff suppressed because one or more lines are too long
Vendored
+101
@@ -0,0 +1,101 @@
|
|||||||
|
import { e as error, g as getCacheProvider, a as getInput, b as exportVariable, C as CacheConfig, i as info, c as cleanTargetDir, r as reportError, s as setOutput } from './cleanup-e3M0pm4f.js';
|
||||||
|
import 'os';
|
||||||
|
import 'crypto';
|
||||||
|
import 'fs';
|
||||||
|
import 'path';
|
||||||
|
import 'http';
|
||||||
|
import 'https';
|
||||||
|
import 'net';
|
||||||
|
import 'tls';
|
||||||
|
import 'events';
|
||||||
|
import 'assert';
|
||||||
|
import 'util';
|
||||||
|
import 'node:assert';
|
||||||
|
import 'node:net';
|
||||||
|
import 'node:http';
|
||||||
|
import 'node:stream';
|
||||||
|
import 'node:buffer';
|
||||||
|
import 'node:util';
|
||||||
|
import 'node:querystring';
|
||||||
|
import 'node:events';
|
||||||
|
import 'node:diagnostics_channel';
|
||||||
|
import 'node:tls';
|
||||||
|
import 'node:zlib';
|
||||||
|
import 'node:perf_hooks';
|
||||||
|
import 'node:util/types';
|
||||||
|
import 'node:worker_threads';
|
||||||
|
import 'node:url';
|
||||||
|
import 'node:async_hooks';
|
||||||
|
import 'node:console';
|
||||||
|
import 'node:dns';
|
||||||
|
import 'string_decoder';
|
||||||
|
import 'child_process';
|
||||||
|
import 'timers';
|
||||||
|
import 'stream';
|
||||||
|
import 'fs/promises';
|
||||||
|
|
||||||
|
process.on("uncaughtException", (e) => {
|
||||||
|
error(e.message);
|
||||||
|
if (e.stack) {
|
||||||
|
error(e.stack);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
async function run() {
|
||||||
|
const cacheProvider = await getCacheProvider();
|
||||||
|
if (!cacheProvider.cache.isFeatureAvailable()) {
|
||||||
|
setCacheHitOutput(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
var cacheOnFailure = getInput("cache-on-failure").toLowerCase();
|
||||||
|
if (cacheOnFailure !== "true") {
|
||||||
|
cacheOnFailure = "false";
|
||||||
|
}
|
||||||
|
var lookupOnly = getInput("lookup-only").toLowerCase() === "true";
|
||||||
|
exportVariable("CACHE_ON_FAILURE", cacheOnFailure);
|
||||||
|
exportVariable("CARGO_INCREMENTAL", 0);
|
||||||
|
const config = await CacheConfig.new();
|
||||||
|
config.printInfo(cacheProvider);
|
||||||
|
info("");
|
||||||
|
info(`... ${lookupOnly ? "Checking" : "Restoring"} cache ...`);
|
||||||
|
const key = config.cacheKey;
|
||||||
|
// Pass a copy of cachePaths to avoid mutating the original array as reported by:
|
||||||
|
// https://github.com/actions/toolkit/pull/1378
|
||||||
|
// TODO: remove this once the underlying bug is fixed.
|
||||||
|
const restoreKey = await cacheProvider.cache.restoreCache(config.cachePaths.slice(), key, [config.restoreKey], {
|
||||||
|
lookupOnly,
|
||||||
|
});
|
||||||
|
if (restoreKey) {
|
||||||
|
const match = restoreKey.localeCompare(key, undefined, {
|
||||||
|
sensitivity: "accent",
|
||||||
|
}) === 0;
|
||||||
|
info(`${lookupOnly ? "Found" : "Restored from"} cache key "${restoreKey}" full match: ${match}.`);
|
||||||
|
if (!match) {
|
||||||
|
// pre-clean the target directory on cache mismatch
|
||||||
|
for (const workspace of config.workspaces) {
|
||||||
|
try {
|
||||||
|
await cleanTargetDir(workspace.target, [], true);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
// We restored the cache but it is not a full match.
|
||||||
|
config.saveState();
|
||||||
|
}
|
||||||
|
setCacheHitOutput(match);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
info("No cache found.");
|
||||||
|
config.saveState();
|
||||||
|
setCacheHitOutput(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
setCacheHitOutput(false);
|
||||||
|
reportError(e);
|
||||||
|
}
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
function setCacheHitOutput(cacheHit) {
|
||||||
|
setOutput("cache-hit", cacheHit.toString());
|
||||||
|
}
|
||||||
|
run();
|
||||||
Vendored
-250489
File diff suppressed because one or more lines are too long
Vendored
+121
@@ -0,0 +1,121 @@
|
|||||||
|
import { e as error, g as getCacheProvider, a as getInput, d as isCacheUpToDate, i as info, C as CacheConfig, c as cleanTargetDir, f as debug, h as cleanRegistry, j as cleanBin, k as cleanGit, r as reportError, l as exec } from './cleanup-e3M0pm4f.js';
|
||||||
|
import 'os';
|
||||||
|
import 'crypto';
|
||||||
|
import 'fs';
|
||||||
|
import 'path';
|
||||||
|
import 'http';
|
||||||
|
import 'https';
|
||||||
|
import 'net';
|
||||||
|
import 'tls';
|
||||||
|
import 'events';
|
||||||
|
import 'assert';
|
||||||
|
import 'util';
|
||||||
|
import 'node:assert';
|
||||||
|
import 'node:net';
|
||||||
|
import 'node:http';
|
||||||
|
import 'node:stream';
|
||||||
|
import 'node:buffer';
|
||||||
|
import 'node:util';
|
||||||
|
import 'node:querystring';
|
||||||
|
import 'node:events';
|
||||||
|
import 'node:diagnostics_channel';
|
||||||
|
import 'node:tls';
|
||||||
|
import 'node:zlib';
|
||||||
|
import 'node:perf_hooks';
|
||||||
|
import 'node:util/types';
|
||||||
|
import 'node:worker_threads';
|
||||||
|
import 'node:url';
|
||||||
|
import 'node:async_hooks';
|
||||||
|
import 'node:console';
|
||||||
|
import 'node:dns';
|
||||||
|
import 'string_decoder';
|
||||||
|
import 'child_process';
|
||||||
|
import 'timers';
|
||||||
|
import 'stream';
|
||||||
|
import 'fs/promises';
|
||||||
|
|
||||||
|
process.on("uncaughtException", (e) => {
|
||||||
|
error(e.message);
|
||||||
|
if (e.stack) {
|
||||||
|
error(e.stack);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
async function run() {
|
||||||
|
const cacheProvider = await getCacheProvider();
|
||||||
|
const save = getInput("save-if").toLowerCase() || "true";
|
||||||
|
if (!(cacheProvider.cache.isFeatureAvailable() && save === "true")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (isCacheUpToDate()) {
|
||||||
|
info(`Cache up-to-date.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const config = CacheConfig.fromState();
|
||||||
|
config.printInfo(cacheProvider);
|
||||||
|
info("");
|
||||||
|
// TODO: remove this once https://github.com/actions/toolkit/pull/553 lands
|
||||||
|
if (process.env["RUNNER_OS"] == "macOS") {
|
||||||
|
await macOsWorkaround();
|
||||||
|
}
|
||||||
|
const workspaceCrates = getInput("cache-workspace-crates").toLowerCase() || "false";
|
||||||
|
const allPackages = [];
|
||||||
|
for (const workspace of config.workspaces) {
|
||||||
|
const packages = await workspace.getPackagesOutsideWorkspaceRoot(config.cmdFormat);
|
||||||
|
if (workspaceCrates === "true") {
|
||||||
|
const wsMembers = await workspace.getWorkspaceMembers(config.cmdFormat);
|
||||||
|
packages.push(...wsMembers);
|
||||||
|
}
|
||||||
|
allPackages.push(...packages);
|
||||||
|
try {
|
||||||
|
info(`... Cleaning ${workspace.target} ...`);
|
||||||
|
await cleanTargetDir(workspace.target, packages);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
debug(`${e.stack}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const crates = getInput("cache-all-crates").toLowerCase() || "false";
|
||||||
|
info(`... Cleaning cargo registry (cache-all-crates: ${crates}) ...`);
|
||||||
|
await cleanRegistry(allPackages, crates !== "true");
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
debug(`${e.stack}`);
|
||||||
|
}
|
||||||
|
if (config.cacheBin) {
|
||||||
|
try {
|
||||||
|
info(`... Cleaning cargo/bin ...`);
|
||||||
|
await cleanBin(config.cargoBins);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
debug(`${e.stack}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
info(`... Cleaning cargo git cache ...`);
|
||||||
|
await cleanGit(allPackages);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
debug(`${e.stack}`);
|
||||||
|
}
|
||||||
|
info(`... Saving cache ...`);
|
||||||
|
// Pass a copy of cachePaths to avoid mutating the original array as reported by:
|
||||||
|
// https://github.com/actions/toolkit/pull/1378
|
||||||
|
// TODO: remove this once the underlying bug is fixed.
|
||||||
|
await cacheProvider.cache.saveCache(config.cachePaths.slice(), config.cacheKey);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
reportError(e);
|
||||||
|
}
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
run();
|
||||||
|
async function macOsWorkaround() {
|
||||||
|
try {
|
||||||
|
// Workaround for https://github.com/actions/cache/issues/403
|
||||||
|
// Also see https://github.com/rust-lang/cargo/issues/8603
|
||||||
|
await exec("sudo", ["/usr/sbin/purge"], { silent: true });
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
Vendored
-250510
File diff suppressed because one or more lines are too long
Vendored
+1825
File diff suppressed because it is too large
Load Diff
Generated
+1684
-342
File diff suppressed because it is too large
Load Diff
+23
-11
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"name": "rust-cache",
|
"name": "rust-cache",
|
||||||
"version": "2.9.0",
|
"version": "2.9.3",
|
||||||
"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",
|
||||||
@@ -21,23 +21,35 @@
|
|||||||
"url": "https://github.com/sponsors/Swatinem"
|
"url": "https://github.com/sponsors/Swatinem"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/Swatinem/rust-cache#readme",
|
"homepage": "https://github.com/Swatinem/rust-cache#readme",
|
||||||
|
"type": "module",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/buildjet-cache": "npm:github-actions.cache-buildjet@0.2.0",
|
"@actions/cache": "^6.3.0",
|
||||||
"@actions/warpbuild-cache": "npm:github-actions.warp-cache@1.4.7",
|
"@actions/core": "^3.0.1",
|
||||||
"@actions/cache": "^6.0.0",
|
|
||||||
"@actions/core": "^3.0.0",
|
|
||||||
"@actions/exec": "^3.0.0",
|
"@actions/exec": "^3.0.0",
|
||||||
"@actions/glob": "^0.6.1",
|
"@actions/glob": "^0.7.0",
|
||||||
"@actions/io": "^3.0.2",
|
"@actions/io": "^3.0.2",
|
||||||
"smol-toml": "^1.6.0"
|
"@actions/warpbuild-cache": "npm:github-actions.warp-cache@1.4.7",
|
||||||
|
"smol-toml": "^1.9.1"
|
||||||
|
},
|
||||||
|
"overrides": {
|
||||||
|
"@actions/cache": {
|
||||||
|
"@actions/glob": "$@actions/glob"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^25.4.0",
|
"@rollup/plugin-commonjs": "^29.0.3",
|
||||||
"@vercel/ncc": "^0.38.4",
|
"@rollup/plugin-json": "^6.1.0",
|
||||||
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
||||||
|
"@types/node": "^26.6.5",
|
||||||
"linefix": "^0.1.1",
|
"linefix": "^0.1.1",
|
||||||
"typescript": "5.9.3"
|
"rollup": "^4.64.12",
|
||||||
|
"typescript": "7.0.2"
|
||||||
},
|
},
|
||||||
"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"
|
"clean": "node -e \"(async () => { try { await require('fs/promises').rm('dist', { recursive: true }); } catch {} })()\"",
|
||||||
|
"prebuild": "npm run clean",
|
||||||
|
"build": "tsc && rollup --config .build/rollup.config.js",
|
||||||
|
"prepublishOnly": "npm run test",
|
||||||
|
"prepare": "npm run build && linefix dist"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import commonjs from "@rollup/plugin-commonjs";
|
||||||
|
import json from "@rollup/plugin-json";
|
||||||
|
import nodeResolve from "@rollup/plugin-node-resolve";
|
||||||
|
import type { RollupWatchOptions } from "rollup";
|
||||||
|
|
||||||
|
const config: RollupWatchOptions = {
|
||||||
|
input: ["./.build/src/restore.js", "./.build/src/save.js"],
|
||||||
|
output: { dir: "./dist", format: "es" },
|
||||||
|
plugins: [nodeResolve({ preferBuiltins: true }), commonjs(), json()],
|
||||||
|
};
|
||||||
|
export default config;
|
||||||
+42
-43
@@ -3,9 +3,9 @@ import * as io from "@actions/io";
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
import { CARGO_HOME } from "./config";
|
import { CARGO_HOME } from "./config.js";
|
||||||
import { exists } from "./utils";
|
import { exists } from "./utils.js";
|
||||||
import { Packages } from "./workspace";
|
import { Packages } from "./workspace.js";
|
||||||
|
|
||||||
export async function cleanTargetDir(targetDir: string, packages: Packages, checkTimestamp = false) {
|
export async function cleanTargetDir(targetDir: string, packages: Packages, checkTimestamp = false) {
|
||||||
core.debug(`cleaning target directory "${targetDir}"`);
|
core.debug(`cleaning target directory "${targetDir}"`);
|
||||||
@@ -15,15 +15,19 @@ export async function cleanTargetDir(targetDir: string, packages: Packages, chec
|
|||||||
for await (const dirent of dir) {
|
for await (const dirent of dir) {
|
||||||
if (dirent.isDirectory()) {
|
if (dirent.isDirectory()) {
|
||||||
let dirName = path.join(dir.path, dirent.name);
|
let dirName = path.join(dir.path, dirent.name);
|
||||||
// is it a profile dir, or a nested target dir?
|
// Target-triple directories do not contain Cargo's target directory
|
||||||
let isNestedTarget =
|
// markers, so identify profiles by their artifact directories as well.
|
||||||
(await exists(path.join(dirName, "CACHEDIR.TAG"))) || (await exists(path.join(dirName, ".rustc_info.json")));
|
const isProfile =
|
||||||
|
dirent.name === "tests" ||
|
||||||
|
(await exists(path.join(dirName, "build"))) ||
|
||||||
|
(await exists(path.join(dirName, ".fingerprint"))) ||
|
||||||
|
(await exists(path.join(dirName, "deps")));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (isNestedTarget) {
|
if (isProfile) {
|
||||||
await cleanTargetDir(dirName, packages, checkTimestamp);
|
|
||||||
} else {
|
|
||||||
await cleanProfileTarget(dirName, packages, checkTimestamp);
|
await cleanProfileTarget(dirName, packages, checkTimestamp);
|
||||||
|
} else {
|
||||||
|
await cleanTargetDir(dirName, packages, checkTimestamp);
|
||||||
}
|
}
|
||||||
} catch {}
|
} catch {}
|
||||||
} else if (dirent.name !== "CACHEDIR.TAG") {
|
} else if (dirent.name !== "CACHEDIR.TAG") {
|
||||||
@@ -42,11 +46,11 @@ async function cleanProfileTarget(profileDir: string, packages: Packages, checkT
|
|||||||
try {
|
try {
|
||||||
// https://github.com/vertexclique/kaos/blob/9876f6c890339741cc5be4b7cb9df72baa5a6d79/src/cargo.rs#L25
|
// https://github.com/vertexclique/kaos/blob/9876f6c890339741cc5be4b7cb9df72baa5a6d79/src/cargo.rs#L25
|
||||||
// https://github.com/eupn/macrotest/blob/c4151a5f9f545942f4971980b5d264ebcd0b1d11/src/cargo.rs#L27
|
// https://github.com/eupn/macrotest/blob/c4151a5f9f545942f4971980b5d264ebcd0b1d11/src/cargo.rs#L27
|
||||||
cleanTargetDir(path.join(profileDir, "target"), packages, checkTimestamp);
|
await cleanTargetDir(path.join(profileDir, "target"), packages, checkTimestamp);
|
||||||
} catch {}
|
} catch {}
|
||||||
try {
|
try {
|
||||||
// https://github.com/dtolnay/trybuild/blob/eec8ca6cb9b8f53d0caf1aa499d99df52cae8b40/src/cargo.rs#L50
|
// https://github.com/dtolnay/trybuild/blob/eec8ca6cb9b8f53d0caf1aa499d99df52cae8b40/src/cargo.rs#L50
|
||||||
cleanTargetDir(path.join(profileDir, "trybuild"), packages, checkTimestamp);
|
await cleanTargetDir(path.join(profileDir, "trybuild"), packages, checkTimestamp);
|
||||||
} catch {}
|
} catch {}
|
||||||
|
|
||||||
// Delete everything else.
|
// Delete everything else.
|
||||||
@@ -58,7 +62,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);
|
||||||
|
|
||||||
@@ -75,21 +79,6 @@ async function cleanProfileTarget(profileDir: string, packages: Packages, checkT
|
|||||||
await rmExcept(path.join(profileDir, "deps"), keepDeps, checkTimestamp);
|
await rmExcept(path.join(profileDir, "deps"), keepDeps, checkTimestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getCargoBins(): Promise<Set<string>> {
|
|
||||||
const bins = new Set<string>();
|
|
||||||
try {
|
|
||||||
const { installs }: { installs: { [key: string]: { bins: Array<string> } } } = JSON.parse(
|
|
||||||
await fs.promises.readFile(path.join(CARGO_HOME, ".crates2.json"), "utf8"),
|
|
||||||
);
|
|
||||||
for (const pkg of Object.values(installs)) {
|
|
||||||
for (const bin of pkg.bins) {
|
|
||||||
bins.add(bin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch {}
|
|
||||||
return bins;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clean the cargo bin directory, removing the binaries that existed
|
* Clean the cargo bin directory, removing the binaries that existed
|
||||||
* when the action started, as they were not created by the build.
|
* when the action started, as they were not created by the build.
|
||||||
@@ -97,15 +86,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,7 +99,7 @@ export async function cleanBin(oldBins: Array<string>) {
|
|||||||
export async function cleanRegistry(packages: Packages, crates = true) {
|
export async function cleanRegistry(packages: Packages, crates = true) {
|
||||||
// remove `.cargo/credentials.toml`
|
// remove `.cargo/credentials.toml`
|
||||||
try {
|
try {
|
||||||
const credentials = path.join(CARGO_HOME, ".cargo", "credentials.toml");
|
const credentials = path.join(CARGO_HOME, "credentials.toml");
|
||||||
core.debug(`deleting "${credentials}"`);
|
core.debug(`deleting "${credentials}"`);
|
||||||
await fs.promises.unlink(credentials);
|
await fs.promises.unlink(credentials);
|
||||||
} catch {}
|
} catch {}
|
||||||
@@ -258,12 +243,19 @@ const ONE_WEEK = 7 * 24 * 3600 * 1000;
|
|||||||
/**
|
/**
|
||||||
* Removes all files or directories in `dirName` matching some criteria.
|
* Removes all files or directories in `dirName` matching some criteria.
|
||||||
*
|
*
|
||||||
* When the `checkTimestamp` flag is set, this will also remove anything older
|
* These two modes are mutually exclusive. When the `checkTimestamp` flag is
|
||||||
* than one week.
|
* set, this will remove anything older than one week and `keepPrefix` is
|
||||||
|
* ignored.
|
||||||
*
|
*
|
||||||
* Otherwise, it will remove everything that does not match any string in the
|
* Otherwise, it will remove everything that does not match any string in the
|
||||||
* `keepPrefix` set.
|
* `keepPrefix` set.
|
||||||
* The matching strips and trailing `-$hash` suffix.
|
* The matching strips and trailing `-$hash` suffix.
|
||||||
|
*
|
||||||
|
* Cargo's newer `build-dir` layout (rust-lang/cargo#17258) nests the hash as
|
||||||
|
* a subdirectory instead of appending it, so entries there are bare package
|
||||||
|
* names with no suffix to strip. Check for an exact match first so those
|
||||||
|
* names (which may themselves contain hyphens) aren't mistaken for a
|
||||||
|
* `<name>-<hash>` entry from the old layout and truncated incorrectly.
|
||||||
*/
|
*/
|
||||||
async function rmExcept(dirName: string, keepPrefix: Set<string>, checkTimestamp = false) {
|
async function rmExcept(dirName: string, keepPrefix: Set<string>, checkTimestamp = false) {
|
||||||
const dir = await fs.promises.opendir(dirName);
|
const dir = await fs.promises.opendir(dirName);
|
||||||
@@ -276,19 +268,26 @@ async function rmExcept(dirName: string, keepPrefix: Set<string>, checkTimestamp
|
|||||||
if (isOutdated) {
|
if (isOutdated) {
|
||||||
await rm(dir.path, dirent);
|
await rm(dir.path, dirent);
|
||||||
}
|
}
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let name = dirent.name;
|
let name = dirent.name;
|
||||||
|
|
||||||
// strip the trailing hash
|
// in Cargo's V1 layout, all packages are suffixed by their hash.
|
||||||
const idx = name.lastIndexOf("-");
|
// in V2, all package hashes are subdirectories instead.
|
||||||
if (idx !== -1) {
|
// Check both possible naming standards for packages and accept either.
|
||||||
name = name.slice(0, idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// v2 package format
|
||||||
if (!keepPrefix.has(name)) {
|
if (!keepPrefix.has(name)) {
|
||||||
await rm(dir.path, dirent);
|
// now check for v1 package format
|
||||||
|
// strip the trailing hash
|
||||||
|
const idx = name.lastIndexOf("-");
|
||||||
|
if (idx !== -1) {
|
||||||
|
name = name.slice(0, idx);
|
||||||
|
}
|
||||||
|
if (!keepPrefix.has(name)) {
|
||||||
|
await rm(dir.path, dirent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+36
-24
@@ -3,14 +3,12 @@ import * as glob from "@actions/glob";
|
|||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
import fs from "fs/promises";
|
import fs from "fs/promises";
|
||||||
import { createReadStream } from "fs";
|
import { createReadStream } from "fs";
|
||||||
import { pipeline } from "stream/promises";
|
|
||||||
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";
|
||||||
|
|
||||||
import { getCargoBins } from "./cleanup";
|
import { CacheProvider, exists, getCmdOutput } from "./utils.js";
|
||||||
import { CacheProvider, exists, getCmdOutput } from "./utils";
|
import { Workspace } from "./workspace.js";
|
||||||
import { Workspace } from "./workspace";
|
|
||||||
|
|
||||||
const HOME = os.homedir();
|
const HOME = os.homedir();
|
||||||
export const CARGO_HOME = process.env.CARGO_HOME || path.join(HOME, ".cargo");
|
export const CARGO_HOME = process.env.CARGO_HOME || path.join(HOME, ".cargo");
|
||||||
@@ -84,7 +82,7 @@ export class CacheConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const job = process.env.GITHUB_JOB;
|
const job = process.env.GITHUB_JOB;
|
||||||
if ((job) && core.getInput("add-job-id-key").toLowerCase() == "true") {
|
if (job && core.getInput("add-job-id-key").toLowerCase() == "true") {
|
||||||
key += `-${job}`;
|
key += `-${job}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,15 +102,9 @@ export class CacheConfig {
|
|||||||
// resulting environment hash.
|
// resulting environment hash.
|
||||||
|
|
||||||
let hasher = crypto.createHash("sha1");
|
let hasher = crypto.createHash("sha1");
|
||||||
const rustVersions = Array.from(await getRustVersions(cmdFormat));
|
const rustVersions = (self.keyRust = await getRustVersions(cmdFormat));
|
||||||
// Doesn't matter how they're sorted, just as long as it's deterministic.
|
|
||||||
rustVersions.sort();
|
|
||||||
|
|
||||||
for (const rustVersion of rustVersions) {
|
for (const rustVersion of rustVersions) {
|
||||||
const { release, host, "commit-hash": commitHash } = rustVersion;
|
hasher.update(rustVersion);
|
||||||
const keyRust = `${release} ${host} ${commitHash}`;
|
|
||||||
hasher.update(keyRust);
|
|
||||||
self.keyRust.push(keyRust);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// these prefixes should cover most of the compiler / rust / cargo keys
|
// these prefixes should cover most of the compiler / rust / cargo keys
|
||||||
@@ -256,7 +248,9 @@ export class CacheConfig {
|
|||||||
keyFiles = sort_and_uniq(keyFiles);
|
keyFiles = sort_and_uniq(keyFiles);
|
||||||
|
|
||||||
for (const file of keyFiles) {
|
for (const file of keyFiles) {
|
||||||
await pipeline(createReadStream(file), hasher);
|
for await (const chunk of createReadStream(file)) {
|
||||||
|
hasher.update(chunk);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
keyFiles.push(...parsedKeyFiles);
|
keyFiles.push(...parsedKeyFiles);
|
||||||
@@ -378,14 +372,23 @@ function digest(hasher: crypto.Hash): string {
|
|||||||
return hasher.digest("hex").substring(0, HASH_LENGTH);
|
return hasher.digest("hex").substring(0, HASH_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface RustVersion {
|
export async function getCargoBins(): Promise<Set<string>> {
|
||||||
host: string;
|
const bins = new Set<string>();
|
||||||
release: string;
|
|
||||||
"commit-hash": string;
|
try {
|
||||||
|
const dir = await fs.opendir(path.join(CARGO_HOME, "bin"));
|
||||||
|
for await (const dirent of dir) {
|
||||||
|
if (dirent.isFile()) {
|
||||||
|
bins.add(dirent.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
return bins;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getRustVersions(cmdFormat: string): Promise<Set<RustVersion>> {
|
async function getRustVersions(cmdFormat: string): Promise<Array<string>> {
|
||||||
const versions = new Set<RustVersion>();
|
const versions = new Set<string>();
|
||||||
|
|
||||||
versions.add(parseRustVersion(await getCmdOutput(cmdFormat, "rustc -vV")));
|
versions.add(parseRustVersion(await getCmdOutput(cmdFormat, "rustc -vV")));
|
||||||
|
|
||||||
@@ -393,7 +396,7 @@ async function getRustVersions(cmdFormat: string): Promise<Set<RustVersion>> {
|
|||||||
try {
|
try {
|
||||||
return await getCmdOutput(cmdFormat, "rustup toolchain list --quiet");
|
return await getCmdOutput(cmdFormat, "rustup toolchain list --quiet");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
core.warning(`Error running rustup toolchain list, falling back to default toolchain only: ${e}`);
|
core.info(`Error running rustup toolchain list, falling back to default toolchain only: ${e}`);
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
@@ -406,16 +409,25 @@ async function getRustVersions(cmdFormat: string): Promise<Set<RustVersion>> {
|
|||||||
versions.add(parseRustVersion(await getCmdOutput(cmdFormat, `rustup run ${toolchain} rustc -vV`)));
|
versions.add(parseRustVersion(await getCmdOutput(cmdFormat, `rustup run ${toolchain} rustc -vV`)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return versions;
|
const rustVersions = Array.from(versions);
|
||||||
|
// Doesn't matter how they're sorted, just as long as it's deterministic.
|
||||||
|
rustVersions.sort();
|
||||||
|
return rustVersions;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseRustVersion(stdout: string): RustVersion {
|
interface RustVersion {
|
||||||
|
host: string;
|
||||||
|
release: string;
|
||||||
|
"commit-hash": string;
|
||||||
|
}
|
||||||
|
function parseRustVersion(stdout: string): string {
|
||||||
const splits = stdout
|
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()))
|
||||||
.filter((s) => s.length === 2);
|
.filter((s) => s.length === 2);
|
||||||
return Object.fromEntries(splits);
|
const { release, host, "commit-hash": commitHash } = Object.fromEntries(splits) as RustVersion;
|
||||||
|
return `${release} ${host} ${commitHash}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function globFiles(pattern: string): Promise<string[]> {
|
async function globFiles(pattern: string): Promise<string[]> {
|
||||||
|
|||||||
+8
-7
@@ -1,8 +1,8 @@
|
|||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
|
|
||||||
import { cleanTargetDir } from "./cleanup";
|
import { cleanTargetDir } from "./cleanup.js";
|
||||||
import { CacheConfig } from "./config";
|
import { CacheConfig } from "./config.js";
|
||||||
import { getCacheProvider, reportError } from "./utils";
|
import { getCacheProvider, reportError } from "./utils.js";
|
||||||
|
|
||||||
process.on("uncaughtException", (e) => {
|
process.on("uncaughtException", (e) => {
|
||||||
core.error(e.message);
|
core.error(e.message);
|
||||||
@@ -12,7 +12,7 @@ process.on("uncaughtException", (e) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
const cacheProvider = getCacheProvider();
|
const cacheProvider = await getCacheProvider();
|
||||||
|
|
||||||
if (!cacheProvider.cache.isFeatureAvailable()) {
|
if (!cacheProvider.cache.isFeatureAvailable()) {
|
||||||
setCacheHitOutput(false);
|
setCacheHitOutput(false);
|
||||||
@@ -42,9 +42,10 @@ async function run() {
|
|||||||
lookupOnly,
|
lookupOnly,
|
||||||
});
|
});
|
||||||
if (restoreKey) {
|
if (restoreKey) {
|
||||||
const match = restoreKey.localeCompare(key, undefined, {
|
const match =
|
||||||
sensitivity: "accent"
|
restoreKey.localeCompare(key, undefined, {
|
||||||
}) === 0;
|
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
|
||||||
|
|||||||
+4
-4
@@ -1,9 +1,9 @@
|
|||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import * as exec from "@actions/exec";
|
import * as exec from "@actions/exec";
|
||||||
|
|
||||||
import { cleanBin, cleanGit, cleanRegistry, cleanTargetDir } from "./cleanup";
|
import { cleanBin, cleanGit, cleanRegistry, cleanTargetDir } from "./cleanup.js";
|
||||||
import { CacheConfig, isCacheUpToDate } from "./config";
|
import { CacheConfig, isCacheUpToDate } from "./config.js";
|
||||||
import { getCacheProvider, reportError } from "./utils";
|
import { getCacheProvider, reportError } from "./utils.js";
|
||||||
|
|
||||||
process.on("uncaughtException", (e) => {
|
process.on("uncaughtException", (e) => {
|
||||||
core.error(e.message);
|
core.error(e.message);
|
||||||
@@ -13,7 +13,7 @@ process.on("uncaughtException", (e) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
const cacheProvider = getCacheProvider();
|
const cacheProvider = await getCacheProvider();
|
||||||
|
|
||||||
const save = core.getInput("save-if").toLowerCase() || "true";
|
const save = core.getInput("save-if").toLowerCase() || "true";
|
||||||
|
|
||||||
|
|||||||
+6
-16
@@ -1,8 +1,5 @@
|
|||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import * as exec from "@actions/exec";
|
import * as exec from "@actions/exec";
|
||||||
import * as buildjetCache from "@actions/buildjet-cache";
|
|
||||||
import * as warpbuildCache from "@actions/warpbuild-cache";
|
|
||||||
import * as ghCache from "@actions/cache";
|
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
|
||||||
export function reportError(e: any) {
|
export function reportError(e: any) {
|
||||||
@@ -15,11 +12,7 @@ export function reportError(e: any) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getCmdOutput(
|
export async function getCmdOutput(cmdFormat: string, cmd: string, options: exec.ExecOptions = {}): Promise<string> {
|
||||||
cmdFormat: string,
|
|
||||||
cmd: string,
|
|
||||||
options: exec.ExecOptions = {},
|
|
||||||
): Promise<string> {
|
|
||||||
cmd = cmdFormat.replace("{0}", cmd);
|
cmd = cmdFormat.replace("{0}", cmd);
|
||||||
let stdout = "";
|
let stdout = "";
|
||||||
let stderr = "";
|
let stderr = "";
|
||||||
@@ -47,8 +40,8 @@ export async function getCmdOutput(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface GhCache {
|
export interface GhCache {
|
||||||
isFeatureAvailable: typeof ghCache.isFeatureAvailable;
|
isFeatureAvailable: typeof import("@actions/cache").isFeatureAvailable;
|
||||||
restoreCache: typeof ghCache.restoreCache;
|
restoreCache: typeof import("@actions/cache").restoreCache;
|
||||||
saveCache: (paths: string[], key: string) => Promise<string | number>;
|
saveCache: (paths: string[], key: string) => Promise<string | number>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,18 +50,15 @@ export interface CacheProvider {
|
|||||||
cache: GhCache;
|
cache: GhCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCacheProvider(): CacheProvider {
|
export async function getCacheProvider(): Promise<CacheProvider> {
|
||||||
const cacheProvider = core.getInput("cache-provider");
|
const cacheProvider = core.getInput("cache-provider");
|
||||||
let cache: GhCache;
|
let cache: GhCache;
|
||||||
switch (cacheProvider) {
|
switch (cacheProvider) {
|
||||||
case "github":
|
case "github":
|
||||||
cache = ghCache;
|
cache = await import("@actions/cache");
|
||||||
break;
|
|
||||||
case "buildjet":
|
|
||||||
cache = buildjetCache;
|
|
||||||
break;
|
break;
|
||||||
case "warpbuild":
|
case "warpbuild":
|
||||||
cache = warpbuildCache;
|
cache = await import("@actions/warpbuild-cache");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Error(`The \`cache-provider\` \`${cacheProvider}\` is not valid.`);
|
throw new Error(`The \`cache-provider\` \`${cacheProvider}\` is not valid.`);
|
||||||
|
|||||||
+12
-5
@@ -1,14 +1,21 @@
|
|||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
import { getCmdOutput } from "./utils";
|
import { getCmdOutput } from "./utils.js";
|
||||||
|
|
||||||
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(cmdFormat: string, 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}` : "");
|
const cmd = "cargo metadata --all-features --format-version 1" + (extraArgs ? ` ${extraArgs}` : "");
|
||||||
let packages: Packages = [];
|
let packages: Packages = [];
|
||||||
try {
|
try {
|
||||||
@@ -16,7 +23,7 @@ export class Workspace {
|
|||||||
const meta: Meta = JSON.parse(
|
const meta: Meta = JSON.parse(
|
||||||
await getCmdOutput(cmdFormat, cmd, {
|
await getCmdOutput(cmdFormat, cmd, {
|
||||||
cwd: this.root,
|
cwd: this.root,
|
||||||
env: { ...process.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`);
|
||||||
|
|||||||
+10
-5
@@ -2,20 +2,25 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"noEmitOnError": false,
|
"noEmitOnError": false,
|
||||||
"diagnostics": true,
|
"diagnostics": true,
|
||||||
"lib": ["esnext"],
|
"lib": ["es2024"],
|
||||||
|
"types": ["node"],
|
||||||
|
|
||||||
"target": "es2020",
|
"target": "es2024",
|
||||||
|
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"moduleResolution": "node",
|
|
||||||
"module": "esnext",
|
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
|
|
||||||
|
"incremental": true,
|
||||||
|
"tsBuildInfoFile": ".build/tsconfig.build.tsbuildinfo",
|
||||||
|
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"noUnusedLocals": true,
|
"noUnusedLocals": true,
|
||||||
"noUnusedParameters": true,
|
"noUnusedParameters": true,
|
||||||
"noImplicitReturns": true
|
"noImplicitReturns": true,
|
||||||
|
|
||||||
|
"outDir": ".build"
|
||||||
},
|
},
|
||||||
|
"include": ["src", "rollup.config.ts"],
|
||||||
"exclude": ["dist"]
|
"exclude": ["dist"]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user