-
Notifications
You must be signed in to change notification settings - Fork 5
281 lines (252 loc) · 9.24 KB
/
rs-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
# This workflow is triggered by a tag that matches the pattern rs/v*.
# Essentially it does the following:
# - gathers release info including its version using created tag
# - applies version to the workspace and updates crates dependencies
# - runs all tests before going further
# - builds assets for the release: IDL Parser for WASM
# - publishes 'sails-*' crates to crates.io
# - amends contract template with the new version and runs tests against it
# - crates PR with the changes, release tag and draft release
# Merging PR and pubslishing release is supposed to be done manually.
name: '[rs] Release'
on:
push:
tags:
- 'rs/v*'
env:
# see https://api.github.com/users/github-actions%5Bbot%5D
GITHUB_USER_NAME: github-actions[bot]
GITHUB_USER_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com
# crates in order of dependency (topological order), first the ones that are not dependent on any other
SAILS_CRATES: |
sails-idl-meta
sails-idl-parser
sails-idl-gen
sails-client-gen
sails-macros-core
sails-macros
sails-rs
sails-cli
jobs:
prepare:
name: Prepare Release
runs-on: ubuntu-latest
permissions:
contents: write
defaults:
run:
shell: bash
outputs:
rc_branch: ${{ steps.rc_branch.outputs.branch }}
r_version: ${{ steps.release_info.outputs.version }}
r_tag: ${{ steps.release_info.outputs.r_tag }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Release Info
id: release_info
run: |
R_TAG=${GITHUB_REF#refs/tags/}
VERSION=${R_TAG#rs/v}
if [[ ! $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-z]+\.[0-9]+)?$ ]]; then
echo "'$VERSION' is not a valid semver version"
exit 1
fi
echo "Release Tag: $R_TAG"
echo "r_tag=$R_TAG" >> $GITHUB_OUTPUT
echo "Version: $VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Create RC Branch
id: rc_branch
run: |
RC_BRANCH="rc/rs/v${{ steps.release_info.outputs.version }}"
git config --global user.name "$GITHUB_USER_NAME"
git config --global user.email "$GITHUB_USER_EMAIL"
git checkout -b "$RC_BRANCH"
git push origin "$RC_BRANCH"
echo "branch=$RC_BRANCH" >> $GITHUB_OUTPUT
- name: Set Workspace Version & Update Its Dependencies
run: |
sed -i "s/^version = \".*\"/version = \"${{ steps.release_info.outputs.version }}\"/" Cargo.toml
cargo update
git add Cargo.toml
git add Cargo.lock
git commit -m "build(rs): update version to v${{ steps.release_info.outputs.version }}"
git push origin "${{ steps.release_info.outputs.rc_branch }}"
# - name: Create RC Branch
# id: rc_branch
# run: |
# RC_BRANCH="rc/rs/v${{ steps.release_info.outputs.version }}"
# git config --global user.name "$GITHUB_USER_NAME"
# git config --global user.email "$GITHUB_USER_EMAIL"
# git checkout -b "$RC_BRANCH"
# git add Cargo.toml
# git add Cargo.lock
# git commit -m "build(rs): update version to v${{ steps.release_info.outputs.version }}"
# git push origin "$RC_BRANCH"
# git push origin --delete "${{ steps.release_info.outputs.pin_tag }}"
# echo "branch=$RC_BRANCH" >> $GITHUB_OUTPUT
ws_tests:
name: Run Workspace Tests
needs:
- prepare
uses: ./.github/workflows/rs-run-ws-tests.yml
with:
sources_ref: ${{ needs.prepare.outputs.rc_branch }}
gear_node_version: 1.7.0
cli_tests:
name: Run CLI Tests
needs:
- prepare
uses: ./.github/workflows/rs-run-cli-tests.yml
with:
sources_ref: ${{ needs.prepare.outputs.rc_branch }}
assets:
name: Build Assets
runs-on: ubuntu-latest
needs:
- prepare
defaults:
run:
shell: bash
steps:
- name: Checkout Code from Release Branch
uses: actions/checkout@v4
with:
ref: ${{ needs.prepare.outputs.rc_branch }}
- name: Install wasm-opt
uses: ./.github/actions/install-wasm-utils
- name: Build IDL Parser for WASM
run: |
cargo build -p sails-idl-parser --target wasm32-unknown-unknown --release
mkdir -p ./assets/sails_idl_parser
wasm-opt -O4 -o ./assets/sails_idl_parser/sails_idl_parser.wasm ./target/wasm32-unknown-unknown/release/sails_idl_parser.wasm
- name: Build Demo
run: |
cargo build -p demo --release
mkdir -p ./assets/demo
cp ./target/wasm32-unknown-unknown/release/demo.opt.wasm ./assets/demo/demo.wasm
cp ./examples/demo/client/demo.idl ./assets/demo/demo.idl
- name: Build NoSvcsProg
run: |
cargo build -p no-svcs-prog --release
mkdir -p ./assets/no_svcs_prog
cp ./target/wasm32-unknown-unknown/release/no_svcs_prog.opt.wasm ./assets/no_svcs_prog/no_svcs_prog.wasm
cp ./examples/no-svcs-prog/wasm/no-svcs-prog.idl ./assets/no_svcs_prog/no-svcs-prog.idl
- name: Upload Assets
uses: actions/upload-artifact@v4
with:
name: sails-assets
path: ./assets/
publish:
name: Publish Crates
runs-on: ubuntu-latest
needs:
- prepare
- ws_tests
- cli_tests
defaults:
run:
shell: bash
steps:
- name: Checkout Code from Release Branch
uses: actions/checkout@v4
with:
ref: ${{ needs.prepare.outputs.rc_branch }}
- name: Publish Crates
if: false
run: |
VERSION=${{ needs.prepare.outputs.r_version }}
for SAILS_CRATE in $SAILS_CRATES; do
sed -i "/^\s*${SAILS_CRATE} = {.*}/ s/}/, version = \"=${VERSION}\" }/" Cargo.toml
done
cargo login ${{ secrets.CRATES_IO_TOKEN }}
for SAILS_CRATE in $SAILS_CRATES; do
cargo publish -p $SAILS_CRATE
done
# Revert temporary changes to Cargo.toml
git checkout -- .
- name: Update Contract Template
run: |
VERSION=${{ needs.prepare.outputs.r_version }}
sed -i -E "s/(variable::set\(\"sails-rs-version\", \")([^\"]+)(\"\);)/\1$VERSION\3/" templates/set-vars.rhai
git config --global user.name "$GITHUB_USER_NAME"
git config --global user.email "$GITHUB_USER_EMAIL"
git add templates/set-vars.rhai
git commit -m "build(tmpl): update version to v${{ needs.prepare.outputs.r_version }} in contract template"
git push origin "${{ needs.prepare.outputs.rc_branch }}"
cli_tests_after_publish:
if: false
name: Run CLI Tests After Publish
needs:
- prepare
- publish
uses: ./.github/workflows/rs-run-cli-tests.yml
with:
sources_ref: ${{ needs.prepare.outputs.rc_branch }}
release:
name: Create Release
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
needs:
- prepare
- cli_tests_after_publish
- assets
defaults:
run:
shell: bash
env:
R_NAME: Sails-RS v${{ needs.prepare.outputs.r_version }}
steps:
- name: Checkout Code from Release Branch
uses: actions/checkout@v4
with:
ref: ${{ needs.prepare.outputs.rc_branch }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Download Assets
uses: actions/download-artifact@v4
with:
name: sails-assets
path: ./assets
- name: Re-create Release Tag
run: |
R_TAG=${{ needs.prepare.outputs.r_tag }}
git config --global user.name "$GITHUB_USER_NAME"
git config --global user.email "$GITHUB_USER_EMAIL"
git push origin --delete "$R_TAG"
git tag -a "$R_TAG" -m "Release v${{ needs.prepare.outputs.r_version }}"
git push origin "$R_TAG"
- name: Install GitHub CLI
run: sudo apt-get install -y gh
- name: Create Sync PR
id: sync_pr
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
PR_URL=$(gh pr create \
--title "release: sync $R_NAME to master" \
--body "This PR was created by GitHub Actions" \
--base master \
--head ${{ needs.prepare.outputs.rc_branch }})
echo "url=$PR_URL" >> $GITHUB_OUTPUT
- name: Create Draft Release
uses: softprops/action-gh-release@v2
with:
name: ${{ env.R_NAME }}
tag_name: ${{ needs.prepare.outputs.r_tag }}
draft: true
body: |
:exclamation: This is a draft release.
:exclamation: Please write/generate change notes and publish the release.
:exclamation: Please also check this [PR](${{ steps.sync_pr.outputs.url }}) to sync the changes to master.
fail_on_unmatched_files: true
files: |
./assets/sails_idl_parser/sails_idl_parser.wasm
./assets/demo/demo.wasm
./assets/demo/demo.idl
./assets/no_svcs_prog/no_svcs_prog.wasm
./assets/no_svcs_prog/no-svcs-prog.idl
token: ${{ secrets.GITHUB_TOKEN }}