-
Notifications
You must be signed in to change notification settings - Fork 112
276 lines (210 loc) · 8.22 KB
/
cd.yaml
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
name: CD
on:
push:
branches:
- main
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
release:
# don't run on forks
if: ${{ github.repository_owner == 'SmartThingsCommunity' }}
name: Release
runs-on: ubuntu-latest
outputs:
cli-released: ${{ steps.cli-release.outputs.published }}
cli-version: ${{ steps.cli-metadata.outputs.version }}
cli-tag: ${{ steps.cli-metadata.outputs.tag }}
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18.5.0
- name: Install Dependencies
run: npm ci
- name: Create Release Pull Request or Publish to npm
id: changesets
uses: changesets/action@v1
with:
version: npm run version
publish: npm run release
commit: "chore(changesets): version packages"
title: "chore(changesets): version packages"
createGithubReleases: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
# decouple Github Release from library-only publishing
- name: Check if CLI Published
id: cli-release
run: echo "published=$(echo '${{ steps.changesets.outputs.publishedPackages }}' | jq 'any(.name == "@smartthings/cli")')" >> $GITHUB_OUTPUT
- name: Derive Required Metadata
id: cli-metadata
if: steps.cli-release.outputs.published == 'true'
run: | # derive latest info from changesets output
PUBLISHED_PACKAGE=$(echo '${{ steps.changesets.outputs.publishedPackages }}' | jq 'map(select(.name == "@smartthings/cli")) | .[]')
echo "tag=$(echo $PUBLISHED_PACKAGE | jq --raw-output '.name + "@" + .version')" >> $GITHUB_OUTPUT
echo "version=$(echo $PUBLISHED_PACKAGE | jq --raw-output '.version')" >> $GITHUB_OUTPUT
package:
name: Package CLI
runs-on: ubuntu-latest
steps:
- name: Install and Setup QEMU
run: |
sudo apt-get update
sudo apt-get install qemu binfmt-support qemu-user-static
# see https://github.com/vercel/pkg/issues/1251#issuecomment-1024832725
- name: Download and Install ldid Codesign Utility
run: |
wget https://github.com/jesec/ldid-static/releases/download/v2.1.4/ldid-amd64
chmod +x ldid-amd64
sudo mv ldid-amd64 /usr/local/bin/ldid
- name: Checkout Repo
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18.5.0
- run: npm ci
- run: npm run build
- name: Package CLI
run: npm run package
# maintain executable file permissions
# see https://github.com/actions/upload-artifact/issues/38
- name: Tar files
run: tar -cvf dist_bin.tar packages/cli/dist_bin/
- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: dist_bin
path: dist_bin.tar
functional-test:
needs: package
name: Functional Tests
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v3
- name: Download Artifacts
uses: actions/download-artifact@v3
with:
name: dist_bin
- name: Extract Artifacts
run: tar -xvf dist_bin.tar
- uses: actions/setup-python@v4
with:
python-version: '3.11.5'
cache: 'pip'
# make sure 'smartthings' is available to child processes
- name: Set Windows Path
if: runner.os == 'Windows'
run: Add-Content $env:GITHUB_PATH "${{ github.workspace }}\packages\cli\dist_bin\win\x64"
- name: Set macOS Path
if: runner.os == 'macOS'
run: echo "$GITHUB_WORKSPACE/packages/cli/dist_bin/macos/x64" >> $GITHUB_PATH
- name: Set Linux Path
if: runner.os == 'Linux'
run: echo "$GITHUB_WORKSPACE/packages/cli/dist_bin/linux/x64" >> $GITHUB_PATH
- name: Install Dependencies and Run Tests
run: |
python -m pip install --force-reinstall -v pip==23.3.1
pip install -r requirements.txt
pytest
working-directory: packages/cli/functional-tests
github-release:
needs: [release, package]
if: needs.release.outputs.cli-released == 'true'
name: Create Github Release
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Download Artifacts
uses: actions/download-artifact@v3
with:
name: dist_bin
- name: Extract Artifacts
run: tar -xvf dist_bin.tar
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18.5.0
- run: npm ci
# hack since Github auto generated notes aren't working right now
- name: Generate Github Release Notes
run: node generate-release-notes.mjs ${{ needs.release.outputs.cli-version }}
- name: Create Github Release
uses: softprops/action-gh-release@v1
with:
name: ${{ needs.release.outputs.cli-version }}
body_path: ${{ github.workspace }}/RELEASE_NOTES.txt
tag_name: ${{ needs.release.outputs.cli-tag }}
prerelease: false
files: 'packages/cli/dist_bin/**/*.@(tar.gz|zip)'
homebrew-formula:
needs: [release, github-release]
if: needs.release.outputs.cli-released == 'true'
name: Bump Homebrew Formula
runs-on: macos-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Configure Git Identity
uses: Homebrew/actions/git-user-config@master
with:
username: smartthingspi
- name: Tap Formula Repo
run: brew tap smartthingscommunity/smartthings
- name: Bump Formula
uses: Homebrew/actions/bump-formulae@master
with:
token: ${{ secrets.HOMEBREW_COMMITTER_TOKEN }}
formulae: smartthingscommunity/smartthings/smartthings
windows-installer:
needs: [release, package, github-release]
if: needs.release.outputs.cli-released == 'true'
name: Release Windows Installer
# ensure WiX Toolset is installed on image before updating runner
# ex: https://github.com/actions/virtual-environments/blob/b87bdfb146bdd41a98f33fc9572a961e9a60e9dd/images/win/Windows2022-Readme.md
runs-on: windows-2022
steps:
- name: Print needs.release.outputs.cli-version
run: Write-Output ${{ needs.release.outputs.cli-version }}
# remove any pre-release labels since WiX doesn't support them
- name: Sanitize CLI Version String
id: safe-semver
run: echo "version=$('${{ needs.release.outputs.cli-version }}'.Split('-') | Select-Object -Index 0)" >> $env:GITHUB_OUTPUT
- name: Print steps.safe-semver.outputs.version
run: Write-Output ${{ steps.safe-semver.outputs.version }}
- name: Checkout Repo
uses: actions/checkout@v3
- name: Download Artifacts
uses: actions/download-artifact@v3
with:
name: dist_bin
- name: Extract Artifacts
run: tar -xvf dist_bin.tar
- run: mv packages\cli\dist_bin\win\x64\smartthings.exe packages\cli\wix
# https://github.community/t/set-path-for-wix-toolset-in-windows-runner/154708/2
# https://stackoverflow.com/a/71579543
- name: Add WiX Toolset to Path
run: Add-Content $env:GITHUB_PATH "C:\Program Files (x86)\WiX Toolset v3.11\bin"
- name: Compile WiX file
run: candle.exe smartthings.wxs -ext WixUIExtension
working-directory: packages\cli\wix
env:
SMARTTHINGS_SEMVER: ${{ steps.safe-semver.outputs.version }}
# must be absolute path or relative to .wxs file
SMARTTHINGS_BINARY_PATH: .\smartthings.exe
- name: Build .msi
run: light.exe -out smartthings.msi smartthings.wixobj -ext WixUIExtension
working-directory: packages\cli\wix
- name: Add .msi Artifact to Github Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.release.outputs.cli-tag }}
files: packages/cli/wix/smartthings.msi