Skip to content

Commit 8e54574

Browse files
authored
cache, check and short-circuit on reused last-tested-commit in namespace cache volumes (#5074)
This should (if we get our cache volume hit rate to anything reasonable) prevent double-executions (where we run once on the merge queue and then _immediately again_ once master advances to the merge queue commit) from happening on the majority of our runners. I also merged the miscellaneous static checks into a single job to cut down on the number of parallel instances and caches we populate. sequential execution of these checks will be fine -- they all run quickly anyways and are dominated by instance setup time.
2 parents e42f884 + b5a6748 commit 8e54574

File tree

1 file changed

+108
-39
lines changed

1 file changed

+108
-39
lines changed

.github/workflows/build.yml

Lines changed: 108 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,60 +18,85 @@ jobs:
1818

1919
complete:
2020
if: always()
21-
needs: [fmt, cargo-deny, rust-check-git-rev-deps, build-linux, build-mac]
21+
needs: [static-checks, build-linux, build-mac]
2222
runs-on:
2323
- namespace-profile-noble-24-04-stellar-core-x64-small
24-
- nscloud-cache-exp-do-not-commit
2524
steps:
2625
- if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
2726
run: exit 1
2827

29-
fmt:
28+
static-checks:
3029
runs-on:
31-
- namespace-profile-noble-24-04-stellar-core-x64-small
32-
- nscloud-cache-exp-do-not-commit
30+
- namespace-profile-noble-24-04-stellar-core-x64-small;overrides.cache-tag=config-static-checks
3331
steps:
3432
- uses: namespacelabs/nscloud-checkout-action@v7
3533
with:
3634
fetch-depth: 1
3735
submodules: recursive
38-
- run: rustup component add rustfmt
39-
- run: rustup update
40-
- run: cargo fmt --all --check
4136

42-
cargo-deny:
43-
runs-on:
44-
- namespace-profile-noble-24-04-stellar-core-x64-small
45-
- nscloud-cache-exp-do-not-commit
46-
strategy:
47-
matrix:
48-
checks:
49-
- advisories
50-
- bans licenses sources
51-
# Prevent sudden announcement of a new advisory from failing ci:
52-
continue-on-error: ${{ matrix.checks == 'advisories' }}
53-
steps:
54-
- uses: namespacelabs/nscloud-checkout-action@v7
37+
- name: Configure Namespace cache volume
38+
uses: namespacelabs/nscloud-cache-action@v1
5539
with:
56-
fetch-depth: 1
57-
submodules: recursive
58-
- uses: EmbarkStudios/cargo-deny-action@8d73959fce1cdc8989f23fdf03bec6ae6a6576ef
40+
path: |
41+
~/.cargo
42+
build-static-checks
43+
44+
- name: Check if commit already tested
45+
id: check-last-tested-commit
46+
run: |
47+
LAST_TESTED_COMMIT_SHA_FILE="build-static-checks/.last-tested-commit-sha"
48+
if [ -f "$LAST_TESTED_COMMIT_SHA_FILE" ] && [ "$(cat "$LAST_TESTED_COMMIT_SHA_FILE")" = "${{ github.sha }}" ]; then
49+
echo "Commit ${{ github.sha }} already tested successfully, skipping build"
50+
echo "skip=true" >> $GITHUB_OUTPUT
51+
else
52+
echo "skip=false" >> $GITHUB_OUTPUT
53+
fi
54+
55+
- name: Install rustup
56+
if: steps.check-last-tested-commit.outputs.skip != 'true'
57+
run: ./install-rust.sh
58+
59+
- name: Update rustup
60+
if: steps.check-last-tested-commit.outputs.skip != 'true'
61+
run: rustup update
62+
63+
- name: Install rustfmt
64+
if: steps.check-last-tested-commit.outputs.skip != 'true'
65+
run: rustup component add rustfmt
66+
67+
- name: Check git rev deps
68+
if: steps.check-last-tested-commit.outputs.skip != 'true'
69+
uses: stellar/actions/rust-check-git-rev-deps@main
70+
71+
- name: Check formatting
72+
if: steps.check-last-tested-commit.outputs.skip != 'true'
73+
run: cargo fmt --all --check
74+
75+
- name: Check cargo-deny advisories
76+
if: steps.check-last-tested-commit.outputs.skip != 'true'
77+
# Prevent sudden announcement of a new advisory from failing ci:
78+
continue-on-error: true
79+
uses: EmbarkStudios/cargo-deny-action@8d73959fce1cdc8989f23fdf03bec6ae6a6576ef
5980
with:
60-
command: check ${{ matrix.checks }}
81+
command: check advisories
6182
# leave arguments empty so we don't test --all-features
6283
# which will see conflicting env versions
6384
arguments:
6485

65-
rust-check-git-rev-deps:
66-
runs-on:
67-
- namespace-profile-noble-24-04-stellar-core-x64-small
68-
- nscloud-cache-exp-do-not-commit
69-
steps:
70-
- uses: namespacelabs/nscloud-checkout-action@v7
86+
- name: Check cargo-deny bans licenses sources
87+
if: steps.check-last-tested-commit.outputs.skip != 'true'
88+
uses: EmbarkStudios/cargo-deny-action@8d73959fce1cdc8989f23fdf03bec6ae6a6576ef
7189
with:
72-
fetch-depth: 1
73-
submodules: recursive
74-
- uses: stellar/actions/rust-check-git-rev-deps@main
90+
command: check bans licenses sources
91+
# leave arguments empty so we don't test --all-features
92+
# which will see conflicting env versions
93+
arguments:
94+
95+
- name: Record successful test commit
96+
if: ${{ success() && steps.check-last-tested-commit.outputs.skip != 'true' }}
97+
run: |
98+
mkdir -p build-static-checks
99+
echo "${{ github.sha }}" > "build-static-checks/.last-tested-commit-sha"
75100
76101
build-linux:
77102
runs-on:
@@ -83,7 +108,7 @@ jobs:
83108
protocol: ["current", "next"]
84109
steps:
85110
- name: Fix kernel mmap rnd bits
86-
# Asan in llvm provided in some ubuntus is incompatible with
111+
# Asan in llvm provided in some ubuntu versions is incompatible with
87112
# high-entropy ASLR in much newer kernels that GitHub runners are
88113
# using leading to random crashes: https://reviews.llvm.org/D148280
89114
run: sudo sysctl vm.mmap_rnd_bits=28
@@ -101,25 +126,41 @@ jobs:
101126
~/.cargo
102127
build-${{matrix.toolchain}}-${{matrix.protocol}}
103128
104-
- name: install rustup
129+
- name: Check if commit already tested
130+
id: check-last-tested-commit
131+
run: |
132+
LAST_TESTED_COMMIT_SHA_FILE="build-${{matrix.toolchain}}-${{matrix.protocol}}/.last-tested-commit-sha"
133+
if [ -f "$LAST_TESTED_COMMIT_SHA_FILE" ] && [ "$(cat "$LAST_TESTED_COMMIT_SHA_FILE")" = "${{ github.sha }}" ]; then
134+
echo "Commit ${{ github.sha }} already tested successfully, skipping build"
135+
echo "skip=true" >> $GITHUB_OUTPUT
136+
else
137+
echo "skip=false" >> $GITHUB_OUTPUT
138+
fi
139+
140+
- name: Install rustup
141+
if: steps.check-last-tested-commit.outputs.skip != 'true'
105142
run: ./install-rust.sh
106143

107-
- name: install rustup components
144+
- name: Install rustup components
145+
if: steps.check-last-tested-commit.outputs.skip != 'true'
108146
run: rustup component add rustfmt
109147

110148
- uses: stellar/binaries@v50
149+
if: steps.check-last-tested-commit.outputs.skip != 'true'
111150
with:
112151
name: cargo-cache
113152
version: 0.8.3
114153

115154
- uses: stellar/binaries@v50
155+
if: steps.check-last-tested-commit.outputs.skip != 'true'
116156
with:
117157
name: cargo-sweep
118158
version: 0.7.0
119159

120160
# Restore original modification time of files based on the date of the most
121161
# recent commit that modified them as mtimes affect the Go test cache.
122162
- name: Restore modification time of checkout files
163+
if: steps.check-last-tested-commit.outputs.skip != 'true'
123164
shell: bash
124165
run: |
125166
# Set a base, fixed modification time of all directories.
@@ -135,6 +176,7 @@ jobs:
135176
git restore-mtime
136177
137178
- name: Build
179+
if: steps.check-last-tested-commit.outputs.skip != 'true'
138180
run: |
139181
if test "${{ matrix.toolchain }}" = "gcc" ; then
140182
export CC='gcc'
@@ -146,6 +188,11 @@ jobs:
146188
echo Build with $CC and $CXX
147189
./ci-build.sh --use-temp-db --protocol ${{ matrix.protocol }}
148190
191+
- name: Record successful test commit
192+
if: ${{ success() && steps.check-last-tested-commit.outputs.skip != 'true' }}
193+
run: |
194+
echo "${{ github.sha }}" > "build-${{matrix.toolchain}}-${{matrix.protocol}}/.last-tested-commit-sha"
195+
149196
build-mac:
150197
runs-on:
151198
- namespace-profile-macos-sequoia;overrides.cache-tag=config-macos-sequoia
@@ -164,30 +211,46 @@ jobs:
164211
~/.cargo
165212
build-clang-current
166213
167-
- name: install prerequisites and uninstall brew rust, add rustup
214+
- name: Check if commit already tested
215+
id: check-last-tested-commit
216+
run: |
217+
LAST_TESTED_COMMIT_SHA_FILE="build-clang-current/.last-tested-commit-sha"
218+
if [ -f "$LAST_TESTED_COMMIT_SHA_FILE" ] && [ "$(cat "$LAST_TESTED_COMMIT_SHA_FILE")" = "${{ github.sha }}" ]; then
219+
echo "Commit ${{ github.sha }} already tested successfully, skipping build"
220+
echo "skip=true" >> $GITHUB_OUTPUT
221+
else
222+
echo "skip=false" >> $GITHUB_OUTPUT
223+
fi
224+
225+
- name: Install prerequisites and uninstall brew rust, add rustup
226+
if: steps.check-last-tested-commit.outputs.skip != 'true'
168227
run: |
169228
brew install libsodium libtool autoconf automake pkg-config libpq openssl parallel ccache bison gnu-sed perl coreutils
170229
brew uninstall rust rustup
171230
brew install rustup
172231
173-
- name: install rustup components
232+
- name: Install rustup components
233+
if: steps.check-last-tested-commit.outputs.skip != 'true'
174234
run: |
175235
rustup-init -y
176236
rustup component add rustfmt rustc cargo clippy rust-src rust-std
177237
178238
- uses: stellar/binaries@v50
239+
if: steps.check-last-tested-commit.outputs.skip != 'true'
179240
with:
180241
name: cargo-cache
181242
version: 0.8.3
182243

183244
- uses: stellar/binaries@v50
245+
if: steps.check-last-tested-commit.outputs.skip != 'true'
184246
with:
185247
name: cargo-sweep
186248
version: 0.7.0
187249

188250
# Restore original modification time of files based on the date of the most
189251
# recent commit that modified them as mtimes affect the Go test cache.
190252
- name: Restore modification time of checkout files
253+
if: steps.check-last-tested-commit.outputs.skip != 'true'
191254
shell: bash
192255
run: |
193256
# Set a base, fixed modification time of all directories.
@@ -201,6 +264,7 @@ jobs:
201264
git restore-mtime
202265
203266
- name: Build
267+
if: steps.check-last-tested-commit.outputs.skip != 'true'
204268
run: |
205269
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$(brew --prefix)/opt/libpq/lib/pkgconfig"
206270
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$(brew --prefix)/opt/openssl@3/lib/pkgconfig"
@@ -210,3 +274,8 @@ jobs:
210274
export CLANG_VERSION=none
211275
export SKIP_FORMAT_CHECK=1
212276
./ci-build.sh --disable-postgres --protocol current
277+
278+
- name: Record successful test commit
279+
if: ${{ success() && steps.check-last-tested-commit.outputs.skip != 'true' }}
280+
run: |
281+
echo "${{ github.sha }}" > "build-clang-current/.last-tested-commit-sha"

0 commit comments

Comments
 (0)