Skip to content

Commit 7940692

Browse files
committed
CI: cache electrs
1 parent a1ae023 commit 7940692

1 file changed

Lines changed: 68 additions & 38 deletions

File tree

.github/workflows/check_lint_build.yaml

Lines changed: 68 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ name: Check, Lint, Build
2525

2626
env:
2727
CARGO_TERM_COLOR: always
28+
ELECTRS_VERSION: v3.2.0
2829

2930
jobs:
3031
check-lint:
@@ -41,11 +42,23 @@ jobs:
4142
toolchain: nightly
4243
components: rustfmt, clippy
4344

44-
- name: Rust Cache
45+
- name: Restore Rust cache
46+
id: restore-rust-cache
47+
uses: Swatinem/rust-cache@v2.9.1
48+
with:
49+
cache-all-crates: "true"
50+
prefix-key: "v0-rust-nightly"
51+
save-if: "false"
52+
shared-key: debug-x86_64-unknown-linux-gnu
53+
54+
- name: Save Rust cache
55+
if: steps.restore-rust-cache.outputs.cache-hit != 'true'
4556
uses: Swatinem/rust-cache@v2.9.1
4657
with:
47-
cache-bin: false
48-
shared-key: x86_64-unknown-linux-gnu
58+
cache-all-crates: "true"
59+
lookup-only: "true"
60+
prefix-key: "v0-rust-nightly"
61+
shared-key: debug-x86_64-unknown-linux-gnu
4962

5063
- name: Rustfmt
5164
run: cargo fmt --all -- --check
@@ -74,10 +87,38 @@ jobs:
7487
(github.event_name == 'workflow_dispatch' && inputs.cargo_deny_check == 'auto' && (steps.changed-files.outputs.cargo_lock == 'true' || steps.changed-files.outputs.deny_toml == 'true'))
7588
uses: EmbarkStudios/cargo-deny-action@v2
7689

90+
cache-electrs:
91+
name: Build electrs if not cached
92+
runs-on: ubuntu-latest
93+
steps:
94+
- name: Check cache
95+
id: check-cache
96+
uses: actions/cache/restore@v6
97+
with:
98+
lookup-only: true
99+
path: ${{ runner.temp }}/electrs/target/release/electrs
100+
key: electrs-${{ env.ELECTRS_VERSION }}
101+
102+
- name: Build electrs
103+
if: steps.check-cache.outputs.cache-hit != 'true'
104+
run: |
105+
git clone --branch ${{ env.ELECTRS_VERSION }} --depth 1 https://github.com/mempool/electrs.git ${{ runner.temp }}/electrs
106+
pushd ${{ runner.temp }}/electrs
107+
cargo build --locked --release
108+
popd
109+
110+
- name: Save cache
111+
if: steps.check-cache.outputs.cache-hit != 'true'
112+
uses: actions/cache/save@v6
113+
with:
114+
path: ${{ runner.temp }}/electrs/target/release/electrs
115+
key: electrs-${{ env.ELECTRS_VERSION }}
116+
117+
77118
integration-test:
78119
name: Integration test
79120
runs-on: ubuntu-latest
80-
needs: [check-lint]
121+
needs: [cache-electrs, check-lint]
81122
steps:
82123
- name: Download latest bitcoin-patched
83124
run: |
@@ -111,43 +152,31 @@ jobs:
111152
chmod +x bip300301-enforcer
112153
popd
113154
114-
- name: Checkout electrs
115-
run: |
116-
pushd ..
117-
git clone https://github.com/mempool/electrs.git
118-
popd
119-
120-
- name: Install latest nightly toolchain
121-
uses: dtolnay/rust-toolchain@master
122-
with:
123-
toolchain: nightly
124-
target: x86_64-pc-windows-gnu
125-
126-
- name: Rust Cache (electrs)
127-
uses: Swatinem/rust-cache@v2.9.1
155+
- name: Restore electrs from cache
156+
uses: actions/cache/restore@v6
128157
with:
129-
cache-bin: false
130-
prefix-key: "v0-rust-electrs"
131-
workspaces: ../electrs -> target
132-
133-
- name: Install electrs
134-
run: |
135-
pushd ../electrs
136-
cargo build --locked --release
137-
popd
158+
fail-on-cache-miss: true
159+
path: ${{ runner.temp }}/electrs/target/release/electrs
160+
key: electrs-${{ env.ELECTRS_VERSION }}
138161

139162
- uses: actions/checkout@v6
140163
with:
141164
submodules: "recursive"
142165

166+
- name: Install latest nightly toolchain
167+
uses: dtolnay/rust-toolchain@master
168+
with:
169+
toolchain: nightly
170+
143171
- name: Rust Cache
144172
uses: Swatinem/rust-cache@v2.9.1
145173
with:
146-
cache-bin: false
147-
shared-key: x86_64-unknown-linux-gnu
174+
cache-all-crates: "true"
175+
prefix-key: "v0-rust-nightly"
176+
shared-key: debug-x86_64-unknown-linux-gnu
148177

149178
- name: Build (debug)
150-
run: cargo build
179+
run: cargo build --bin thunder_app --example integration_tests
151180

152181
- name: Run integration tests
153182
id: runIntegrationTests
@@ -156,9 +185,9 @@ jobs:
156185
export BITCOIND='../bitcoin-patched-bins/bitcoind'
157186
export BITCOIND_UNPATCHED='../bitcoin-unpatched-bins/bitcoind'
158187
export BITCOIN_CLI='../bitcoin-patched-bins/bitcoin-cli'
159-
export ELECTRS='../electrs/target/release/electrs'
188+
export ELECTRS='${{ runner.temp }}/electrs/target/release/electrs'
160189
export THUNDER_APP='target/debug/thunder_app'
161-
cargo run --example integration_tests
190+
target/debug/examples/integration_tests
162191
163192
test-build-release:
164193
strategy:
@@ -187,6 +216,10 @@ jobs:
187216
contents: write
188217
timeout-minutes: 20
189218
steps:
219+
- name: Install windows-specific deps
220+
run: sudo apt install mingw-w64
221+
if: ${{ matrix.name == 'x86_64-pc-windows-gnu' }}
222+
190223
- uses: actions/checkout@v6
191224
with:
192225
submodules: recursive
@@ -200,12 +233,9 @@ jobs:
200233
- name: Rust Cache
201234
uses: Swatinem/rust-cache@v2.9.1
202235
with:
203-
cache-bin: false
204-
key: ${{ matrix.name }}
205-
206-
- name: Install windows-specific deps
207-
run: sudo apt install mingw-w64
208-
if: ${{ matrix.name == 'x86_64-pc-windows-gnu' }}
236+
cache-all-crates: "true"
237+
prefix-key: "v0-rust-nightly"
238+
shared-key: ${{ matrix.name }}
209239

210240
- name: Test
211241
run: cargo test --tests

0 commit comments

Comments
 (0)