Skip to content

Commit 25399b2

Browse files
Speed up CI: path filtering, sccache, caching, concurrency
- Only build changed projects on push (git diff HEAD~1) - Add sccache compilation cache (GitHub Actions backend) - Add Cargo registry/git caching - Add concurrency groups with cancel-in-progress - Remove nightly cron schedules - Fix token-swap invariant bug (pool_a * pool_a → pool_a * pool_b)
1 parent 2ffa337 commit 25399b2

5 files changed

Lines changed: 138 additions & 14 deletions

File tree

.github/workflows/anchor.yml

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
name: Anchor
22

33
on:
4-
schedule:
5-
- cron: "0 0 * * *"
64
push:
75
branches:
86
- main
@@ -11,6 +9,10 @@ on:
119
branches:
1210
- main
1311

12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
15+
1416
env:
1517
MAX_JOBS: 64
1618
MIN_PROJECTS_PER_JOB: 4
@@ -29,6 +31,8 @@ jobs:
2931
matrix: ${{ steps.matrix.outputs.matrix }}
3032
steps:
3133
- uses: actions/checkout@v5
34+
with:
35+
fetch-depth: 2
3236
- uses: dorny/paths-filter@v4
3337
id: changes
3438
if: github.event_name == 'pull_request'
@@ -51,8 +55,17 @@ jobs:
5155
}
5256
5357
# Determine which projects to build and test
54-
if [[ "${{ github.event_name }}" == "push" || "${{ github.event_name }}" == "schedule" || "${{ steps.changes.outputs.workflow }}" == "true" ]]; then
58+
if [[ "${{ github.event_name }}" == "schedule" || "${{ steps.changes.outputs.workflow }}" == "true" ]]; then
59+
# Workflow file changed or schedule — build everything
5560
projects=$(get_projects)
61+
elif [[ "${{ github.event_name }}" == "push" ]]; then
62+
# On push, only build projects with changes since parent commit
63+
changed_files=$(git diff --name-only HEAD~1 HEAD 2>/dev/null || echo "")
64+
if [ -z "$changed_files" ]; then
65+
projects=$(get_projects)
66+
else
67+
projects=$(echo "$changed_files" | while read file; do dirname "$file" | grep anchor | sed 's#/anchor/.*#/anchor#g'; done | grep -vE "$ignore_pattern" | sort -u)
68+
fi
5669
elif [[ "${{ steps.changes.outputs.anchor }}" == "true" ]]; then
5770
changed_files=(${{ steps.changes.outputs.anchor_files }})
5871
projects=$(for file in "${changed_files[@]}"; do dirname "${file}" | grep anchor | sed 's#/anchor/.*#/anchor#g'; done | grep -vE "$ignore_pattern" | sort -u)
@@ -106,6 +119,21 @@ jobs:
106119
failed_projects: ${{ steps.set-failed.outputs.failed_projects }}
107120
steps:
108121
- uses: actions/checkout@v5
122+
- name: Setup sccache
123+
uses: mozilla-actions/sccache-action@v0.0.9
124+
- name: Configure sccache
125+
run: |
126+
echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV
127+
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
128+
- name: Cache Cargo registry and git
129+
uses: actions/cache@v4
130+
with:
131+
path: |
132+
~/.cargo/registry
133+
~/.cargo/git
134+
key: cargo-${{ runner.os }}-${{ hashFiles('**/Cargo.toml', '**/Cargo.lock') }}
135+
restore-keys: |
136+
cargo-${{ runner.os }}-
109137
- uses: pnpm/action-setup@v4
110138
- uses: heyAyushh/setup-anchor@v4.999
111139
with:
@@ -164,7 +192,7 @@ jobs:
164192
if ! anchor build; then
165193
echo "::error::anchor build failed for $project"
166194
echo "$project: anchor build failed" >> $GITHUB_WORKSPACE/failed_projects.txt
167-
rm -rf target
195+
rm -rf target node_modules
168196
cd - > /dev/null
169197
return 1
170198
fi
@@ -224,6 +252,9 @@ jobs:
224252
# Prepare failed projects list for output
225253
failed_projects=$(cat $GITHUB_WORKSPACE/failed_projects.txt | jq -R -s -c 'split("\n")[:-1]')
226254
echo "failed_projects=$failed_projects" >> $GITHUB_OUTPUT
255+
- name: Show sccache stats
256+
if: always()
257+
run: sccache --show-stats
227258

228259
summary:
229260
needs: [changes, build-and-test]

.github/workflows/native.yml

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
name: Native
22

33
on:
4-
schedule:
5-
- cron: "0 0 * * *"
64
push:
75
branches:
86
- main
@@ -11,6 +9,10 @@ on:
119
branches:
1210
- main
1311

12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
15+
1416
env:
1517
MAX_JOBS: 64
1618
MIN_PROJECTS_PER_JOB: 4
@@ -29,6 +31,8 @@ jobs:
2931
matrix: ${{ steps.matrix.outputs.matrix }}
3032
steps:
3133
- uses: actions/checkout@v5
34+
with:
35+
fetch-depth: 2
3236
- uses: dorny/paths-filter@v4
3337
id: changes
3438
if: github.event_name == 'pull_request'
@@ -51,8 +55,17 @@ jobs:
5155
}
5256
5357
# Determine which projects to build and test
54-
if [[ "${{ github.event_name }}" == "push" || "${{ github.event_name }}" == "schedule" || "${{ steps.changes.outputs.workflow }}" == "true" ]]; then
58+
if [[ "${{ github.event_name }}" == "schedule" || "${{ steps.changes.outputs.workflow }}" == "true" ]]; then
59+
# Workflow file changed or schedule — build everything
5560
projects=$(get_projects)
61+
elif [[ "${{ github.event_name }}" == "push" ]]; then
62+
# On push, only build projects with changes since parent commit
63+
changed_files=$(git diff --name-only HEAD~1 HEAD 2>/dev/null || echo "")
64+
if [ -z "$changed_files" ]; then
65+
projects=$(get_projects)
66+
else
67+
projects=$(echo "$changed_files" | while read file; do dirname "$file" | grep native | sed 's#/native/.*#/native#g'; done | grep -vE "$ignore_pattern" | sort -u)
68+
fi
5669
elif [[ "${{ steps.changes.outputs.native }}" == "true" ]]; then
5770
changed_files=(${{ steps.changes.outputs.native_files }})
5871
projects=$(for file in "${changed_files[@]}"; do dirname "${file}" | grep native | sed 's#/native/.*#/native#g'; done | grep -vE "$ignore_pattern" | sort -u)
@@ -105,6 +118,21 @@ jobs:
105118
failed_projects: ${{ steps.set-failed.outputs.failed_projects }}
106119
steps:
107120
- uses: actions/checkout@v5
121+
- name: Setup sccache
122+
uses: mozilla-actions/sccache-action@v0.0.9
123+
- name: Configure sccache
124+
run: |
125+
echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV
126+
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
127+
- name: Cache Cargo registry and git
128+
uses: actions/cache@v4
129+
with:
130+
path: |
131+
~/.cargo/registry
132+
~/.cargo/git
133+
key: cargo-${{ runner.os }}-${{ hashFiles('**/Cargo.toml', '**/Cargo.lock') }}
134+
restore-keys: |
135+
cargo-${{ runner.os }}-
108136
- uses: pnpm/action-setup@v4
109137
- name: Use Node.js
110138
uses: actions/setup-node@v5
@@ -227,6 +255,9 @@ jobs:
227255
else
228256
echo "failed_projects=[]" >> $GITHUB_OUTPUT
229257
fi
258+
- name: Show sccache stats
259+
if: always()
260+
run: sccache --show-stats
230261

231262
summary:
232263
needs: [changes, build-and-test]

.github/workflows/pinocchio.yml

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
name: Pinocchio
22

33
on:
4-
schedule:
5-
- cron: "0 0 * * *"
64
push:
75
branches:
86
- main
@@ -11,6 +9,10 @@ on:
119
branches:
1210
- main
1311

12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
15+
1416
env:
1517
MAX_JOBS: 64
1618
MIN_PROJECTS_PER_JOB: 4
@@ -29,6 +31,8 @@ jobs:
2931
matrix: ${{ steps.matrix.outputs.matrix }}
3032
steps:
3133
- uses: actions/checkout@v5
34+
with:
35+
fetch-depth: 2
3236
- uses: dorny/paths-filter@v4
3337
id: changes
3438
if: github.event_name == 'pull_request'
@@ -51,8 +55,17 @@ jobs:
5155
}
5256
5357
# Determine which projects to build and test
54-
if [[ "${{ github.event_name }}" == "push" || "${{ github.event_name }}" == "schedule" || "${{ steps.changes.outputs.workflow }}" == "true" ]]; then
58+
if [[ "${{ github.event_name }}" == "schedule" || "${{ steps.changes.outputs.workflow }}" == "true" ]]; then
59+
# Workflow file changed or schedule — build everything
5560
projects=$(get_projects)
61+
elif [[ "${{ github.event_name }}" == "push" ]]; then
62+
# On push, only build projects with changes since parent commit
63+
changed_files=$(git diff --name-only HEAD~1 HEAD 2>/dev/null || echo "")
64+
if [ -z "$changed_files" ]; then
65+
projects=$(get_projects)
66+
else
67+
projects=$(echo "$changed_files" | while read file; do dirname "$file" | grep pinocchio | sed 's#/pinocchio/.*#/pinocchio#g'; done | grep -vE "$ignore_pattern" | sort -u)
68+
fi
5669
elif [[ "${{ steps.changes.outputs.pinocchio }}" == "true" ]]; then
5770
changed_files=(${{ steps.changes.outputs.pinocchio_files }})
5871
projects=$(for file in "${changed_files[@]}"; do dirname "${file}" | grep pinocchio | sed 's#/pinocchio/.*#/pinocchio#g'; done | grep -vE "$ignore_pattern" | sort -u)
@@ -105,6 +118,21 @@ jobs:
105118
failed_projects: ${{ steps.set-failed.outputs.failed_projects }}
106119
steps:
107120
- uses: actions/checkout@v5
121+
- name: Setup sccache
122+
uses: mozilla-actions/sccache-action@v0.0.9
123+
- name: Configure sccache
124+
run: |
125+
echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV
126+
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
127+
- name: Cache Cargo registry and git
128+
uses: actions/cache@v4
129+
with:
130+
path: |
131+
~/.cargo/registry
132+
~/.cargo/git
133+
key: cargo-${{ runner.os }}-${{ hashFiles('**/Cargo.toml', '**/Cargo.lock') }}
134+
restore-keys: |
135+
cargo-${{ runner.os }}-
108136
- uses: pnpm/action-setup@v4
109137
- name: Use Node.js
110138
uses: actions/setup-node@v5
@@ -227,6 +255,9 @@ jobs:
227255
else
228256
echo "failed_projects=[]" >> $GITHUB_OUTPUT
229257
fi
258+
- name: Show sccache stats
259+
if: always()
260+
run: sccache --show-stats
230261

231262
summary:
232263
needs: [changes, build-and-test]

.github/workflows/quasar.yml

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
name: Quasar
22

33
on:
4-
schedule:
5-
- cron: "0 0 * * *"
64
push:
75
branches:
86
- main
@@ -11,6 +9,10 @@ on:
119
branches:
1210
- main
1311

12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
15+
1416
env:
1517
MAX_JOBS: 64
1618
MIN_PROJECTS_PER_JOB: 4
@@ -31,6 +33,8 @@ jobs:
3133
matrix: ${{ steps.matrix.outputs.matrix }}
3234
steps:
3335
- uses: actions/checkout@v5
36+
with:
37+
fetch-depth: 2
3438
- uses: dorny/paths-filter@v4
3539
id: changes
3640
if: github.event_name == 'pull_request'
@@ -53,8 +57,17 @@ jobs:
5357
}
5458
5559
# Determine which projects to build and test
56-
if [[ "${{ github.event_name }}" == "push" || "${{ github.event_name }}" == "schedule" || "${{ steps.changes.outputs.workflow }}" == "true" ]]; then
60+
if [[ "${{ github.event_name }}" == "schedule" || "${{ steps.changes.outputs.workflow }}" == "true" ]]; then
61+
# Workflow file changed or schedule — build everything
5762
projects=$(get_projects)
63+
elif [[ "${{ github.event_name }}" == "push" ]]; then
64+
# On push, only build projects with changes since parent commit
65+
changed_files=$(git diff --name-only HEAD~1 HEAD 2>/dev/null || echo "")
66+
if [ -z "$changed_files" ]; then
67+
projects=$(get_projects)
68+
else
69+
projects=$(echo "$changed_files" | while read file; do dirname "$file" | grep quasar | sed 's#/quasar/.*#/quasar#g'; done | grep -vE "$ignore_pattern" | sort -u)
70+
fi
5871
elif [[ "${{ steps.changes.outputs.quasar }}" == "true" ]]; then
5972
changed_files=(${{ steps.changes.outputs.quasar_files }})
6073
projects=$(for file in "${changed_files[@]}"; do dirname "${file}" | grep quasar | sed 's#/quasar/.*#/quasar#g'; done | grep -vE "$ignore_pattern" | sort -u)
@@ -107,6 +120,21 @@ jobs:
107120
failed_projects: ${{ steps.set-failed.outputs.failed_projects }}
108121
steps:
109122
- uses: actions/checkout@v5
123+
- name: Setup sccache
124+
uses: mozilla-actions/sccache-action@v0.0.9
125+
- name: Configure sccache
126+
run: |
127+
echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV
128+
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
129+
- name: Cache Cargo registry and git
130+
uses: actions/cache@v4
131+
with:
132+
path: |
133+
~/.cargo/registry
134+
~/.cargo/git
135+
key: cargo-${{ runner.os }}-${{ hashFiles('**/Cargo.toml', '**/Cargo.lock') }}
136+
restore-keys: |
137+
cargo-${{ runner.os }}-
110138
- name: Setup build environment
111139
id: setup
112140
run: |
@@ -190,6 +218,9 @@ jobs:
190218
else
191219
echo "failed_projects=[]" >> $GITHUB_OUTPUT
192220
fi
221+
- name: Show sccache stats
222+
if: always()
223+
run: sccache --show-stats
193224

194225
summary:
195226
needs: [changes, build-and-test]

tokens/token-swap/anchor/programs/token-swap/src/instructions/swap_exact_tokens_for_tokens.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub fn handle_swap_exact_tokens_for_tokens(
134134
// We tolerate if the new invariant is higher because it means a rounding error for LPs
135135
context.accounts.pool_account_a.reload()?;
136136
context.accounts.pool_account_b.reload()?;
137-
if invariant > context.accounts.pool_account_a.amount * context.accounts.pool_account_a.amount {
137+
if invariant > context.accounts.pool_account_a.amount * context.accounts.pool_account_b.amount {
138138
return err!(TutorialError::InvariantViolated);
139139
}
140140

0 commit comments

Comments
 (0)