Skip to content

Commit 1ef2cbe

Browse files
ci: add Cargo registry/git caching and keep target/ between projects
Add actions/cache@v4 for ~/.cargo/registry and ~/.cargo/git to all 4 matrix CI workflows (anchor, native, pinocchio, quasar). Cache key uses Cargo.toml/Cargo.lock hashes with OS-based restore-keys fallback. Also stop deleting target/ between project builds in anchor.yml — the shared dependencies (anchor-lang, solana-program, etc.) only need to compile once. node_modules cleanup is kept since each project has its own JS deps.
1 parent c79fac5 commit 1ef2cbe

4 files changed

Lines changed: 38 additions & 3 deletions

File tree

.github/workflows/anchor.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ jobs:
108108
failed_projects: ${{ steps.set-failed.outputs.failed_projects }}
109109
steps:
110110
- uses: actions/checkout@v5
111+
- name: Cache Cargo registry and git
112+
uses: actions/cache@v4
113+
with:
114+
path: |
115+
~/.cargo/registry
116+
~/.cargo/git
117+
key: cargo-${{ runner.os }}-${{ hashFiles('**/Cargo.toml', '**/Cargo.lock') }}
118+
restore-keys: |
119+
cargo-${{ runner.os }}-
111120
- uses: pnpm/action-setup@v4
112121
- uses: heyAyushh/setup-anchor@v4.999
113122
with:
@@ -166,7 +175,6 @@ jobs:
166175
if ! anchor build; then
167176
echo "::error::anchor build failed for $project"
168177
echo "$project: anchor build failed" >> $GITHUB_WORKSPACE/failed_projects.txt
169-
rm -rf target
170178
cd - > /dev/null
171179
return 1
172180
fi
@@ -175,13 +183,13 @@ jobs:
175183
if ! anchor test; then
176184
echo "::error::anchor test failed for $project"
177185
echo "$project: anchor test failed" >> $GITHUB_WORKSPACE/failed_projects.txt
178-
rm -rf target node_modules
186+
rm -rf node_modules
179187
cd - > /dev/null
180188
return 1
181189
fi
182190
183191
echo "Build and tests succeeded for $project."
184-
rm -rf target node_modules
192+
rm -rf node_modules
185193
cd - > /dev/null
186194
return 0
187195
}

.github/workflows/native.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ jobs:
107107
failed_projects: ${{ steps.set-failed.outputs.failed_projects }}
108108
steps:
109109
- uses: actions/checkout@v5
110+
- name: Cache Cargo registry and git
111+
uses: actions/cache@v4
112+
with:
113+
path: |
114+
~/.cargo/registry
115+
~/.cargo/git
116+
key: cargo-${{ runner.os }}-${{ hashFiles('**/Cargo.toml', '**/Cargo.lock') }}
117+
restore-keys: |
118+
cargo-${{ runner.os }}-
110119
- uses: pnpm/action-setup@v4
111120
- name: Use Node.js
112121
uses: actions/setup-node@v5

.github/workflows/pinocchio.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ jobs:
107107
failed_projects: ${{ steps.set-failed.outputs.failed_projects }}
108108
steps:
109109
- uses: actions/checkout@v5
110+
- name: Cache Cargo registry and git
111+
uses: actions/cache@v4
112+
with:
113+
path: |
114+
~/.cargo/registry
115+
~/.cargo/git
116+
key: cargo-${{ runner.os }}-${{ hashFiles('**/Cargo.toml', '**/Cargo.lock') }}
117+
restore-keys: |
118+
cargo-${{ runner.os }}-
110119
- uses: pnpm/action-setup@v4
111120
- name: Use Node.js
112121
uses: actions/setup-node@v5

.github/workflows/quasar.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ jobs:
109109
failed_projects: ${{ steps.set-failed.outputs.failed_projects }}
110110
steps:
111111
- uses: actions/checkout@v5
112+
- name: Cache Cargo registry and git
113+
uses: actions/cache@v4
114+
with:
115+
path: |
116+
~/.cargo/registry
117+
~/.cargo/git
118+
key: cargo-${{ runner.os }}-${{ hashFiles('**/Cargo.toml', '**/Cargo.lock') }}
119+
restore-keys: |
120+
cargo-${{ runner.os }}-
112121
- name: Setup build environment
113122
id: setup
114123
run: |

0 commit comments

Comments
 (0)