-
Notifications
You must be signed in to change notification settings - Fork 2
214 lines (185 loc) · 6.91 KB
/
publish-packages.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
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
name: Publish
on:
pull_request:
types:
- closed
branches:
- master
jobs:
build-test:
name: Build and test (${{ matrix.os }})
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
env:
MAESTRO_API_KEY: ${{ secrets.MAESTRO_API_KEY }}
steps:
- uses: actions/checkout@v3
- uses: swatinem/rust-cache@v2
- name: Build sidan-csl-rs
run: >
cd packages/sidan-csl-rs &&
cargo build
--locked
--verbose
- uses: actions/checkout@v3
- uses: swatinem/rust-cache@v2
- name: Build whisky
run: >
cd packages/whisky &&
cargo build
--locked
--verbose
- name: Create .env file
run: echo "MAESTRO_API_KEY=${MAESTRO_API_KEY}" > packages/whisky/.env
- name: Run core tests (without coverage)
if: matrix.os != 'ubuntu-latest'
run: >
cd packages/sidan-csl-rs &&
cargo test
--verbose
- name: Run rust tests (without coverage)
if: matrix.os != 'ubuntu-latest'
run: >
cd packages/whisky &&
cargo test
--verbose
- name: Run core tests (with coverage)
if: matrix.os == 'ubuntu-latest'
run: >
cd packages/sidan-csl-rs &&
cargo install cargo-tarpaulin
&& cargo tarpaulin
--verbose
--out Xml
--engine llvm
--skip-clean
- name: Run rust tests (with coverage)
if: matrix.os == 'ubuntu-latest'
run: >
cd packages/whisky &&
cargo install cargo-tarpaulin
&& cargo tarpaulin
--verbose
--out Xml
--engine llvm
--skip-clean
- name: Upload coverage reports to Codecov
if: matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v3
check-version:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
outputs:
core-version-updated: ${{ steps.compare-versions.outputs.core-version-updated }}
rust-version-updated: ${{ steps.compare-versions.outputs.rust-version-updated }}
steps:
- name: Checkout master branch at commit before merge
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.sha }}
- name: Get package version from master branch before merge
id: pre-merge-version
run: |
cd packages/sidan-csl-rs
CORE_PRE_MERGE_VERSION=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[0].version')
echo "core_pre_merge_version=$CORE_PRE_MERGE_VERSION" >> "$GITHUB_OUTPUT"
cd ../whisky
RUST_PRE_MERGE_VERSION=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[0].version')
echo "rust_pre_merge_version=$RUST_PRE_MERGE_VERSION" >> "$GITHUB_OUTPUT"
- name: Checkout master branch at commit after merge
uses: actions/checkout@v4
with:
ref: "master"
- name: Get package version from master branch after merge
id: post-merge-version
run: |
cd packages/sidan-csl-rs
CORE_POST_MERGE_VERSION=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[0].version')
echo "core_post_merge_version=$CORE_POST_MERGE_VERSION" >> "$GITHUB_OUTPUT"
cd ../whisky
RUST_POST_MERGE_VERSION=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[0].version')
echo "rust_post_merge_version=$RUST_POST_MERGE_VERSION" >> "$GITHUB_OUTPUT"
- name: Compare versions
id: compare-versions
run: |
if [[ "${{ steps.pre-merge-version.outputs.core_pre_merge_version }}" != "${{ steps.post-merge-version.outputs.core_post_merge_version }}" ]]; then
echo "core-version-updated=true" >> "$GITHUB_OUTPUT"
else
echo "core-version-updated=false" >> "$GITHUB_OUTPUT"
fi
if [[ "${{ steps.pre-merge-version.outputs.rust_pre_merge_version }}" != "${{ steps.post-merge-version.outputs.rust_post_merge_version }}" ]]; then
echo "rust-version-updated=true" >> "$GITHUB_OUTPUT"
else
echo "rust-version-updated=false" >> "$GITHUB_OUTPUT"
fi
publish-npm:
needs: [check-version, build-test]
if: needs.check-version.outputs.core-version-updated == 'true'
name: Publish NPM wasm package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org/
- name: Install dependencies
run: npm install && cargo install wasm-pack
- run: npm run js:publish-nodejs && npm run js:publish-browser
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
publish-core-crate:
needs: [check-version, build-test]
if: needs.check-version.outputs.core-version-updated == 'true'
name: Publish core crate
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: cd packages/sidan-csl-rs && cargo publish --token ${PUBLISH_KEY}
env:
PUBLISH_KEY: ${{ secrets.PUBLISH_KEY }}
only-publish-whisky-crate:
needs: [check-version, build-test]
if: needs.check-version.outputs.rust-version-updated == 'true' && needs.check-version.outputs.core-version-updated == 'false'
name: Only publish Whisky crate
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: cd packages/whisky && cargo publish --token ${PUBLISH_KEY}
env:
PUBLISH_KEY: ${{ secrets.PUBLISH_KEY }}
publish-whisky-crate:
needs: [check-version, build-test, publish-core-crate]
if: needs.check-version.outputs.rust-version-updated == 'true' && needs.check-version.outputs.core-version-updated == 'true'
name: Publish Whisky crate
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: cd packages/whisky && cargo publish --token ${PUBLISH_KEY}
env:
PUBLISH_KEY: ${{ secrets.PUBLISH_KEY }}