Skip to content

Commit e2c4903

Browse files
authored
Merge pull request #171 from paritytech/ci/share-codegen-artifact
ci: share codegen output across jobs via artifact
2 parents ed26641 + a9bd558 commit e2c4903

3 files changed

Lines changed: 60 additions & 27 deletions

File tree

.github/workflows/ci.yml

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,29 @@ jobs:
6464
- name: Run codegen
6565
run: ./scripts/codegen.sh
6666

67+
- name: Upload codegen output
68+
uses: actions/upload-artifact@v4
69+
with:
70+
name: codegen-output
71+
if-no-files-found: error
72+
retention-days: 1
73+
path: |
74+
js/packages/truapi/src/generated
75+
js/packages/truapi/src/playground/codegen
76+
js/packages/truapi/src/explorer/codegen
77+
js/packages/truapi/src/explorer/versions.ts
78+
js/packages/truapi-host/src/generated
79+
playground/test/generated
80+
6781
ts-client:
6882
name: '@parity/truapi'
6983
runs-on: ubuntu-latest
84+
needs: codegen
85+
env:
86+
TRUAPI_REQUIRE_GENERATED: 1
7087
steps:
7188
- uses: actions/checkout@v4
7289

73-
- uses: dtolnay/rust-toolchain@nightly
74-
75-
- uses: dtolnay/rust-toolchain@stable
76-
77-
- uses: Swatinem/rust-cache@v2
78-
7990
- uses: actions/setup-node@v4
8091
with:
8192
node-version: 22
@@ -84,6 +95,11 @@ jobs:
8495
with:
8596
bun-version: latest
8697

98+
- name: Download codegen output
99+
uses: actions/download-artifact@v4
100+
with:
101+
name: codegen-output
102+
87103
- name: Install
88104
run: npm ci
89105

@@ -97,21 +113,22 @@ jobs:
97113
name: Playground (build + lint)
98114
runs-on: ubuntu-latest
99115
needs: ts-client
116+
env:
117+
TRUAPI_REQUIRE_GENERATED: 1
100118
steps:
101119
- uses: actions/checkout@v4
102120

103-
- uses: dtolnay/rust-toolchain@nightly
104-
105-
- uses: dtolnay/rust-toolchain@stable
106-
107-
- uses: Swatinem/rust-cache@v2
108-
109121
- uses: actions/setup-node@v4
110122
with:
111123
node-version: 22
112124

125+
- name: Download codegen output
126+
uses: actions/download-artifact@v4
127+
with:
128+
name: codegen-output
129+
113130
- name: Install workspace deps + build @parity/truapi
114-
run: npm ci && ./scripts/codegen.sh
131+
run: npm ci
115132

116133
- name: Install playground deps
117134
working-directory: playground
@@ -137,21 +154,22 @@ jobs:
137154
name: Explorer (build + lint)
138155
runs-on: ubuntu-latest
139156
needs: ts-client
157+
env:
158+
TRUAPI_REQUIRE_GENERATED: 1
140159
steps:
141160
- uses: actions/checkout@v4
142161

143-
- uses: dtolnay/rust-toolchain@nightly
144-
145-
- uses: dtolnay/rust-toolchain@stable
146-
147-
- uses: Swatinem/rust-cache@v2
148-
149162
- uses: actions/setup-node@v4
150163
with:
151164
node-version: 22
152165

166+
- name: Download codegen output
167+
uses: actions/download-artifact@v4
168+
with:
169+
name: codegen-output
170+
153171
- name: Install workspace deps + build @parity/truapi
154-
run: npm ci && ./scripts/codegen.sh
172+
run: npm ci
155173

156174
- name: Install explorer deps
157175
working-directory: explorer
@@ -172,17 +190,13 @@ jobs:
172190
runs-on: ubuntu-latest
173191
needs: playground
174192
timeout-minutes: 30
193+
env:
194+
TRUAPI_REQUIRE_GENERATED: 1
175195
steps:
176196
- uses: actions/checkout@v4
177197
with:
178198
submodules: recursive
179199

180-
- uses: dtolnay/rust-toolchain@nightly
181-
182-
- uses: dtolnay/rust-toolchain@stable
183-
184-
- uses: Swatinem/rust-cache@v2
185-
186200
- uses: actions/setup-node@v4
187201
with:
188202
node-version: 22
@@ -191,8 +205,13 @@ jobs:
191205
with:
192206
bun-version: latest
193207

208+
- name: Download codegen output
209+
uses: actions/download-artifact@v4
210+
with:
211+
name: codegen-output
212+
194213
- name: Build @parity/truapi
195-
run: npm ci && ./scripts/codegen.sh
214+
run: npm ci
196215

197216
- name: Install dotli deps
198217
working-directory: hosts/dotli

js/packages/truapi-host/scripts/ensure-generated.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,11 @@ if [ "$missing" -eq 0 ]; then
2222
exit 0
2323
fi
2424

25+
if [ "${TRUAPI_REQUIRE_GENERATED:-0}" = "1" ]; then
26+
echo "ensure-generated: generated files are missing and TRUAPI_REQUIRE_GENERATED=1, so codegen will not run." >&2
27+
echo "These files are expected to be restored from the 'codegen-output' CI artifact." >&2
28+
echo "If you added a generated output, add its path to the upload-artifact step in .github/workflows/ci.yml." >&2
29+
exit 1
30+
fi
31+
2532
TRUAPI_SKIP_PACKAGE_BUILD=1 ./scripts/codegen.sh

js/packages/truapi/scripts/ensure-generated.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,11 @@ if [ "$missing" -eq 0 ] && find playground/test/generated/examples -name '*.ts'
2626
exit 0
2727
fi
2828

29+
if [ "${TRUAPI_REQUIRE_GENERATED:-0}" = "1" ]; then
30+
echo "ensure-generated: generated files are missing and TRUAPI_REQUIRE_GENERATED=1, so codegen will not run." >&2
31+
echo "These files are expected to be restored from the 'codegen-output' CI artifact." >&2
32+
echo "If you added a generated output, add its path to the upload-artifact step in .github/workflows/ci.yml." >&2
33+
exit 1
34+
fi
35+
2936
TRUAPI_SKIP_PACKAGE_BUILD=1 ./scripts/codegen.sh

0 commit comments

Comments
 (0)