-
Notifications
You must be signed in to change notification settings - Fork 8
383 lines (356 loc) · 16 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
382
383
name: Release version
on:
push:
tags:
- "v*.*.*"
branches:
- main
# The following two branch names can be used to force build a version for development and sharing a patch.
- "*force-npm-publish*"
- "v*.*.*-branch*"
- "release-*"
env:
CARGO_TERM_COLOR: always
jobs:
prepare:
name: Prepare release
runs-on: ubuntu-22.04
outputs:
tag_name: ${{ steps.release_info.outputs.tag_name }}
release_name: ${{ steps.release_info.outputs.release_name }}
release_type: ${{ steps.release_info.outputs.release_type }}
is_tagged: ${{ steps.release_info.outputs.is_tagged }}
release_info: ${{ steps.release_info.outputs.release_info }}
matrix: ${{ steps.set_matrix.outputs.matrix }}
changelog: ${{ steps.build_changelog.outputs.changelog }}
commit_hash: ${{ steps.vars.outputs.hash_short }}
steps:
- name: Checkout sources
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Declare commit hash variable
id: vars
shell: bash
run: |
echo "::set-output name=hash_short::$(git rev-parse --short HEAD)"
- name: Compute release name and tag
id: release_info
run: |
## NOTE: currently `tag_name` and `release_name` are the exact same for all these cases. They can be combined.
if [[ "${GITHUB_REF_NAME}" =~ ^v([0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?(\.[a-zA-Z0-9]+)?) ]]; then
echo "::set-output name=tag_name::${GITHUB_REF_NAME}"
echo "::set-output name=release_name::${GITHUB_REF_NAME}"
echo "::set-output name=is_tagged::true"
echo "::set-output name=release_type::next" # NOTE: we currently go directly into prod when a tag is released - using 'next' would give us time to review before upgrading the tag.
# echo "::set-output name=release_type::latest"
elif [[ "${GITHUB_REF_NAME}" =~ ^release-([0-9]+\.[0-9]+\.[0-9]+) ]]; then
version=v${BASH_REMATCH[1]}
timestamp=$(date +'%Y%m%d%H%M%S')
short_commit=${{ steps.vars.outputs.hash_short }}
echo "::set-output name=tag_name::${version}-${timestamp}-${short_commit}"
echo "::set-output name=release_name::${version}-${timestamp}-${short_commit}"
echo "::set-output name=is_tagged::false"
echo "::set-output name=release_type::dev"
else
timestamp=$(date +'%Y%m%d%H%M%S')
short_commit=${{ steps.vars.outputs.hash_short }}
echo "::set-output name=tag_name::v2.0.0-${GITHUB_REF_NAME}-${timestamp}-${short_commit}"
echo "::set-output name=release_name::v2.0.0-${GITHUB_REF_NAME}-${timestamp}-${short_commit}"
echo "::set-output name=is_tagged::false"
echo "::set-output name=release_type::dev"
fi
- name: Set matrix
id: set_matrix
# The OS is used for the runner
# The platform is a generic platform name
# The target is used by Cargo
# The arch is either 386, arm64 or amd64
# The svm target platform to use for the binary https://github.com/roynalnaruto/svm-rs/blob/84cbe0ac705becabdc13168bae28a45ad2299749/svm-builds/build.rs#L4-L24
# TODO: fix the builds for the below architectures and add them back to the matrix (see the 'Set new version in Cargo.toml' below for windows issue )
# {"os":"windows-latest", "platform":"win32", "target":"x86_64-pc-windows-msvc", "arch":"amd64", "svm_target_platform":"windows-amd64", "name":"win32-x64-msvc"}
run: |
matrix='[
{"os":"ubuntu-22.04", "platform":"linux", "target":"aarch64-unknown-linux-gnu", "arch":"arm64", "svm_target_platform":"linux-aarch64", "name":"linux-arm64-glibc"},
{"os":"ubuntu-22.04", "platform":"linux", "target":"x86_64-unknown-linux-musl", "arch":"amd64", "svm_target_platform":"linux-amd64", "name":"linux-x64-musl"},
{"os":"macos-latest", "platform":"darwin", "target":"x86_64-apple-darwin", "arch":"amd64", "svm_target_platform":"macosx-amd64", "name":"darwin-x64"},
{"os":"macos-latest", "platform":"darwin", "target":"aarch64-apple-darwin", "arch":"arm64", "svm_target_platform":"macosx-aarch64", "name":"darwin-arm64"}
]'
if [[ "${{ steps.release_info.outputs.is_tagged }}" == "false" ]]; then
# Non-release builds are only for the team, so we don't need to build for windows, or old mac books, or unused arm linux.
matrix=$(echo "$matrix" | jq '[.[] | select(.platform != "win32" and .name != "darwin-x64")]')
fi
matrix=$(echo "$matrix" | jq -c '.') # put it on a single line (compact)
echo "::set-output name=matrix::${matrix}"
- name: Build changelog
id: build_changelog
if: steps.release_info.outputs.is_tagged == 'true'
uses: mikepenz/release-changelog-builder-action@v2
with:
configuration: "./.github/changelog.json"
fromTag: ${{ '' }}
toTag: ${{ steps.release_info.outputs.tag_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
release:
name: ${{ matrix.job.target }} (${{ matrix.job.os }})
runs-on: ${{ matrix.job.os }}
defaults:
run:
working-directory: codegenerator
needs: prepare
strategy:
matrix:
job: ${{ fromJSON(needs.prepare.outputs.matrix) }}
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Set new version in Cargo.toml
working-directory: codegenerator/cli
shell: bash
run: |
awk -v version="${VERSION:1}" '/^version = "/ {$0 = "version = \"" version "\""} 1' Cargo.toml > Cargo.toml.tmp && mv Cargo.toml.tmp Cargo.toml
env:
VERSION: ${{ needs.prepare.outputs.tag_name }}
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: ${{ matrix.job.target }}
override: true
- uses: Swatinem/rust-cache@v1
with:
cache-on-failure: true
- name: Apple M1 setup
if: ${{ matrix.job.target == 'aarch64-apple-darwin' }}
run: |
echo "SDKROOT=$(xcrun -sdk macosx --show-sdk-path)" >> $GITHUB_ENV
echo "MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx --show-sdk-platform-version)" >> $GITHUB_ENV
- name: Linux ARM setup
if: ${{ matrix.job.target == 'aarch64-unknown-linux-gnu' }}
run: |
sudo apt-get update -y
sudo apt-get install -y gcc-aarch64-linux-gnu
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
- if: ${{ runner.os == 'Linux' }}
uses: awalsh128/cache-apt-pkgs-action@v1
with:
# musl-tools provides musl-gcc
packages: musl-tools
- if: ${{ runner.os == 'Linux' }}
run: rustup target add x86_64-unknown-linux-musl
- name: Build binaries
uses: actions-rs/cargo@v1
env:
SVM_TARGET_PLATFORM: ${{ matrix.job.svm_target_platform }}
with:
command: build
args: --release --bins --target ${{ matrix.job.target }} --manifest-path codegenerator/Cargo.toml
- name: Archive binaries
id: artifacts
env:
PLATFORM_NAME: ${{ matrix.job.platform }}
TARGET: ${{ matrix.job.target }}
ARCH: ${{ matrix.job.arch }}
VERSION_NAME: ${{ needs.prepare.outputs.tag_name }}
run: |
if [ "$PLATFORM_NAME" == "linux" ]; then
tar -czvf "envio_${VERSION_NAME}_${PLATFORM_NAME}_${ARCH}.tar.gz" -C ./target/${TARGET}/release envio
echo "::set-output name=file_name::envio_${VERSION_NAME}_${PLATFORM_NAME}_${ARCH}.tar.gz"
elif [ "$PLATFORM_NAME" == "darwin" ]; then
# We need to use gtar here otherwise the archive is corrupt.
# See: https://github.com/actions/virtual-environments/issues/2619
gtar -czvf "envio_${VERSION_NAME}_${PLATFORM_NAME}_${ARCH}.tar.gz" -C ./target/${TARGET}/release envio
echo "::set-output name=file_name::envio_${VERSION_NAME}_${PLATFORM_NAME}_${ARCH}.tar.gz"
else
cd ./target/${TARGET}/release
7z a -tzip "envio_${VERSION_NAME}_${PLATFORM_NAME}_${ARCH}.zip" envio.exe
mv "envio_${VERSION_NAME}_${PLATFORM_NAME}_${ARCH}.zip" ../../../
echo "::set-output name=file_name::envio_${VERSION_NAME}_${PLATFORM_NAME}_${ARCH}.zip"
fi
shell: bash
- name: Build man page
id: man
if: ${{ matrix.job.target == 'x86_64-unknown-linux-gnu' }}
env:
PLATFORM_NAME: ${{ matrix.job.platform }}
TARGET: ${{ matrix.job.target }}
VERSION_NAME: ${{ needs.prepare.outputs.tag_name }}
run: |
sudo apt-get -y install help2man
help2man -N ./target/${TARGET}/release/envio > envio.1
gzip envio.1
tar -czvf "envio_man_${VERSION_NAME}.tar.gz" envio.1.gz
echo "::set-output name=envio_man::envio_man_${VERSION_NAME}.tar.gz"
shell: bash
# Creates the release for this specific version
- name: Create release
if: steps.release_info.outputs.is_tagged == 'true'
uses: softprops/action-gh-release@v1
with:
name: ${{ needs.prepare.outputs.release_name }}
tag_name: ${{ needs.prepare.outputs.tag_name }}
prerelease: true #always true for now
body: ${{ needs.prepare.outputs.changelog }}
files: |
codegenerator/${{ steps.artifacts.outputs.file_name }}
codegenerator/${{ steps.man.outputs.envio_man }}
- name: Install node
uses: actions/setup-node@v4
with:
node-version: "18.16.0"
registry-url: "https://registry.npmjs.org"
- name: Publish to NPM
shell: bash
env:
TARGET: ${{ matrix.job.target }}
NAME: ${{ matrix.job.name }}
OS: ${{ matrix.job.os }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
version: ${{ needs.prepare.outputs.tag_name }}
run: |
cd cli/npm
bin="envio"
node_os=$(echo "${NAME}" | cut -d '-' -f1)
export node_os
node_arch=$(echo "${NAME}" | cut -d '-' -f2)
export node_arch
if [ "${OS}" = "windows-2022" ]; then
export node_pkg="${bin}-windows-${node_arch}"
else
export node_pkg="${bin}-${node_os}-${node_arch}"
fi
mkdir -p "${node_pkg}/bin"
envsubst < package.json.tmpl > "${node_pkg}/package.json"
if [ "${OS}" = "windows-2022" ]; then
bin="${bin}.exe"
fi
cp "../../target/${TARGET}/release/${bin}" "${node_pkg}/bin"
cp ../README.md "${node_pkg}"
cd "${node_pkg}"
npm publish --access public
publish-npm:
name: Publish the base package to NPM
needs:
- "release"
- "prepare"
runs-on: ubuntu-22.04
defaults:
run:
working-directory: codegenerator/cli/npm/envio
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install node
uses: actions/setup-node@v4
with:
node-version: "18.16.0"
registry-url: "https://registry.npmjs.org"
- uses: pnpm/action-setup@v3
with:
version: 8
- name: Publish the package
shell: bash
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
version: ${{ needs.prepare.outputs.tag_name }}
RELEASE_TYPE: ${{ needs.prepare.outputs.release_type}}
run: |
envsubst < ./package.json.tmpl > "package.json"
cat package.json # Leave this here for the sake of debugging bad builds.
cp ../../README.md .
echo "Publishing with tag ${RELEASE_TYPE}"
npm publish --access public --tag ${RELEASE_TYPE}
# TODO: add back the integration tests and work out how to automate this. This has been causing issues previously.
# update-npm-tag:
# if: ${{ needs.prepare.outputs.is_tagged }}
# needs:
# - prepare
# - template-integration-test
# runs-on: ubuntu-22.04
# steps:
# - name: update npm tag
# env:
# NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# VERSION: ${{ needs.prepare.outputs.tag_name }}
# run: |
# npm dist-tag add envio@${VERSION} next
## NOTE: we no longer need to build/push an image every commit.
# build-and-push:
# name: "build, publish and add docker container for deployment"
# needs:
# - "prepare"
# - "publish-npm"
# runs-on: ubuntu-latest
#
# steps:
# - name: Checkout
# uses: actions/checkout@v4
#
# - name: Set up Docker Buildx
# id: buildx
# uses: docker/setup-buildx-action@master
#
# - name: Cache Docker rescript layers
# uses: actions/cache@v2
# with:
# path: /tmp/.base-template-deployer-docker-rescript-cache
# key: ${{ runner.os }}-base-template-deployer-docker-rescript-cache-${{ github.sha }}
# restore-keys: |
# ${{ runner.os }}-base-template-deployer-docker-rescript-cache-
#
# - name: Cache Docker typescript layers
# uses: actions/cache@v2
# with:
# path: /tmp/.base-template-deployer-docker-ts-cache
# key: ${{ runner.os }}-base-template-deployer-docker-ts-cache-${{ github.sha }}
# restore-keys: |
# ${{ runner.os }}-base-template-deployer-docker-ts-cache-
#
# - name: Log in to Docker Hub
# uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
# with:
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
#
# - name: Build & push docker image
# uses: docker/build-push-action@v2
# with:
# builder: ${{ steps.buildx.outputs.name }}
# file: ./.github/Dockerfile #this parameter does not take into account the context above
# push: true
# tags: ${{ secrets.DOCKER_USERNAME }}/envio-rescript-pnpm:${{ needs.prepare.outputs.release_name }}
# # tags: ${{ secrets.DOCKER_USERNAME }}/envio:${{ needs.prepare.outputs.release_name }}
# build-args: |
# COMMIT_HASH_ARG= ${{ needs.prepare.outputs.commit_hash }} #used for database name
# ENVIO_VERSION=${{ needs.prepare.outputs.tag_name }}
# cache-from: type=local,src=/tmp/.base-template-deployer-docker-rescript-cache
# cache-to: type=local,dest=/tmp/.base-template-deployer-docker-rescript-cache-new
#
# - name: Build & push type script docker image
# uses: docker/build-push-action@v2
# with:
# builder: ${{ steps.buildx.outputs.name }}
# file: ./.github/Dockerfile.typescript #this parameter does not take into account the context above
# push: true
# tags: ${{ secrets.DOCKER_USERNAME }}/envio-typescript-pnpm:${{ needs.prepare.outputs.release_name }}
# # tags: ${{ secrets.DOCKER_USERNAME }}/envio:${{ needs.prepare.outputs.release_name }}
# build-args: |
# COMMIT_HASH_ARG= ${{ needs.prepare.outputs.commit_hash }} #used for database name
# ENVIO_VERSION=${{ needs.prepare.outputs.tag_name }}
# cache-from: type=local,src=/tmp/.base-template-deployer-docker-ts-cache
# cache-to: type=local,dest=/tmp/.base-template-deployer-docker-ts-cache-new
#
# # Temp fix
# # https://github.com/docker/build-push-action/issues/252
# # https://github.com/moby/buildkit/issues/1896
# - name: Move cache
# run: |
# rm -rf /tmp/.base-template-deployer-docker-rescript-cache
# mv /tmp/.base-template-deployer-docker-rescript-cache-new /tmp/.base-template-deployer-docker-rescript-cache
#
# - name: Move cache typescript
# run: |
# rm -rf /tmp/.base-template-deployer-docker-ts-cache
# mv /tmp/.base-template-deployer-docker-ts-cache-new /tmp/.base-template-deployer-docker-ts-cache