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 | ||
|
|
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 | ||
|
|
f13886b937 | ||
|
|
5abb1e2a95 | ||
|
|
3c68c31fe5 | ||
|
|
5467cca14c | ||
|
|
94b28bf00e | ||
|
|
cb8ffc21fa | ||
|
|
c4f0bbdf58 | ||
|
|
d8c5063361 | ||
|
|
267a8a94c9 | ||
|
|
46cb408fba | ||
|
|
203c9eb82a | ||
|
|
a8b36e3f74 | ||
|
|
7e1e2d0a10 | ||
|
|
98c8021b55 | ||
|
|
14d3bc39c4 | ||
|
|
52ea1434f8 | ||
|
|
eaa85be6b1 | ||
|
|
901019c0f8 | ||
|
|
9d47c6ad4b | ||
|
|
27b8ea9368 | ||
|
|
f0deed1e0e | ||
|
|
008623fb83 | ||
|
|
720f7e45cc | ||
|
|
4b1f006ad2 | ||
|
|
e8e63cdbf2 | ||
|
|
9a2e0d3212 | ||
|
|
c00f3025ca | ||
|
|
68b3cb7503 | ||
|
|
82a92a6e8f | ||
|
|
598fe25fa1 | ||
|
|
8f842c2d45 | ||
|
|
96a8d65dba | ||
|
|
9bdad043e8 | ||
|
|
f7a52f6914 | ||
|
|
2bceda3912 | ||
|
|
640a22190e | ||
|
|
1582741630 | ||
|
|
23bce251a8 | ||
|
|
378c8285a4 | ||
|
|
a226033982 | ||
|
|
d30f1144e8 | ||
|
|
b1db5f9d5f | ||
|
|
3cf7f8cc28 | ||
|
|
e03705e031 | ||
|
|
b86d1c6caa | ||
|
|
f27990c89a | ||
|
|
a95ba19544 | ||
|
|
82c8487d00 | ||
|
|
67c46e7159 | ||
|
|
44b6087283 | ||
|
|
e207df5d26 | ||
|
|
decb69d790 | ||
|
|
ab6b2769d1 | ||
|
|
578b235f6e | ||
|
|
5113490c3f | ||
|
|
c0e052c18c | ||
|
|
4e0f4b19dd | ||
|
|
b919e1427f | ||
|
|
b8a6852b4f | ||
|
|
80c47cc945 | ||
|
|
5ec9842c14 | ||
|
|
3312b3ab47 | ||
|
|
f6987ea139 | ||
|
|
e97a782690 | ||
|
|
b00faf5858 | ||
|
|
9de8f90afb | ||
|
|
fd201ad913 | ||
|
|
cf3f88254c | ||
|
|
4fedae9bcf | ||
|
|
1e604afb09 | ||
|
|
dd05243424 | ||
|
|
65dbc54a5d | ||
|
|
be7377e68e | ||
|
|
2656b87321 | ||
|
|
715970feed | ||
|
|
3d4000164d | ||
|
|
988c164c3d | ||
|
|
bb80d0f127 | ||
|
|
ad97570a01 |
@@ -0,0 +1,50 @@
|
|||||||
|
# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/optimizing-pr-creation-version-updates#setting-up-a-cooldown-period-for-dependency-updates
|
||||||
|
|
||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: cargo
|
||||||
|
directories:
|
||||||
|
- tests
|
||||||
|
- tests/wasm-workspace
|
||||||
|
schedule:
|
||||||
|
interval: weekly
|
||||||
|
# https://docs.github.com/en/code-security/dependabot/working-with-dependabot/dependabot-options-reference#groups--
|
||||||
|
# 1 PR per week and group
|
||||||
|
groups:
|
||||||
|
cargo-major:
|
||||||
|
update-types: ["major"]
|
||||||
|
cargo-minor:
|
||||||
|
update-types: ["minor"]
|
||||||
|
cargo-patch:
|
||||||
|
update-types: ["patch"]
|
||||||
|
- package-ecosystem: github-actions
|
||||||
|
directory: /
|
||||||
|
schedule:
|
||||||
|
interval: weekly
|
||||||
|
groups:
|
||||||
|
actions:
|
||||||
|
# Combine all images of the last week
|
||||||
|
patterns: ["*"]
|
||||||
|
- package-ecosystem: npm
|
||||||
|
directory: /
|
||||||
|
schedule:
|
||||||
|
interval: weekly
|
||||||
|
groups:
|
||||||
|
prd-major:
|
||||||
|
dependency-type: "production"
|
||||||
|
update-types: ["major"]
|
||||||
|
prd-minor:
|
||||||
|
dependency-type: "production"
|
||||||
|
update-types: ["minor"]
|
||||||
|
prd-patch:
|
||||||
|
dependency-type: "production"
|
||||||
|
update-types: ["patch"]
|
||||||
|
dev-major:
|
||||||
|
dependency-type: "development"
|
||||||
|
update-types: ["major"]
|
||||||
|
dev-minor:
|
||||||
|
dependency-type: "development"
|
||||||
|
update-types: ["minor"]
|
||||||
|
dev-patch:
|
||||||
|
dependency-type: "development"
|
||||||
|
update-types: ["patch"]
|
||||||
@@ -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 }}
|
||||||
@@ -1,26 +1,31 @@
|
|||||||
name: check dist/
|
name: check dist/
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- '**.md'
|
- "**.md"
|
||||||
pull_request:
|
pull_request:
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- '**.md'
|
- "**.md"
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
check-dist:
|
check-dist:
|
||||||
|
if: github.repository == 'Swatinem/rust-cache'
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
|
||||||
- name: Setup Node.js 16.x
|
|
||||||
uses: actions/setup-node@v3
|
|
||||||
with:
|
with:
|
||||||
node-version: 16.x
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: Setup Node.js 24.x
|
||||||
|
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
|
||||||
|
with:
|
||||||
|
node-version: 24.x
|
||||||
cache: npm
|
cache: npm
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
@@ -38,7 +43,7 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
id: diff
|
id: diff
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v3
|
- 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
|
||||||
|
|||||||
@@ -2,8 +2,11 @@ name: coverage
|
|||||||
|
|
||||||
on: [push, pull_request]
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
coverage:
|
coverage:
|
||||||
|
if: github.repository == 'Swatinem/rust-cache'
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
@@ -16,15 +19,15 @@ jobs:
|
|||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
# When rustup is updated, it tries to replace its binary, which on Windows is somehow locked.
|
- run: rustup toolchain install stable --profile minimal --component llvm-tools-preview --no-self-update
|
||||||
# This can result in the CI failure, see: https://github.com/rust-lang/rustup/issues/3029
|
|
||||||
- run: |
|
|
||||||
rustup set auto-self-update disable
|
|
||||||
rustup toolchain install stable --profile minimal --component llvm-tools-preview
|
|
||||||
|
|
||||||
- uses: taiki-e/install-action@cargo-llvm-cov
|
- uses: taiki-e/install-action@8cca0918f8471c33515202b73f56ab27f2bed283 # v2.87.29
|
||||||
|
with:
|
||||||
|
tool: cargo-llvm-cov
|
||||||
|
|
||||||
- uses: ./
|
- uses: ./
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
# https://docs.github.com/en/code-security/dependabot/working-with-dependabot/automating-dependabot-with-github-actions#enabling-automerge-on-a-pull-request
|
||||||
|
|
||||||
|
name: Dependabot Automation
|
||||||
|
on: pull_request
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
automerge:
|
||||||
|
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'
|
||||||
|
steps:
|
||||||
|
- name: Fetch metadata
|
||||||
|
id: metadata
|
||||||
|
uses: dependabot/fetch-metadata@25dd0e34f4fe68f24cc83900b1fe3fe149efef98 # v3.1.0
|
||||||
|
with:
|
||||||
|
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
||||||
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
fetch-depth: 2
|
||||||
|
persist-credentials: false
|
||||||
|
if: steps.metadata.outputs.update-type == 'version-update:semver-patch'
|
||||||
|
- name: Check if package-lock.json has been changed
|
||||||
|
if: steps.metadata.outputs.update-type == 'version-update:semver-patch'
|
||||||
|
id: npm
|
||||||
|
env:
|
||||||
|
PR_URL: ${{github.event.pull_request.html_url}}
|
||||||
|
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||||
|
run: |
|
||||||
|
if ! git diff --quiet HEAD~1.. -- package-lock.json; then
|
||||||
|
echo "changed=true" >> $GITHUB_OUTPUT
|
||||||
|
echo "changed=true, checking out $PR_URL to allow amend"
|
||||||
|
gh pr checkout "$PR_URL"
|
||||||
|
fi
|
||||||
|
- name: Setup node if necessary
|
||||||
|
if: steps.npm.outputs.changed != ''
|
||||||
|
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
|
||||||
|
with:
|
||||||
|
node-version: 24.x
|
||||||
|
cache: npm
|
||||||
|
- name: Re-generate and commit dist/ if changed
|
||||||
|
id: amend
|
||||||
|
if: steps.npm.outputs.changed != ''
|
||||||
|
run: |
|
||||||
|
npm ci
|
||||||
|
npm run prepare
|
||||||
|
if ! git diff --quiet dist/*/index.js; then
|
||||||
|
echo "dist/ changed, amending last commit"
|
||||||
|
export $(git log -1 --pretty=format:'GIT_COMMITTER_NAME=%cn GIT_COMMITTER_EMAIL=%ce GIT_AUTHOR_NAME=%an GIT_AUTHOR_EMAIL=%ae')
|
||||||
|
git fetch --unshallow
|
||||||
|
echo "Before amend:" && git show --name-only --pretty=
|
||||||
|
git commit --amend --no-edit --no-reset-author -- dist/*/index.js
|
||||||
|
echo "After amend:" && git show --name-only --pretty=
|
||||||
|
git push --force-with-lease origin HEAD
|
||||||
|
echo "changed=true" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
- name: Auto-merge Patch PRs
|
||||||
|
if: steps.metadata.outputs.update-type == 'version-update:semver-patch'
|
||||||
|
run: gh pr merge --auto --merge "$PR_URL"
|
||||||
|
env:
|
||||||
|
PR_URL: ${{github.event.pull_request.html_url}}
|
||||||
|
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
name: git-registry
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
git-registry:
|
||||||
|
if: github.repository == 'Swatinem/rust-cache'
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
|
|
||||||
|
name: Test cargo "git" registry on ${{ matrix.os }}
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
|
||||||
|
env:
|
||||||
|
CARGO_TERM_COLOR: always
|
||||||
|
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: git
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- run: rustup toolchain install stable --profile minimal --no-self-update
|
||||||
|
|
||||||
|
- uses: ./
|
||||||
|
with:
|
||||||
|
workspaces: tests
|
||||||
|
|
||||||
|
- run: |
|
||||||
|
cargo check
|
||||||
|
cargo test
|
||||||
|
working-directory: tests
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
name: globbed-directories
|
|
||||||
|
|
||||||
on: [push, pull_request]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
simple:
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [ubuntu-latest]
|
|
||||||
|
|
||||||
name: Test `cargo check/test` on ${{ matrix.os }}
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
|
|
||||||
env:
|
|
||||||
CARGO_TERM_COLOR: always
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- name: Create folder that will be globbed
|
|
||||||
run: |
|
|
||||||
mkdir -p folder/rust-toolchain
|
|
||||||
- uses: ./
|
|
||||||
@@ -2,8 +2,11 @@ name: install
|
|||||||
|
|
||||||
on: [push, pull_request]
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
install:
|
install:
|
||||||
|
if: github.repository == 'Swatinem/rust-cache'
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
@@ -16,13 +19,11 @@ jobs:
|
|||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
# When rustup is updated, it tries to replace its binary, which on Windows is somehow locked.
|
- run: rustup toolchain install stable --profile minimal --no-self-update
|
||||||
# This can result in the CI failure, see: https://github.com/rust-lang/rustup/issues/3029
|
|
||||||
- run: |
|
|
||||||
rustup set auto-self-update disable
|
|
||||||
rustup toolchain install stable --profile minimal
|
|
||||||
|
|
||||||
- uses: ./
|
- uses: ./
|
||||||
|
|
||||||
|
|||||||
@@ -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@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
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@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
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
|
||||||
@@ -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@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- uses: cachix/install-nix-action@448cde739abec1eaf0646249e3d25bb8d9bc7702 # v31.11.2
|
||||||
|
|
||||||
|
- 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
|
||||||
@@ -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
|
||||||
@@ -2,27 +2,28 @@ name: simple
|
|||||||
|
|
||||||
on: [push, pull_request]
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
simple:
|
simple:
|
||||||
|
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 `cargo check/test` on ${{ matrix.os }}
|
name: Test `cargo check/test/build` 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@v3
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
# When rustup is updated, it tries to replace its binary, which on Windows is somehow locked.
|
- run: rustup toolchain install stable --profile minimal --no-self-update
|
||||||
# This can result in the CI failure, see: https://github.com/rust-lang/rustup/issues/3029
|
|
||||||
- run: |
|
|
||||||
rustup set auto-self-update disable
|
|
||||||
rustup toolchain install stable --profile minimal
|
|
||||||
|
|
||||||
- uses: ./
|
- uses: ./
|
||||||
with:
|
with:
|
||||||
@@ -31,4 +32,5 @@ jobs:
|
|||||||
- run: |
|
- run: |
|
||||||
cargo check
|
cargo check
|
||||||
cargo test
|
cargo test
|
||||||
|
cargo build --release
|
||||||
working-directory: tests
|
working-directory: tests
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
name: sparse-registry
|
|
||||||
|
|
||||||
on: [push, pull_request]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
sparse-registry:
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
||||||
|
|
||||||
name: Test `cargo check/test` with sparse registry on ${{ matrix.os }}
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
|
|
||||||
env:
|
|
||||||
CARGO_TERM_COLOR: always
|
|
||||||
CARGO_UNSTABLE_SPARSE_REGISTRY: true
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
|
|
||||||
# When rustup is updated, it tries to replace its binary, which on Windows is somehow locked.
|
|
||||||
# This can result in the CI failure, see: https://github.com/rust-lang/rustup/issues/3029
|
|
||||||
- run: |
|
|
||||||
rustup set auto-self-update disable
|
|
||||||
rustup toolchain install nightly --profile minimal
|
|
||||||
rustup default nightly
|
|
||||||
|
|
||||||
- uses: ./
|
|
||||||
with:
|
|
||||||
workspaces: tests
|
|
||||||
|
|
||||||
- run: |
|
|
||||||
cargo check
|
|
||||||
cargo test
|
|
||||||
working-directory: tests
|
|
||||||
@@ -2,8 +2,11 @@ name: target-dir
|
|||||||
|
|
||||||
on: [push, pull_request]
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
target-dir:
|
target-dir:
|
||||||
|
if: github.repository == 'Swatinem/rust-cache'
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
@@ -16,13 +19,11 @@ jobs:
|
|||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
# When rustup is updated, it tries to replace its binary, which on Windows is somehow locked.
|
- run: rustup toolchain install stable --profile minimal --no-self-update
|
||||||
# This can result in the CI failure, see: https://github.com/rust-lang/rustup/issues/3029
|
|
||||||
- run: |
|
|
||||||
rustup set auto-self-update disable
|
|
||||||
rustup toolchain install stable --profile minimal
|
|
||||||
|
|
||||||
# the `workspaces` option has the format `$workspace -> $target-dir`
|
# the `workspaces` option has the format `$workspace -> $target-dir`
|
||||||
# and the `$target-dir` is relative to the `$workspace`.
|
# and the `$target-dir` is relative to the `$workspace`.
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
name: warpbuild
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
warpbuild:
|
||||||
|
if: github.repository == 'Swatinem/rust-cache'
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||||
|
|
||||||
|
name: Test warpbuild provider 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: ./
|
||||||
|
with:
|
||||||
|
workspaces: tests
|
||||||
|
cache-provider: warpbuild
|
||||||
|
|
||||||
|
- run: |
|
||||||
|
cargo check
|
||||||
|
cargo test
|
||||||
|
cargo build --release
|
||||||
|
working-directory: tests
|
||||||
@@ -2,8 +2,11 @@ name: workspaces
|
|||||||
|
|
||||||
on: [push, pull_request]
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
permissions: {}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
workspaces:
|
workspaces:
|
||||||
|
if: github.repository == 'Swatinem/rust-cache'
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
@@ -16,13 +19,11 @@ jobs:
|
|||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
# When rustup is updated, it tries to replace its binary, which on Windows is somehow locked.
|
- run: rustup toolchain install stable --profile minimal --target wasm32-unknown-unknown --no-self-update
|
||||||
# This can result in the CI failure, see: https://github.com/rust-lang/rustup/issues/3029
|
|
||||||
- run: |
|
|
||||||
rustup set auto-self-update disable
|
|
||||||
rustup toolchain install stable --profile minimal --target wasm32-unknown-unknown
|
|
||||||
|
|
||||||
- uses: ./
|
- uses: ./
|
||||||
with:
|
with:
|
||||||
@@ -30,8 +31,10 @@ jobs:
|
|||||||
tests
|
tests
|
||||||
tests/wasm-workspace
|
tests/wasm-workspace
|
||||||
|
|
||||||
- run: cargo check
|
- name: cargo check (tests)
|
||||||
working-directory: tests
|
working-directory: tests
|
||||||
|
run: cargo check
|
||||||
|
|
||||||
- run: cargo check
|
- name: cargo check (tests/wasm-workspace)
|
||||||
working-directory: tests/wasm-workspace
|
working-directory: tests/wasm-workspace
|
||||||
|
run: cargo check
|
||||||
|
|||||||
@@ -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@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: Run zizmor 🌈
|
||||||
|
uses: zizmorcore/zizmor-action@85b2b9fb8e3325e7a23d7d0a9d7ba5ae0f999e3e # v0.7.1
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
target/
|
target/
|
||||||
|
src/*.js
|
||||||
|
.build
|
||||||
|
|
||||||
# Editors
|
# Editors
|
||||||
.idea/
|
.idea/
|
||||||
|
|||||||
+102
@@ -1,5 +1,107 @@
|
|||||||
# 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
|
||||||
|
|
||||||
|
- Don't overwrite env for cargo-metadata call
|
||||||
|
|
||||||
|
## 2.8.1
|
||||||
|
|
||||||
|
- Set empty `CARGO_ENCODED_RUSTFLAGS` when retrieving metadata
|
||||||
|
- Various dependency updates
|
||||||
|
|
||||||
|
## 2.8.0
|
||||||
|
|
||||||
|
- Add support for `warpbuild` cache provider
|
||||||
|
- Add new `cache-workspace-crates` feature
|
||||||
|
|
||||||
|
## 2.7.8
|
||||||
|
|
||||||
|
- Include CPU arch in the cache key
|
||||||
|
|
||||||
|
## 2.7.7
|
||||||
|
|
||||||
|
- Also cache `cargo install` metadata
|
||||||
|
|
||||||
|
## 2.7.6
|
||||||
|
|
||||||
|
- Allow opting out of caching $CARGO_HOME/bin
|
||||||
|
- Add runner OS in cache key
|
||||||
|
- Adds an option to do lookup-only of the cache
|
||||||
|
|
||||||
|
## 2.7.5
|
||||||
|
|
||||||
|
- Support Cargo.lock format cargo-lock v4
|
||||||
|
- Only run macOsWorkaround() on macOS
|
||||||
|
|
||||||
|
## 2.7.3
|
||||||
|
|
||||||
|
- Work around upstream problem that causes cache saving to hang for minutes.
|
||||||
|
|
||||||
|
## 2.7.2
|
||||||
|
|
||||||
|
- Only key by `Cargo.toml` and `Cargo.lock` files of workspace members.
|
||||||
|
|
||||||
|
## 2.7.1
|
||||||
|
|
||||||
|
- Update toml parser to fix parsing errors.
|
||||||
|
|
||||||
|
## 2.7.0
|
||||||
|
|
||||||
|
- Properly cache `trybuild` tests.
|
||||||
|
|
||||||
|
## 2.6.2
|
||||||
|
|
||||||
|
- Fix `toml` parsing.
|
||||||
|
|
||||||
|
## 2.6.1
|
||||||
|
|
||||||
|
- Fix hash contributions of `Cargo.lock`/`Cargo.toml` files.
|
||||||
|
|
||||||
|
## 2.6.0
|
||||||
|
|
||||||
|
- Add "buildjet" as a second `cache-provider` backend.
|
||||||
|
- Clean up sparse registry index.
|
||||||
|
- Do not clean up src of `-sys` crates.
|
||||||
|
- Remove `.cargo/credentials.toml` before saving.
|
||||||
|
|
||||||
|
## 2.5.1
|
||||||
|
|
||||||
|
- Fix hash contribution of `Cargo.lock`.
|
||||||
|
|
||||||
|
## 2.5.0
|
||||||
|
|
||||||
|
- feat: Rm workspace crates version before caching.
|
||||||
|
- feat: Add hash of `.cargo/config.toml` to key.
|
||||||
|
|
||||||
|
## 2.4.0
|
||||||
|
|
||||||
|
- Fix cache key stability.
|
||||||
|
- Use 8 character hash components to reduce the key length, making it more readable.
|
||||||
|
|
||||||
## 2.3.0
|
## 2.3.0
|
||||||
|
|
||||||
- Add `cache-all-crates` option, which enables caching of crates installed by workflows.
|
- Add `cache-all-crates` option, which enables caching of crates installed by workflows.
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ sensible defaults.
|
|||||||
## Example usage
|
## Example usage
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: actions/checkout@v3
|
- 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
|
||||||
@@ -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
|
||||||
@@ -60,11 +70,45 @@ sensible defaults.
|
|||||||
# default: "false"
|
# default: "false"
|
||||||
cache-all-crates: ""
|
cache-all-crates: ""
|
||||||
|
|
||||||
# Determiners whether the cache should be saved.
|
# Similar to cache-all-crates.
|
||||||
|
# If `true` the workspace crates will be cached.
|
||||||
|
# Useful if the workspace contains libraries that are only updated sporadically.
|
||||||
|
# default: "false"
|
||||||
|
cache-workspace-crates: ""
|
||||||
|
|
||||||
|
# Determines whether the cache should be saved.
|
||||||
# If `false`, the cache is only restored.
|
# If `false`, the cache is only restored.
|
||||||
# Useful for jobs where the matrix is additive e.g. additional Cargo features.
|
# Useful for jobs where the matrix is additive e.g. additional Cargo features,
|
||||||
|
# or when only runs from `master` should be saved to the cache.
|
||||||
# default: "true"
|
# default: "true"
|
||||||
save-if: ""
|
save-if: ""
|
||||||
|
# To only cache runs from `master`:
|
||||||
|
save-if: ${{ github.ref == 'refs/heads/master' }}
|
||||||
|
|
||||||
|
# Determines whether the cache should be restored.
|
||||||
|
# If `true` the cache key will be checked and the `cache-hit` output will be set
|
||||||
|
# but the cache itself won't be restored
|
||||||
|
# default: "false"
|
||||||
|
lookup-only: ""
|
||||||
|
|
||||||
|
# Specifies what to use as the backend providing cache
|
||||||
|
# Can be set to "github", or "warpbuild"
|
||||||
|
# default: "github"
|
||||||
|
cache-provider: ""
|
||||||
|
|
||||||
|
# Determines whether to cache the ~/.cargo/bin directory.
|
||||||
|
# default: "true"
|
||||||
|
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.
|
||||||
@@ -77,15 +121,16 @@ This is a boolean flag that will be set to `true` when there was an exact cache
|
|||||||
|
|
||||||
## Cache Effectiveness
|
## Cache Effectiveness
|
||||||
|
|
||||||
This action only caches the _dependencies_ of a crate, so is more effective if
|
This action only caches the _dependencies_ of a crate, so it is more effective if
|
||||||
the dependency / own code ratio is higher.
|
the dependency / own code ratio is higher.
|
||||||
|
|
||||||
It is also most effective for repositories with a `Cargo.lock` file. Library
|
It is also more effective for repositories with a `Cargo.lock` file. Library
|
||||||
repositories with only a `Cargo.toml` file have limited benefits, as cargo will
|
repositories with only a `Cargo.toml` file have limited benefits, as cargo will
|
||||||
_always_ use the most up-to-date dependency versions, which may not be cached.
|
_always_ use the most up-to-date dependency versions, which may not be cached.
|
||||||
|
|
||||||
Usage with Stable Rust is most effective, as a cache is tied to the Rust version.
|
Usage with Stable Rust is the most effective, as a cache is tied to the Rust version.
|
||||||
Using it with Nightly Rust is less effective as it will throw away the cache every day.
|
Using it with Nightly Rust is less effective as it will throw away the cache every day,
|
||||||
|
unless a specific nightly build is being pinned.
|
||||||
|
|
||||||
## Cache Details
|
## Cache Details
|
||||||
|
|
||||||
@@ -96,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 installed packages as generated by `cargo install --list`.
|
- 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.
|
||||||
|
|
||||||
@@ -137,7 +185,7 @@ otherwise corrupt the cache on macOS builds.
|
|||||||
This specialized cache action is built on top of the upstream cache action
|
This specialized cache action is built on top of the upstream cache action
|
||||||
maintained by GitHub. The same restrictions and limits apply, which are
|
maintained by GitHub. The same restrictions and limits apply, which are
|
||||||
documented here:
|
documented here:
|
||||||
https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows
|
[Caching dependencies to speed up workflows](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows)
|
||||||
|
|
||||||
In particular, caches are currently limited to 10 GB in total and exceeding that
|
In particular, caches are currently limited to 10 GB in total and exceeding that
|
||||||
limit will cause eviction of older caches.
|
limit will cause eviction of older caches.
|
||||||
@@ -160,4 +208,7 @@ to see those details as well as further details related to caching operations.
|
|||||||
## Known issues
|
## Known issues
|
||||||
|
|
||||||
- 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`).
|
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
|
||||||
|
is expected to be preserved across runs. You can work around this by setting
|
||||||
|
`cache-bin: "false"`.
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
- better .cargo/bin handling:
|
- better .cargo/bin handling:
|
||||||
- get a list of all the files on "pre"/"restore"
|
- get a list of all the files on "pre"/"restore"
|
||||||
- move the files out of the way on "post"/"save" and move them back afterwards
|
- move the files out of the way on "post"/"save" and move them back afterwards
|
||||||
- properly clean sparse registry
|
|
||||||
|
|||||||
+31
-3
@@ -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
|
||||||
@@ -32,17 +40,37 @@ inputs:
|
|||||||
description: "Determines which crates are cached. If `true` all crates will be cached, otherwise only dependent crates will be cached."
|
description: "Determines which crates are cached. If `true` all crates will be cached, otherwise only dependent crates will be cached."
|
||||||
required: false
|
required: false
|
||||||
default: "false"
|
default: "false"
|
||||||
|
cache-workspace-crates:
|
||||||
|
description: "Similar to cache-all-crates. If `true` the workspace crates will be cached."
|
||||||
|
required: false
|
||||||
|
default: "false"
|
||||||
save-if:
|
save-if:
|
||||||
description: "Determiners whether the cache should be saved. If `false`, the cache is only restored."
|
description: "Determiners whether the cache should be saved. If `false`, the cache is only restored."
|
||||||
required: false
|
required: false
|
||||||
default: "true"
|
default: "true"
|
||||||
|
cache-provider:
|
||||||
|
description: "Determines which provider to use for caching. Options are github, or warpbuild. Defaults to github."
|
||||||
|
required: false
|
||||||
|
default: "github"
|
||||||
|
cache-bin:
|
||||||
|
description: "Determines whether to cache ${CARGO_HOME}/bin."
|
||||||
|
required: false
|
||||||
|
default: "true"
|
||||||
|
lookup-only:
|
||||||
|
description: "Check if a cache entry exists without downloading the cache"
|
||||||
|
required: 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: "node16"
|
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
-60503
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
-60521
File diff suppressed because one or more lines are too long
Vendored
+1825
File diff suppressed because it is too large
Load Diff
Generated
+2855
-716
File diff suppressed because it is too large
Load Diff
+25
-9
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"name": "rust-cache",
|
"name": "rust-cache",
|
||||||
"version": "2.3.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,19 +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/cache": "^3.2.1",
|
"@actions/cache": "^6.3.0",
|
||||||
"@actions/core": "^1.10.0",
|
"@actions/core": "^3.0.1",
|
||||||
"@actions/exec": "^1.1.1",
|
"@actions/exec": "^3.0.0",
|
||||||
"@actions/glob": "^0.4.0",
|
"@actions/glob": "^0.7.0",
|
||||||
"@actions/io": "^1.1.3"
|
"@actions/io": "^3.0.2",
|
||||||
|
"@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": {
|
||||||
"@vercel/ncc": "^0.36.1",
|
"@rollup/plugin-commonjs": "^29.0.3",
|
||||||
|
"@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.0.4"
|
"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;
|
||||||
+117
-56
@@ -3,8 +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, STATE_BINS } from "./config";
|
import { CARGO_HOME } from "./config.js";
|
||||||
import { Packages } from "./workspace";
|
import { exists } from "./utils.js";
|
||||||
|
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}"`);
|
||||||
@@ -14,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") {
|
||||||
@@ -34,10 +39,30 @@ export async function cleanTargetDir(targetDir: string, packages: Packages, chec
|
|||||||
async function cleanProfileTarget(profileDir: string, packages: Packages, checkTimestamp = false) {
|
async function cleanProfileTarget(profileDir: string, packages: Packages, checkTimestamp = false) {
|
||||||
core.debug(`cleaning profile directory "${profileDir}"`);
|
core.debug(`cleaning profile directory "${profileDir}"`);
|
||||||
|
|
||||||
|
// Quite a few testing utility crates store compilation artifacts as nested
|
||||||
|
// workspaces under `target/tests`. Notably, `target/tests/target` and
|
||||||
|
// `target/tests/trybuild`.
|
||||||
|
if (path.basename(profileDir) === "tests") {
|
||||||
|
try {
|
||||||
|
// https://github.com/vertexclique/kaos/blob/9876f6c890339741cc5be4b7cb9df72baa5a6d79/src/cargo.rs#L25
|
||||||
|
// https://github.com/eupn/macrotest/blob/c4151a5f9f545942f4971980b5d264ebcd0b1d11/src/cargo.rs#L27
|
||||||
|
await cleanTargetDir(path.join(profileDir, "target"), packages, checkTimestamp);
|
||||||
|
} catch {}
|
||||||
|
try {
|
||||||
|
// https://github.com/dtolnay/trybuild/blob/eec8ca6cb9b8f53d0caf1aa499d99df52cae8b40/src/cargo.rs#L50
|
||||||
|
await cleanTargetDir(path.join(profileDir, "trybuild"), packages, checkTimestamp);
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
// Delete everything else.
|
||||||
|
await rmExcept(profileDir, new Set(["target", "trybuild"]), checkTimestamp);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
@@ -54,43 +79,33 @@ 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>();
|
* Clean the cargo bin directory, removing the binaries that existed
|
||||||
try {
|
* when the action started, as they were not created by the build.
|
||||||
const { installs }: { installs: { [key: string]: { bins: Array<string> } } } = JSON.parse(
|
*
|
||||||
await fs.promises.readFile(path.join(CARGO_HOME, ".crates2.json"), "utf8"),
|
* @param oldBins The binaries that existed when the action started.
|
||||||
);
|
*/
|
||||||
for (const pkg of Object.values(installs)) {
|
export async function cleanBin(oldBins: Array<string>) {
|
||||||
for (const bin of pkg.bins) {
|
const binsToRemove = new Set<string>(oldBins);
|
||||||
bins.add(bin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch {}
|
|
||||||
return bins;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function cleanBin() {
|
|
||||||
const bins = await getCargoBins();
|
|
||||||
const oldBins = JSON.parse(core.getState(STATE_BINS));
|
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function cleanRegistry(packages: Packages, crates = true) {
|
export async function cleanRegistry(packages: Packages, crates = true) {
|
||||||
// `.cargo/registry/src`
|
// remove `.cargo/credentials.toml`
|
||||||
// we can remove this completely, as cargo will recreate this from `cache`
|
try {
|
||||||
await rmRF(path.join(CARGO_HOME, "registry", "src"));
|
const credentials = path.join(CARGO_HOME, "credentials.toml");
|
||||||
|
core.debug(`deleting "${credentials}"`);
|
||||||
|
await fs.promises.unlink(credentials);
|
||||||
|
} catch {}
|
||||||
|
|
||||||
// `.cargo/registry/index`
|
// `.cargo/registry/index`
|
||||||
|
let pkgSet = new Set(packages.map((p) => p.name));
|
||||||
const indexDir = await fs.promises.opendir(path.join(CARGO_HOME, "registry", "index"));
|
const indexDir = await fs.promises.opendir(path.join(CARGO_HOME, "registry", "index"));
|
||||||
for await (const dirent of indexDir) {
|
for await (const dirent of indexDir) {
|
||||||
if (dirent.isDirectory()) {
|
if (dirent.isDirectory()) {
|
||||||
@@ -101,19 +116,38 @@ export async function cleanRegistry(packages: Packages, crates = true) {
|
|||||||
// for a git registry, we can remove `.cache`, as cargo will recreate it from git
|
// for a git registry, we can remove `.cache`, as cargo will recreate it from git
|
||||||
if (await exists(path.join(dirPath, ".git"))) {
|
if (await exists(path.join(dirPath, ".git"))) {
|
||||||
await rmRF(path.join(dirPath, ".cache"));
|
await rmRF(path.join(dirPath, ".cache"));
|
||||||
|
} else {
|
||||||
|
await cleanRegistryIndexCache(dirPath, pkgSet);
|
||||||
}
|
}
|
||||||
// TODO: else, clean `.cache` based on the `packages`
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!crates) {
|
if (!crates) {
|
||||||
core.debug(`skipping crate cleanup`);
|
core.debug("skipping registry cache and src cleanup");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const pkgSet = new Set(packages.map((p) => `${p.name}-${p.version}.crate`));
|
// `.cargo/registry/src`
|
||||||
|
// Cargo usually re-creates these from the `.crate` cache below,
|
||||||
|
// but for some reason that does not work for `-sys` crates that check timestamps
|
||||||
|
// to decide if rebuilds are necessary.
|
||||||
|
pkgSet = new Set(packages.filter((p) => p.name.endsWith("-sys")).map((p) => `${p.name}-${p.version}`));
|
||||||
|
const srcDir = await fs.promises.opendir(path.join(CARGO_HOME, "registry", "src"));
|
||||||
|
for await (const dirent of srcDir) {
|
||||||
|
if (dirent.isDirectory()) {
|
||||||
|
// eg `.cargo/registry/src/github.com-1ecc6299db9ec823`
|
||||||
|
// or `.cargo/registry/src/index.crates.io-e139d0d48fed7772`
|
||||||
|
const dir = await fs.promises.opendir(path.join(srcDir.path, dirent.name));
|
||||||
|
for await (const dirent of dir) {
|
||||||
|
if (dirent.isDirectory() && !pkgSet.has(dirent.name)) {
|
||||||
|
await rmRF(path.join(dir.path, dirent.name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// `.cargo/registry/cache`
|
// `.cargo/registry/cache`
|
||||||
|
pkgSet = new Set(packages.map((p) => `${p.name}-${p.version}.crate`));
|
||||||
const cacheDir = await fs.promises.opendir(path.join(CARGO_HOME, "registry", "cache"));
|
const cacheDir = await fs.promises.opendir(path.join(CARGO_HOME, "registry", "cache"));
|
||||||
for await (const dirent of cacheDir) {
|
for await (const dirent of cacheDir) {
|
||||||
if (dirent.isDirectory()) {
|
if (dirent.isDirectory()) {
|
||||||
@@ -130,6 +164,28 @@ export async function cleanRegistry(packages: Packages, crates = true) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Recursively walks and cleans the index `.cache`
|
||||||
|
async function cleanRegistryIndexCache(dirName: string, keepPkg: Set<string>) {
|
||||||
|
let dirIsEmpty = true;
|
||||||
|
const cacheDir = await fs.promises.opendir(dirName);
|
||||||
|
for await (const dirent of cacheDir) {
|
||||||
|
if (dirent.isDirectory()) {
|
||||||
|
if (await cleanRegistryIndexCache(path.join(dirName, dirent.name), keepPkg)) {
|
||||||
|
await rm(dirName, dirent);
|
||||||
|
} else {
|
||||||
|
dirIsEmpty &&= false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (keepPkg.has(dirent.name)) {
|
||||||
|
dirIsEmpty &&= false;
|
||||||
|
} else {
|
||||||
|
await rm(dirName, dirent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return dirIsEmpty;
|
||||||
|
}
|
||||||
|
|
||||||
export async function cleanGit(packages: Packages) {
|
export async function cleanGit(packages: Packages) {
|
||||||
const coPath = path.join(CARGO_HOME, "git", "checkouts");
|
const coPath = path.join(CARGO_HOME, "git", "checkouts");
|
||||||
const dbPath = path.join(CARGO_HOME, "git", "db");
|
const dbPath = path.join(CARGO_HOME, "git", "db");
|
||||||
@@ -187,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);
|
||||||
@@ -205,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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -238,12 +308,3 @@ async function rmRF(dirName: string) {
|
|||||||
core.debug(`deleting "${dirName}"`);
|
core.debug(`deleting "${dirName}"`);
|
||||||
await io.rmRF(dirName);
|
await io.rmRF(dirName);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function exists(path: string) {
|
|
||||||
try {
|
|
||||||
await fs.promises.access(path);
|
|
||||||
return true;
|
|
||||||
} catch {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+283
-57
@@ -1,22 +1,25 @@
|
|||||||
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 { 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 { getCmdOutput } from "./utils";
|
import { CacheProvider, exists, getCmdOutput } from "./utils.js";
|
||||||
import { Workspace } from "./workspace";
|
import { Workspace } from "./workspace.js";
|
||||||
|
|
||||||
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");
|
||||||
|
|
||||||
const STATE_LOCKFILE_HASH = "RUST_CACHE_LOCKFILE_HASH";
|
const STATE_CONFIG = "RUST_CACHE_CONFIG";
|
||||||
const STATE_LOCKFILES = "RUST_CACHE_LOCKFILES";
|
const HASH_LENGTH = 8;
|
||||||
export const STATE_BINS = "RUST_CACHE_BINS";
|
|
||||||
export const STATE_KEY = "RUST_CACHE_KEY";
|
|
||||||
|
|
||||||
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 */
|
||||||
@@ -24,13 +27,19 @@ export class CacheConfig {
|
|||||||
/** The secondary (restore) key that only contains the prefix and environment */
|
/** The secondary (restore) key that only contains the prefix and environment */
|
||||||
public restoreKey = "";
|
public restoreKey = "";
|
||||||
|
|
||||||
|
/** Whether to cache CARGO_HOME/.bin */
|
||||||
|
public cacheBin: boolean = true;
|
||||||
|
|
||||||
/** The workspace configurations */
|
/** The workspace configurations */
|
||||||
public workspaces: Array<Workspace> = [];
|
public workspaces: Array<Workspace> = [];
|
||||||
|
|
||||||
|
/** The cargo binaries present during main step */
|
||||||
|
public cargoBins: Array<string> = [];
|
||||||
|
|
||||||
/** 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 */
|
||||||
@@ -46,6 +55,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.
|
||||||
@@ -62,11 +82,16 @@ 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}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add runner OS and CPU architecture to the key to avoid cross-contamination of cache
|
||||||
|
const runnerOS = os.type();
|
||||||
|
const runnerArch = os.arch();
|
||||||
|
key += `-${runnerOS}-${runnerArch}`;
|
||||||
|
|
||||||
self.keyPrefix = key;
|
self.keyPrefix = key;
|
||||||
|
|
||||||
// Construct environment portion of the key:
|
// Construct environment portion of the key:
|
||||||
@@ -77,14 +102,10 @@ 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 = (self.keyRust = await getRustVersions(cmdFormat));
|
||||||
|
for (const rustVersion of rustVersions) {
|
||||||
let keyRust = `${rustVersion.release} ${rustVersion.host}`;
|
hasher.update(rustVersion);
|
||||||
hasher.update(keyRust);
|
}
|
||||||
hasher.update(rustVersion["commit-hash"]);
|
|
||||||
|
|
||||||
keyRust += ` (${rustVersion["commit-hash"]})`;
|
|
||||||
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"];
|
||||||
@@ -104,24 +125,18 @@ export class CacheConfig {
|
|||||||
|
|
||||||
self.keyEnvs = keyEnvs;
|
self.keyEnvs = keyEnvs;
|
||||||
|
|
||||||
// Installed packages and their versions are also considered for the key.
|
// Add job hash suffix if 'add-rust-environment-hash-key' is true
|
||||||
const packages = await getPackages();
|
if (core.getInput("add-rust-environment-hash-key").toLowerCase() == "true") {
|
||||||
hasher.update(packages);
|
key += `-${digest(hasher)}`;
|
||||||
|
}
|
||||||
key += `-${hasher.digest("hex")}`;
|
|
||||||
|
|
||||||
self.restoreKey = key;
|
self.restoreKey = key;
|
||||||
|
|
||||||
// Construct the lockfiles portion of the key:
|
// Construct the lockfiles portion of the key:
|
||||||
// This considers all the files found via globbing for various manifests
|
// This considers all the files found via globbing for various manifests
|
||||||
// and lockfiles.
|
// and lockfiles.
|
||||||
// This part is computed in the "pre"/"restore" part of the job and persisted
|
|
||||||
// into the `state`. That state is loaded in the "post"/"save" part of the
|
|
||||||
// job so we have consistent values even though the "main" actions run
|
|
||||||
// might create/overwrite lockfiles.
|
|
||||||
|
|
||||||
let lockHash = core.getState(STATE_LOCKFILE_HASH);
|
self.cacheBin = core.getInput("cache-bin").toLowerCase() == "true";
|
||||||
let keyFiles: Array<string> = JSON.parse(core.getState(STATE_LOCKFILES) || "[]");
|
|
||||||
|
|
||||||
// Constructs the workspace config and paths to restore:
|
// Constructs the workspace config and paths to restore:
|
||||||
// The workspaces are given using a `$workspace -> $target` syntax.
|
// The workspaces are given using a `$workspace -> $target` syntax.
|
||||||
@@ -136,37 +151,126 @@ export class CacheConfig {
|
|||||||
}
|
}
|
||||||
self.workspaces = workspaces;
|
self.workspaces = workspaces;
|
||||||
|
|
||||||
if (!lockHash) {
|
// Add hash suffix of all rust environment lockfiles + manifests if
|
||||||
keyFiles = keyFiles.concat(await globFiles("rust-toolchain\nrust-toolchain.toml"));
|
// '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");
|
||||||
|
|
||||||
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.toml\n${root}/**/Cargo.lock\n${root}/**/rust-toolchain\n${root}/**/rust-toolchain.toml`,
|
`${root}/**/.cargo/config.toml\n${root}/**/rust-toolchain\n${root}/**/rust-toolchain.toml`,
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
}
|
|
||||||
keyFiles = keyFiles.filter(file => !fs.statSync(file).isDirectory());
|
|
||||||
keyFiles.sort((a, b) => a.localeCompare(b));
|
|
||||||
|
|
||||||
hasher = crypto.createHash("sha1");
|
const workspaceMembers = await workspace.getWorkspaceMembers(cmdFormat);
|
||||||
|
|
||||||
|
const cargo_manifests = sort_and_uniq(workspaceMembers.map((member) => path.join(member.path, "Cargo.toml")));
|
||||||
|
|
||||||
|
for (const cargo_manifest of cargo_manifests) {
|
||||||
|
try {
|
||||||
|
const content = await fs.readFile(cargo_manifest, { encoding: "utf8" });
|
||||||
|
// Use any since TomlPrimitive is not exposed
|
||||||
|
const parsed = toml.parse(content) as { [key: string]: any };
|
||||||
|
|
||||||
|
if ("package" in parsed) {
|
||||||
|
const pack = parsed.package;
|
||||||
|
if ("version" in pack) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
if (await exists(cargo_lock)) {
|
||||||
|
try {
|
||||||
|
const content = await fs.readFile(cargo_lock, { encoding: "utf8" });
|
||||||
|
const parsed = toml.parse(content);
|
||||||
|
|
||||||
|
if ((parsed.version !== 3 && parsed.version !== 4) || !("package" in parsed)) {
|
||||||
|
// Fallback to caching them as regular file since this action
|
||||||
|
// can only handle Cargo.lock format version 3
|
||||||
|
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 = 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lockHash = hasher.digest("hex");
|
|
||||||
|
|
||||||
core.saveState(STATE_LOCKFILE_HASH, lockHash);
|
keyFiles.push(...parsedKeyFiles);
|
||||||
core.saveState(STATE_LOCKFILES, JSON.stringify(keyFiles));
|
self.keyFiles = sort_and_uniq(keyFiles);
|
||||||
|
|
||||||
|
let lockHash = digest(hasher);
|
||||||
|
key += `-${lockHash}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.keyFiles = keyFiles;
|
|
||||||
|
|
||||||
key += `-${lockHash}`;
|
|
||||||
self.cacheKey = key;
|
self.cacheKey = key;
|
||||||
|
|
||||||
self.cachePaths = [CARGO_HOME];
|
self.cachePaths = [path.join(CARGO_HOME, "registry"), path.join(CARGO_HOME, "git")];
|
||||||
|
if (self.cacheBin) {
|
||||||
|
self.cachePaths = [
|
||||||
|
path.join(CARGO_HOME, "bin"),
|
||||||
|
path.join(CARGO_HOME, ".crates.toml"),
|
||||||
|
path.join(CARGO_HOME, ".crates2.json"),
|
||||||
|
...self.cachePaths,
|
||||||
|
];
|
||||||
|
}
|
||||||
const cacheTargets = core.getInput("cache-targets").toLowerCase() || "true";
|
const cacheTargets = core.getInput("cache-targets").toLowerCase() || "true";
|
||||||
if (cacheTargets === "true") {
|
if (cacheTargets === "true") {
|
||||||
self.cachePaths.push(...workspaces.map((ws) => ws.target));
|
self.cachePaths.push(...workspaces.map((ws) => ws.target));
|
||||||
@@ -177,11 +281,40 @@ export class CacheConfig {
|
|||||||
self.cachePaths.push(dir);
|
self.cachePaths.push(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bins = await getCargoBins();
|
||||||
|
self.cargoBins = Array.from(bins.values());
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
printInfo() {
|
/**
|
||||||
|
* Reads and returns the cache config from the action `state`.
|
||||||
|
*
|
||||||
|
* @throws {Error} if the state is not present.
|
||||||
|
* @returns {CacheConfig} the configuration.
|
||||||
|
* @see {@link CacheConfig#saveState}
|
||||||
|
* @see {@link CacheConfig#new}
|
||||||
|
*/
|
||||||
|
static fromState(): CacheConfig {
|
||||||
|
const source = core.getState(STATE_CONFIG);
|
||||||
|
if (!source) {
|
||||||
|
throw new Error("Cache configuration not found in state");
|
||||||
|
}
|
||||||
|
|
||||||
|
const self = new CacheConfig();
|
||||||
|
Object.assign(self, JSON.parse(source));
|
||||||
|
self.workspaces = self.workspaces.map((w: any) => new Workspace(w.root, w.target));
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prints the configuration to the action log.
|
||||||
|
*/
|
||||||
|
printInfo(cacheProvider: CacheProvider) {
|
||||||
core.startGroup("Cache Configuration");
|
core.startGroup("Cache Configuration");
|
||||||
|
core.info(`Cache Provider:`);
|
||||||
|
core.info(` ${cacheProvider.name}`);
|
||||||
core.info(`Workspaces:`);
|
core.info(`Workspaces:`);
|
||||||
for (const workspace of this.workspaces) {
|
for (const workspace of this.workspaces) {
|
||||||
core.info(` ${workspace.root}`);
|
core.info(` ${workspace.root}`);
|
||||||
@@ -197,7 +330,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}`);
|
||||||
}
|
}
|
||||||
@@ -207,6 +343,76 @@ export class CacheConfig {
|
|||||||
}
|
}
|
||||||
core.endGroup();
|
core.endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves the configuration to the state store.
|
||||||
|
* This is used to restore the configuration in the post action.
|
||||||
|
*/
|
||||||
|
saveState() {
|
||||||
|
core.saveState(STATE_CONFIG, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the cache is up to date.
|
||||||
|
*
|
||||||
|
* @returns `true` if the cache is up to date, `false` otherwise.
|
||||||
|
*/
|
||||||
|
export function isCacheUpToDate(): boolean {
|
||||||
|
return core.getState(STATE_CONFIG) === "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a hex digest of the given hasher truncated to `HASH_LENGTH`.
|
||||||
|
*
|
||||||
|
* @param hasher The hasher to digest.
|
||||||
|
* @returns The hex digest.
|
||||||
|
*/
|
||||||
|
function digest(hasher: crypto.Hash): string {
|
||||||
|
return hasher.digest("hex").substring(0, HASH_LENGTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getCargoBins(): Promise<Set<string>> {
|
||||||
|
const bins = new Set<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<Array<string>> {
|
||||||
|
const versions = new Set<string>();
|
||||||
|
|
||||||
|
versions.add(parseRustVersion(await getCmdOutput(cmdFormat, "rustc -vV")));
|
||||||
|
|
||||||
|
const stdout = await (async () => {
|
||||||
|
try {
|
||||||
|
return await getCmdOutput(cmdFormat, "rustup toolchain list --quiet");
|
||||||
|
} catch (e) {
|
||||||
|
core.info(`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`)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const rustVersions = Array.from(versions);
|
||||||
|
// Doesn't matter how they're sorted, just as long as it's deterministic.
|
||||||
|
rustVersions.sort();
|
||||||
|
return rustVersions;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface RustVersion {
|
interface RustVersion {
|
||||||
@@ -214,26 +420,46 @@ interface RustVersion {
|
|||||||
release: string;
|
release: string;
|
||||||
"commit-hash": string;
|
"commit-hash": string;
|
||||||
}
|
}
|
||||||
|
function parseRustVersion(stdout: string): string {
|
||||||
async function getRustVersion(): Promise<RustVersion> {
|
const splits = stdout
|
||||||
const stdout = await getCmdOutput("rustc", ["-vV"]);
|
|
||||||
let 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 getPackages(): Promise<string> {
|
|
||||||
let stdout = await getCmdOutput("cargo", ["install", "--list"]);
|
|
||||||
// Make OS independent.
|
|
||||||
return stdout.split(/[\n\r]+/).join("\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function globFiles(pattern: string): Promise<string[]> {
|
async function globFiles(pattern: string): Promise<string[]> {
|
||||||
const globber = await glob.create(pattern, {
|
const globber = await glob.create(pattern, {
|
||||||
followSymbolicLinks: false,
|
followSymbolicLinks: false,
|
||||||
});
|
});
|
||||||
return await globber.glob();
|
// fs.stat resolve the symbolic link and returns stat for the
|
||||||
|
// file it pointed to, so isFile would make sure the resolved
|
||||||
|
// file is actually a regular file.
|
||||||
|
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[]) {
|
||||||
|
return a
|
||||||
|
.sort((a, b) => a.localeCompare(b))
|
||||||
|
.reduce((accumulator: string[], currentValue: string) => {
|
||||||
|
const len = accumulator.length;
|
||||||
|
// If accumulator is empty or its last element != currentValue
|
||||||
|
// Since array is already sorted, elements with the same value
|
||||||
|
// are grouped together to be continugous in space.
|
||||||
|
//
|
||||||
|
// If currentValue != last element, then it must be unique.
|
||||||
|
if (len == 0 || accumulator[len - 1].localeCompare(currentValue) != 0) {
|
||||||
|
accumulator.push(currentValue);
|
||||||
|
}
|
||||||
|
return accumulator;
|
||||||
|
}, []);
|
||||||
}
|
}
|
||||||
|
|||||||
+28
-18
@@ -1,18 +1,20 @@
|
|||||||
import * as cache from "@actions/cache";
|
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
|
|
||||||
import { cleanTargetDir, getCargoBins } from "./cleanup";
|
import { cleanTargetDir } from "./cleanup.js";
|
||||||
import { CacheConfig, STATE_BINS, STATE_KEY } from "./config";
|
import { CacheConfig } from "./config.js";
|
||||||
|
import { getCacheProvider, reportError } from "./utils.js";
|
||||||
|
|
||||||
process.on("uncaughtException", (e) => {
|
process.on("uncaughtException", (e) => {
|
||||||
core.info(`[warning] ${e.message}`);
|
core.error(e.message);
|
||||||
if (e.stack) {
|
if (e.stack) {
|
||||||
core.info(e.stack);
|
core.error(e.stack);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
if (!cache.isFeatureAvailable()) {
|
const cacheProvider = await getCacheProvider();
|
||||||
|
|
||||||
|
if (!cacheProvider.cache.isFeatureAvailable()) {
|
||||||
setCacheHitOutput(false);
|
setCacheHitOutput(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -22,46 +24,54 @@ async function run() {
|
|||||||
if (cacheOnFailure !== "true") {
|
if (cacheOnFailure !== "true") {
|
||||||
cacheOnFailure = "false";
|
cacheOnFailure = "false";
|
||||||
}
|
}
|
||||||
|
var lookupOnly = core.getInput("lookup-only").toLowerCase() === "true";
|
||||||
|
|
||||||
core.exportVariable("CACHE_ON_FAILURE", cacheOnFailure);
|
core.exportVariable("CACHE_ON_FAILURE", cacheOnFailure);
|
||||||
core.exportVariable("CARGO_INCREMENTAL", 0);
|
core.exportVariable("CARGO_INCREMENTAL", 0);
|
||||||
|
|
||||||
const config = await CacheConfig.new();
|
const config = await CacheConfig.new();
|
||||||
config.printInfo();
|
config.printInfo(cacheProvider);
|
||||||
core.info("");
|
core.info("");
|
||||||
|
|
||||||
const bins = await getCargoBins();
|
core.info(`... ${lookupOnly ? "Checking" : "Restoring"} cache ...`);
|
||||||
core.saveState(STATE_BINS, JSON.stringify([...bins]));
|
|
||||||
|
|
||||||
core.info(`... Restoring cache ...`);
|
|
||||||
const key = config.cacheKey;
|
const key = config.cacheKey;
|
||||||
// Pass a copy of cachePaths to avoid mutating the original array as reported by:
|
// Pass a copy of cachePaths to avoid mutating the original array as reported by:
|
||||||
// https://github.com/actions/toolkit/pull/1378
|
// https://github.com/actions/toolkit/pull/1378
|
||||||
// TODO: remove this once the underlying bug is fixed.
|
// TODO: remove this once the underlying bug is fixed.
|
||||||
const restoreKey = await cache.restoreCache(config.cachePaths.slice(), key, [config.restoreKey]);
|
const restoreKey = await cacheProvider.cache.restoreCache(config.cachePaths.slice(), key, [config.restoreKey], {
|
||||||
|
lookupOnly,
|
||||||
|
});
|
||||||
if (restoreKey) {
|
if (restoreKey) {
|
||||||
core.info(`Restored from cache key "${restoreKey}".`);
|
const match =
|
||||||
core.saveState(STATE_KEY, restoreKey);
|
restoreKey.localeCompare(key, undefined, {
|
||||||
|
sensitivity: "accent",
|
||||||
if (restoreKey !== key) {
|
}) === 0;
|
||||||
|
core.info(`${lookupOnly ? "Found" : "Restored from"} cache key "${restoreKey}" full match: ${match}.`);
|
||||||
|
if (!match) {
|
||||||
// pre-clean the target directory on cache mismatch
|
// pre-clean the target directory on cache mismatch
|
||||||
for (const workspace of config.workspaces) {
|
for (const workspace of config.workspaces) {
|
||||||
try {
|
try {
|
||||||
await cleanTargetDir(workspace.target, [], true);
|
await cleanTargetDir(workspace.target, [], true);
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We restored the cache but it is not a full match.
|
||||||
|
config.saveState();
|
||||||
}
|
}
|
||||||
|
|
||||||
setCacheHitOutput(restoreKey === key);
|
setCacheHitOutput(match);
|
||||||
} else {
|
} else {
|
||||||
core.info("No cache found.");
|
core.info("No cache found.");
|
||||||
|
config.saveState();
|
||||||
|
|
||||||
setCacheHitOutput(false);
|
setCacheHitOutput(false);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setCacheHitOutput(false);
|
setCacheHitOutput(false);
|
||||||
|
|
||||||
core.info(`[warning] ${(e as any).stack}`);
|
reportError(e);
|
||||||
}
|
}
|
||||||
|
process.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setCacheHitOutput(cacheHit: boolean): void {
|
function setCacheHitOutput(cacheHit: boolean): void {
|
||||||
|
|||||||
+39
-27
@@ -1,79 +1,91 @@
|
|||||||
import * as cache from "@actions/cache";
|
|
||||||
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, STATE_KEY } from "./config";
|
import { CacheConfig, isCacheUpToDate } from "./config.js";
|
||||||
|
import { getCacheProvider, reportError } from "./utils.js";
|
||||||
|
|
||||||
process.on("uncaughtException", (e) => {
|
process.on("uncaughtException", (e) => {
|
||||||
core.info(`[warning] ${e.message}`);
|
core.error(e.message);
|
||||||
if (e.stack) {
|
if (e.stack) {
|
||||||
core.info(e.stack);
|
core.error(e.stack);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
|
const cacheProvider = await getCacheProvider();
|
||||||
|
|
||||||
const save = core.getInput("save-if").toLowerCase() || "true";
|
const save = core.getInput("save-if").toLowerCase() || "true";
|
||||||
|
|
||||||
if (!(cache.isFeatureAvailable() && save === "true")) {
|
if (!(cacheProvider.cache.isFeatureAvailable() && save === "true")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const config = await CacheConfig.new();
|
if (isCacheUpToDate()) {
|
||||||
config.printInfo();
|
|
||||||
core.info("");
|
|
||||||
|
|
||||||
if (core.getState(STATE_KEY) === config.cacheKey) {
|
|
||||||
core.info(`Cache up-to-date.`);
|
core.info(`Cache up-to-date.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove this once https://github.com/actions/toolkit/pull/553 lands
|
const config = CacheConfig.fromState();
|
||||||
await macOsWorkaround();
|
config.printInfo(cacheProvider);
|
||||||
|
core.info("");
|
||||||
|
|
||||||
|
// TODO: remove this once https://github.com/actions/toolkit/pull/553 lands
|
||||||
|
if (process.env["RUNNER_OS"] == "macOS") {
|
||||||
|
await macOsWorkaround();
|
||||||
|
}
|
||||||
|
|
||||||
|
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.getPackages();
|
const packages = await workspace.getPackagesOutsideWorkspaceRoot(config.cmdFormat);
|
||||||
|
if (workspaceCrates === "true") {
|
||||||
|
const wsMembers = await workspace.getWorkspaceMembers(config.cmdFormat);
|
||||||
|
packages.push(...wsMembers);
|
||||||
|
}
|
||||||
allPackages.push(...packages);
|
allPackages.push(...packages);
|
||||||
try {
|
try {
|
||||||
core.info(`... Cleaning ${workspace.target} ...`);
|
core.info(`... Cleaning ${workspace.target} ...`);
|
||||||
await cleanTargetDir(workspace.target, packages);
|
await cleanTargetDir(workspace.target, packages);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
core.error(`${(e as any).stack}`);
|
core.debug(`${(e as any).stack}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const creates = core.getInput("cache-all-crates").toLowerCase() || "false";
|
const crates = core.getInput("cache-all-crates").toLowerCase() || "false";
|
||||||
core.info(`... Cleaning cargo registry cache-all-crates: ${creates} ...`);
|
core.info(`... Cleaning cargo registry (cache-all-crates: ${crates}) ...`);
|
||||||
await cleanRegistry(allPackages, creates === "true");
|
await cleanRegistry(allPackages, crates !== "true");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
core.error(`${(e as any).stack}`);
|
core.debug(`${(e as any).stack}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
if (config.cacheBin) {
|
||||||
core.info(`... Cleaning cargo/bin ...`);
|
try {
|
||||||
await cleanBin();
|
core.info(`... Cleaning cargo/bin ...`);
|
||||||
} catch (e) {
|
await cleanBin(config.cargoBins);
|
||||||
core.error(`${(e as any).stack}`);
|
} catch (e) {
|
||||||
|
core.debug(`${(e as any).stack}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
core.info(`... Cleaning cargo git cache ...`);
|
core.info(`... Cleaning cargo git cache ...`);
|
||||||
await cleanGit(allPackages);
|
await cleanGit(allPackages);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
core.error(`${(e as any).stack}`);
|
core.debug(`${(e as any).stack}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
core.info(`... Saving cache ...`);
|
core.info(`... Saving cache ...`);
|
||||||
// Pass a copy of cachePaths to avoid mutating the original array as reported by:
|
// Pass a copy of cachePaths to avoid mutating the original array as reported by:
|
||||||
// https://github.com/actions/toolkit/pull/1378
|
// https://github.com/actions/toolkit/pull/1378
|
||||||
// TODO: remove this once the underlying bug is fixed.
|
// TODO: remove this once the underlying bug is fixed.
|
||||||
await cache.saveCache(config.cachePaths.slice(), config.cacheKey);
|
await cacheProvider.cache.saveCache(config.cachePaths.slice(), config.cacheKey);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
core.error(`${(e as any).stack}`);
|
reportError(e);
|
||||||
}
|
}
|
||||||
|
process.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
run();
|
run();
|
||||||
|
|||||||
+58
-8
@@ -1,15 +1,23 @@
|
|||||||
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 fs from "fs";
|
||||||
|
|
||||||
export async function getCmdOutput(
|
export function reportError(e: any) {
|
||||||
cmd: string,
|
const { commandFailed } = e;
|
||||||
args: Array<string> = [],
|
if (commandFailed) {
|
||||||
options: exec.ExecOptions = {},
|
core.error(`Command failed: ${commandFailed.command}`);
|
||||||
): Promise<string> {
|
core.error(commandFailed.stderr);
|
||||||
|
} else {
|
||||||
|
core.error(`${e.stack}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getCmdOutput(cmdFormat: string, cmd: string, options: exec.ExecOptions = {}): 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) {
|
||||||
@@ -22,9 +30,51 @@ export async function getCmdOutput(
|
|||||||
...options,
|
...options,
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
core.info(`[warning] Command failed: ${cmd} ${args.join(" ")}`);
|
(e as any).commandFailed = {
|
||||||
core.info(`[warning] ${stderr}`);
|
command: cmd,
|
||||||
|
stderr,
|
||||||
|
};
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
return stdout;
|
return stdout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface GhCache {
|
||||||
|
isFeatureAvailable: typeof import("@actions/cache").isFeatureAvailable;
|
||||||
|
restoreCache: typeof import("@actions/cache").restoreCache;
|
||||||
|
saveCache: (paths: string[], key: string) => Promise<string | number>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CacheProvider {
|
||||||
|
name: string;
|
||||||
|
cache: GhCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getCacheProvider(): Promise<CacheProvider> {
|
||||||
|
const cacheProvider = core.getInput("cache-provider");
|
||||||
|
let cache: GhCache;
|
||||||
|
switch (cacheProvider) {
|
||||||
|
case "github":
|
||||||
|
cache = await import("@actions/cache");
|
||||||
|
break;
|
||||||
|
case "warpbuild":
|
||||||
|
cache = await import("@actions/warpbuild-cache");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Error(`The \`cache-provider\` \`${cacheProvider}\` is not valid.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
name: cacheProvider,
|
||||||
|
cache: cache,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function exists(path: string) {
|
||||||
|
try {
|
||||||
|
await fs.promises.access(path);
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+26
-10
@@ -1,33 +1,49 @@
|
|||||||
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,
|
||||||
|
) {}
|
||||||
|
|
||||||
public async getPackages(): 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"], {
|
await getCmdOutput(cmdFormat, cmd, {
|
||||||
cwd: this.root,
|
cwd: this.root,
|
||||||
|
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`);
|
||||||
for (const pkg of meta.packages) {
|
for (const pkg of meta.packages.filter(filter)) {
|
||||||
if (pkg.manifest_path.startsWith(this.root)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const targets = pkg.targets.filter((t) => t.kind.some((kind) => SAVE_TARGETS.has(kind))).map((t) => t.name);
|
const targets = pkg.targets.filter((t) => t.kind.some((kind) => SAVE_TARGETS.has(kind))).map((t) => t.name);
|
||||||
packages.push({ name: pkg.name, version: pkg.version, targets, path: path.dirname(pkg.manifest_path) });
|
packages.push({ name: pkg.name, version: pkg.version, targets, path: path.dirname(pkg.manifest_path) });
|
||||||
}
|
}
|
||||||
} catch {}
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
return packages;
|
return packages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getPackagesOutsideWorkspaceRoot(cmdFormat: string): Promise<Packages> {
|
||||||
|
return await this.getPackages(cmdFormat, (pkg) => !pkg.manifest_path.startsWith(this.root));
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getWorkspaceMembers(cmdFormat: string): Promise<Packages> {
|
||||||
|
return await this.getPackages(cmdFormat, (_) => true, "--no-deps");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PackageDefinition {
|
export interface PackageDefinition {
|
||||||
|
|||||||
Generated
+1119
-300
File diff suppressed because it is too large
Load Diff
+9
-2
@@ -6,5 +6,12 @@ authors = ["Arpad Borsos <arpad.borsos@googlemail.com>"]
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
reqwest = "0.11.11"
|
reqwest = "0.12.1"
|
||||||
watto = { git = "https://github.com/getsentry/watto", rev = "d71c8218506bddba102a124a460d64da25e303dc", features = ["strings"] }
|
jsonpath_lib_polars_vendor = "0.0.1"
|
||||||
|
watto = { git = "https://github.com/getsentry/watto", rev = "39ccb9add289c1f23c89f40506f4a80b2f4011b9", features = ["strings"] }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
trybuild = "1"
|
||||||
|
|
||||||
|
[target.'cfg(not(target_env = "msvc"))'.dependencies]
|
||||||
|
tikv-jemallocator = "0.6.0"
|
||||||
|
|||||||
@@ -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";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
the `rust-toolchain` directory will be globbed,
|
||||||
|
and should not lead to any errors down the road
|
||||||
@@ -1,3 +1,10 @@
|
|||||||
|
#[cfg(not(target_env = "msvc"))]
|
||||||
|
use tikv_jemallocator::Jemalloc;
|
||||||
|
|
||||||
|
#[cfg(not(target_env = "msvc"))]
|
||||||
|
#[global_allocator]
|
||||||
|
static GLOBAL: Jemalloc = Jemalloc;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello, world!");
|
println!("Hello, world!");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#[test]
|
||||||
|
fn test_trybuild() {
|
||||||
|
let t = trybuild::TestCases::new();
|
||||||
|
t.pass("tests/trybuild/empty_main.rs");
|
||||||
|
t.compile_fail("tests/trybuild/fail_to_compile.rs");
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
fn main() {}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fn main() {
|
||||||
|
"foobar".foobar();
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
error[E0599]: no method named `foobar` found for reference `&'static str` in the current scope
|
||||||
|
--> tests/trybuild/fail_to_compile.rs:2:14
|
||||||
|
|
|
||||||
|
2 | "foobar".foobar();
|
||||||
|
| ^^^^^^ method not found in `&'static str`
|
||||||
Generated
+1135
-443
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,5 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
|
resolver = "2"
|
||||||
members = [
|
members = [
|
||||||
"crates/one",
|
"crates/one",
|
||||||
"crates/two",
|
"crates/two",
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ version = "0.1.0"
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
reqwest = "0.11.0"
|
reqwest = "0.12"
|
||||||
async-std = "1"
|
async-std = "1"
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tracing-futures = "0.2"
|
tracing-futures = "0.2"
|
||||||
|
|||||||
@@ -5,4 +5,4 @@ version = "0.1.0"
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = "3"
|
clap = "4"
|
||||||
|
|||||||
+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