381 lines (344 loc) · 11 KB
/
release.yml
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# Workflow for creating releases
#
# This workflow is triggered by the `version.yml` workflow when a version
# tag is created (one starting with `v`).
#
# It also has inputs to allow all, or some jobs, to be triggered manually via
# https://github.com/stencila/stencila/actions/workflows/release.yml.
# This is useful for fixing parts of the release without creating a new tag, or
# moving an existing tag.
name: Release
on:
workflow_dispatch:
inputs:
tag:
description: The tag to create the release for e.g. v2.1.0
type: string
required: true
create-release:
description: Create release
type: boolean
default: true
build-cli:
description: Build CLI
type: boolean
default: true
publish-ts:
description: Publish @stencila/types
type: boolean
default: true
build-node:
description: Build Node.js SDK addons
type: boolean
default: true
publish-node:
description: Publish Node.js SDK
type: boolean
default: true
build-python:
description: Build Python SDK wheels
type: boolean
default: true
publish-python:
description: Publish Python SDK
type: boolean
default: true
publish-docker:
description: Build and Push Docker image
type: boolean
default: true
publish-release:
description: Publish release
type: boolean
default: true
env:
RUST_VERSION: "1.76.0"
NODE_VERSION: "20"
PYTHON_VERSION: "3.11"
jobs:
# Create a draft release
create-release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
# Needed only because `gh` errors if not in a repo
uses: actions/checkout@v4
with:
ref: ${{ inputs.tag }}
- name: Create release
# Put `if` here because all subsequent jobs `need` it so will not
# run if this one does not
if: ${{ inputs.create-release }}
run: gh release create ${{ inputs.tag }} --title ${{ inputs.tag }} --draft
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Build and upload CLI
build-cli:
if: ${{ inputs.build-cli }}
needs: [create-release]
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
ext: tar.xz
- os: macos-latest
target: x86_64-apple-darwin
ext: tar.xz
- os: macos-latest
target: aarch64-apple-darwin
ext: tar.xz
- os: windows-latest
target: x86_64-pc-windows-msvc
ext: zip
runs-on: ${{ matrix.os }}
permissions:
contents: write
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
ref: ${{ inputs.tag }}
- name: Setup Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_VERSION }}
targets: ${{ matrix.target }}
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
- name: Build and archive CLI
run: make -C rust build archive -e TARGET=${{ matrix.target }}
- name: Upload archive
run: gh release upload ${{ inputs.tag }} target/cli-${{ inputs.tag }}-${{ matrix.target }}.${{ matrix.ext }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Build and publish @stencila/types package
publish-ts:
if: ${{ inputs.publish-ts }}
needs: [create-release]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ inputs.tag }}
- name: Setup Node.js and NPM
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: "https://registry.npmjs.org"
- name: Publish @stencila/types
run: make -C ts -B install publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# Build and upload Node SDK binary addons
build-node:
if: ${{ inputs.build-node }}
needs: [create-release]
strategy:
fail-fast: false
matrix:
# See `node/install.cjs` for the correct target to use
include:
- os: ubuntu-latest
target: linux-x64-gnu
- os: buildjet-8vcpu-ubuntu-2204-arm
target: linux-arm64-gnu
- os: macos-latest
target: darwin-x64
- os: macos-latest-xlarge
target: darwin-arm64
- os: windows-latest
target: win32-x64-msvc
runs-on: ${{ matrix.os }}
permissions:
contents: write
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
ref: ${{ inputs.tag }}
- name: Setup Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_VERSION }}
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
- name: Setup Node.js and NPM
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: "https://registry.npmjs.org"
- name: Build package
# This avoids various issues with doing just `npm install` here by
# only installing `napi` (globally, so other deps are not installed).
# Here be dragons; change with care.
run: |
npm install --global @napi-rs/cli
cd node && npm run build:addon
- name: Upload addon
# Use `matrix.target` here instead of `*` glob because the latter does not work on Windows
run: gh release upload ${{ inputs.tag }} node/stencila.${{ matrix.target }}.node.gz
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Publish @stencila/node package
publish-node:
if: ${{ inputs.publish-node }}
needs: [build-node]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ inputs.tag }}
- name: Setup Node.js and NPM
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: "https://registry.npmjs.org"
- name: Publish @stencila/node
run: make -C node -B publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# Build Python SDK
# Based on https://github.com/messense/py-dissimilar/blob/main/.github/workflows/CI.yml
build-python:
if: ${{ inputs.build-python }}
needs: [create-release]
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-20.04
architecture: x64
target: x64
interpreter: 3.8 3.9 3.10 3.11 3.12
- os: ubuntu-latest
architecture: x64
target: x64
interpreter: 3.8 3.9 3.10 3.11 3.12
- os: macos-latest
architecture: x64
target: x64
interpreter: 3.8 3.9 3.10 3.11 3.12
- os: macos-latest-xlarge
architecture: arm64
target: aarch64
interpreter: 3.8 3.9 3.10 3.11 3.12
- os: windows-latest
architecture: x64
target: x64
interpreter: 3.8 3.9 3.10 3.11 3.12
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
ref: ${{ inputs.tag }}
- name: Setup Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_VERSION }}
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
architecture: ${{ matrix.architecture }}
- name: Build wheel
uses: PyO3/maturin-action@v1
with:
working-directory: python
target: ${{ matrix.target }}
# Test changes to these args using the `build` recipe in the `python/Makefile`
args: --release --out dist --interpreter ${{ matrix.interpreter }}
- name: Upload wheel
uses: actions/upload-artifact@v4
with:
name: wheels
path: python/dist
# Publish Python SDK
# This action should not checkout the repository because that adds other,
# non-wheel files to the upload and thereby causes the upload to fail.
publish-python:
if: ${{ inputs.publish-python }}
needs: [build-python]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: wheels
- name: Publish to PyPI
uses: PyO3/maturin-action@v1
env:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
with:
command: upload
args: --skip-existing *
# Build and push Docker image
# Based on https://docs.github.com/en/actions/publishing-packages/publishing-docker-images
publish-docker:
if: ${{ inputs.publish-docker }}
needs: [create-release]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ inputs.tag }}
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Log in to the GitHub container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
stencila/stencila
ghcr.io/${{ github.repository }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
stencila/stencila:latest
stencila/stencila:${{ inputs.tag }}
labels: ${{ steps.meta.outputs.labels }}
# Publish the draft release
# Wait for all packages to be published so that the `install.yml` workflow
# that this triggers tests this release and not a previous version
publish-release:
if: ${{ inputs.publish-release }}
needs: [build-cli, publish-ts, publish-node, publish-python, publish-docker]
runs-on: ubuntu-latest
permissions:
contents: write
actions: write
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout repository
# Needed only because `gh` errors if not in a repo
uses: actions/checkout@v4
with:
ref: ${{ inputs.tag }}
- name: Mark release as non-draft
run: gh release edit ${{ inputs.tag }} --draft=false
- name: Trigger installation test workflow
# Sleep for a while to allow last published assets (usually Python packages)
# to be made available on package repositories before attempting to install them
run: sleep 90 && gh workflow run install.yml