-
Notifications
You must be signed in to change notification settings - Fork 1.9k
231 lines (206 loc) · 8.6 KB
/
Copy pathtemplate-tests.yaml
File metadata and controls
231 lines (206 loc) · 8.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
name: Template Tests
on:
push:
branches:
- anchor-next
paths-ignore:
- "docs/**"
pull_request:
paths-ignore:
- "docs/**"
workflow_dispatch:
env:
SOLANA_VERSION: "3.1.10"
NODE_VERSION: "20"
SURFPOOL_CLI_VERSION: "1.2.0"
jobs:
# Build CLI once to share across test jobs
build-cli:
name: Build CLI
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup/
- uses: actions/cache@v4
name: Cache Cargo home
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: cargo-home-${{ runner.os }}-template-${{ hashFiles('**/Cargo.lock') }}
restore-keys: cargo-home-${{ runner.os }}-template-
- uses: actions/cache@v4
name: Cache cargo target
with:
path: ./target/
key: cargo-target-template-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: cargo-target-template-${{ runner.os }}-
- run: cargo install --path cli --locked --debug --force --target-dir ./target
- uses: actions/upload-artifact@v4
with:
name: anchor-cli
path: ~/.cargo/bin/anchor
retention-days: 1
if-no-files-found: error
# Rust-only test templates: `--javascript` and `--package-manager` don't
# apply, so the matrix is just template × test-template (2 × 3 = 6 cells).
template-rust-tests:
name: ${{ matrix.template }} + ${{ matrix.test_template }}
needs: build-cli
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
template: [single, multiple]
test_template: [rust, mollusk, litesvm]
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup/
- uses: ./.github/actions/setup-solana/
- uses: ./.github/actions/setup-surfpool/
- uses: actions/download-artifact@v4
with:
name: anchor-cli
path: ~/.cargo/bin/
- run: chmod +x ~/.cargo/bin/anchor
# Match `tests-v2/src/lib.rs::build_program`. Pre-install so concurrent
# `cargo build-sbf` invocations don't race on the platform-tools rename.
- run: cargo build-sbf --tools-version v1.52 --install-only
# Cache the generated project's `target/` so subsequent runs reuse
# compiled deps. Restored before `anchor init` (which is invoked with
# `--force`, leaving `target/` intact); the deps don't depend on the
# template-files diff, so a partial restore from a prior commit is
# always a hit. Per-cell key avoids cross-pollination — different
# test templates pull different dev-deps.
- uses: actions/cache@v4
with:
path: /tmp/my_program/target/
key: template-target-${{ runner.os }}-${{ matrix.template }}-${{ matrix.test_template }}-${{ github.sha }}
restore-keys: template-target-${{ runner.os }}-${{ matrix.template }}-${{ matrix.test_template }}-
- name: anchor init
working-directory: /tmp
run: |
mkdir -p my_program
anchor init my_program \
--template ${{ matrix.template }} \
--test-template ${{ matrix.test_template }} \
--no-git \
--no-install \
--force
# Redirect every `git = ".../anchor.git"` dep in the generated
# project to this PR's checkout so PR changes are exercised. Without
# this, `anchor init` resolves anchor-lang-v2 / anchor-client /
# anchor-v2-testing from upstream `anchor-next`, masking any local
# changes. Listed crates that the lockfile doesn't reference are
# silently ignored (Cargo emits a warning, not an error). The rust
# test template has its own non-workspace `tests/Cargo.toml`, so
# we patch it separately when present.
- name: Patch generated project to use PR checkout
env:
REPO: ${{ github.workspace }}
run: |
patch_block() {
cat <<EOF >> "$1"
[patch."https://github.com/solana-foundation/anchor.git"]
anchor-lang-v2 = { path = "$REPO/lang-v2" }
anchor-derive-accounts-v2 = { path = "$REPO/lang-v2/derive" }
anchor-client = { path = "$REPO/client" }
anchor-spl-v2 = { path = "$REPO/spl-v2" }
anchor-v2-testing = { path = "$REPO/v2-testing" }
EOF
}
patch_block /tmp/my_program/Cargo.toml
if [ -f /tmp/my_program/tests/Cargo.toml ]; then
patch_block /tmp/my_program/tests/Cargo.toml
fi
- name: anchor test
working-directory: /tmp/my_program
run: anchor test
# JS-based test templates: cross-product over template × language ×
# package manager (2 × 2 × 2 × 4 = 32 cells).
template-js-tests:
name: ${{ matrix.template }} + ${{ matrix.test_template }} + ${{ matrix.language }} + ${{ matrix.package_manager }}
needs: build-cli
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
template: [single, multiple]
test_template: [mocha, jest]
language: [typescript, javascript]
package_manager: [npm, yarn, pnpm, bun]
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup/
- uses: ./.github/actions/setup-solana/
- uses: ./.github/actions/setup-surfpool/
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
# Each PM gets its own setup. Corepack's shim approach didn't work
# reliably without a `packageManager` field in package.json, and
# ubuntu-latest only ships yarn classic pre-installed.
# - npm: bundled with Node (no setup needed)
# - yarn: pre-installed on ubuntu-latest as yarn classic
# - pnpm: pnpm/action-setup adds the binary to PATH
# - bun: oven-sh/setup-bun does the same
- if: matrix.package_manager == 'pnpm'
uses: pnpm/action-setup@v4
with:
version: 10
- if: matrix.package_manager == 'bun'
uses: oven-sh/setup-bun@v2
- uses: actions/download-artifact@v4
with:
name: anchor-cli
path: ~/.cargo/bin/
- run: chmod +x ~/.cargo/bin/anchor
- run: cargo build-sbf --tools-version v1.52 --install-only
# Cache cargo `target/` and `node_modules/` for the generated project.
# `anchor init --force` leaves both alone, so the dirs survive a fresh
# init. Caching keys are per-cell so e.g. `mocha+ts+npm` doesn't pull
# `jest+js+pnpm`'s lockfile artifacts. `restore-keys` lets a stale
# commit's cache hit when the SHA-suffixed primary key misses.
- uses: actions/cache@v4
with:
path: /tmp/my_program/target/
key: template-target-${{ runner.os }}-${{ matrix.template }}-${{ matrix.test_template }}-${{ github.sha }}
restore-keys: template-target-${{ runner.os }}-${{ matrix.template }}-${{ matrix.test_template }}-
- uses: actions/cache@v4
with:
path: /tmp/my_program/node_modules/
key: template-nm-${{ runner.os }}-${{ matrix.test_template }}-${{ matrix.language }}-${{ matrix.package_manager }}-${{ github.sha }}
restore-keys: template-nm-${{ runner.os }}-${{ matrix.test_template }}-${{ matrix.language }}-${{ matrix.package_manager }}-
- name: anchor init
working-directory: /tmp
run: |
mkdir -p my_program
anchor init my_program \
--template ${{ matrix.template }} \
--test-template ${{ matrix.test_template }} \
--package-manager ${{ matrix.package_manager }} \
${{ matrix.language == 'javascript' && '--javascript' || '' }} \
--no-git \
--force
# Redirect git deps to this PR's checkout. See the rust matrix above
# for the rationale; JS templates only carry git deps through the
# program crate (no separate `tests/Cargo.toml`).
- name: Patch generated project to use PR checkout
env:
REPO: ${{ github.workspace }}
run: |
cat <<EOF >> /tmp/my_program/Cargo.toml
[patch."https://github.com/solana-foundation/anchor.git"]
anchor-lang-v2 = { path = "$REPO/lang-v2" }
anchor-derive-accounts-v2 = { path = "$REPO/lang-v2/derive" }
anchor-client = { path = "$REPO/client" }
anchor-spl-v2 = { path = "$REPO/spl-v2" }
anchor-v2-testing = { path = "$REPO/v2-testing" }
EOF
- name: anchor test
working-directory: /tmp/my_program
run: anchor test