-
Notifications
You must be signed in to change notification settings - Fork 26
246 lines (206 loc) · 10.5 KB
/
ci.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
name: CI
on:
push:
pull_request:
schedule:
# https://crontab.guru/#3_21_*_*_6
- cron: "3 21 * * 6"
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/[email protected]
with:
node-version: "18"
- name: Install system dependencies
run: sudo apt update && sudo apt-get -y install libusb-1.0-0-dev libasound2-dev libudev-dev
- name: Install nodejs dependencies
run: npm ci
- name: Build TS
run: npm run build
- name: Create tar with compilation results
run: |
shopt -s globstar
tar cvzf compilation-results.tar.gz --exclude "node_modules" **/*.js **/*.js.map **/*.d.ts **/*.d.ts.map **/*.tsbuildinfo **/*.ttf
- name: Upload compilation results
uses: actions/upload-artifact@v4
with:
name: compilation-results
path: compilation-results.tar.gz
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/[email protected]
with:
node-version: "18"
- name: Install system dependencies
run: sudo apt update && sudo apt-get -y install libusb-1.0-0-dev libasound2-dev libudev-dev
- name: Install nodejs dependencies
run: npm ci
- name: Run tests
run: npm run coverage -- --verbose
nodecg:
# This test runs with the current version of NodeCG as defined by the
# nodecg-cli. It checks if all bundles (only core, services, samples)
# are mounted by NodeCG. It will fail if one of them is not mounted.
# You may check for other NodeCG runtime errors in the output (these
# may not fail the run).
strategy:
matrix:
os: [ubuntu-22.04, ubuntu-20.04, windows-2019]
runs-on: ${{ matrix.os }}
continue-on-error: true
steps:
- uses: actions/[email protected]
with:
node-version: "18"
- name: Download NodeCG
uses: actions/checkout@v4
with:
repository: nodecg/nodecg
- name: Get NodeCG commit hash
id: nodecgHash
shell: bash
run: echo "NODECG_HASH=$(git rev-parse HEAD)" >> $GITHUB_ENV
- name: Cache NodeCG dependencies
id: cache-nodecg-deps
uses: actions/cache@v4
with:
path: "node_modules"
key: ${{ runner.os }}-${{ env.NODECG_HASH }}-nodecg-deps
- name: Cache NodeCG compilation outputs
id: cache-nodecg-build
uses: actions/cache@v4
with:
path: "build"
key: ${{ runner.os }}-${{ env.NODECG_HASH }}-nodecg-build
- name: Install NodeCG dependencies
# Only get dependencies if we didn't get them from the cache
if: steps.cache-nodecg-deps.outputs.cache-hit != 'true'
run: npm install
- name: Build NodeCG
# Only build NodeCG if we didn't have cached compilation results
if: steps.cache-nodecg-build.outputs.cache-hit != 'true'
run: npm run build
- name: Setup NodeCG config linux
if: (matrix.os == 'ubuntu-22.04' || matrix.os == 'ubuntu-20.04')
run: |
mkdir cfg
echo '{"bundles": {"paths": ["'${GITHUB_WORKSPACE}'/nodecg-io","'${GITHUB_WORKSPACE}'/nodecg-io/services","'${GITHUB_WORKSPACE}'/nodecg-io/samples"]}}' > ./cfg/nodecg.json
- name: Setup NodeCG config windows
if: matrix.os == 'windows-2019'
shell: bash
run: |
mkdir cfg
# We need to escape backslashes to get valid json. Replaces each "\" with "\\"
echo '{"bundles": {"paths": ["'${GITHUB_WORKSPACE//\\/\\\\}'\\nodecg-io","'${GITHUB_WORKSPACE//\\/\\\\}'\\nodecg-io\\services","'${GITHUB_WORKSPACE//\\/\\\\}'\\nodecg-io\\samples"]}}' > ./cfg/nodecg.json
- uses: actions/checkout@v4
with:
path: "nodecg-io"
- name: Install system dependencies
if: (matrix.os == 'ubuntu-22.04' || matrix.os == 'ubuntu-20.04')
run: sudo apt update && sudo apt-get -y install libusb-1.0-0-dev libasound2-dev libudev-dev
- name: Temp patch \#1030 (ubuntu 22.04) – Removing midi services / samples
working-directory: ./nodecg-io
if: matrix.os == 'ubuntu-22.04'
run: |
sudo rm -rf ./services/nodecg-io-midi-*
sudo rm -rf ./samples/midi-*
- name: Install node native development files
shell: bash
run: npx node-gyp install
- name: Install nodejs dependencies
run: npm ci
working-directory: ./nodecg-io
- name: Build Typescript
run: npm run build
working-directory: ./nodecg-io
# Under linux we need to run the test as the root user because
# the midi service requires access to audio devices.
# By default the GitHub Actions user is not in the `audio` group and therefore
# has no access. Either we need to run as root to get access or need to add the user
# to the `audio` group which doesn't work for us, as it would only take affect on next login,
# but we cannot logout and login in CI.
- name: Run test (ubuntu)
if: (matrix.os == 'ubuntu-22.04' || matrix.os == 'ubuntu-20.04')
run: sudo node .scripts/ci-nodecg-integration.mjs
working-directory: ./nodecg-io
- name: Run test (windows)
if: matrix.os == 'windows-2019'
shell: bash
run: node .scripts/ci-nodecg-integration.mjs
working-directory: ./nodecg-io
publish:
runs-on: ubuntu-latest
name: Publish compilation results
# Don't run this in forks. This pushes to our separate repository that external contributors don't have access to.
# We also only want to publish if we have pushed a branch, not on a pull request. Otherwise we would publish everything twice.
if: startsWith(github.repository, 'codeoverflow-org') && github.actor != 'dependabot[bot]' && github.event_name != 'pull_request' && github.ref_type != 'tag'
# Only publish anything if we're sure this version compiles (obviously) and all tests pass.
needs:
- build
- tests
- nodecg
steps:
- uses: actions/checkout@v4
- uses: actions/[email protected]
with:
node-version: "18"
- name: Download compilation results # From the build step
uses: actions/download-artifact@v4
with:
name: compilation-results
- name: Extract compilation results
run: tar xvf compilation-results.tar.gz
# All twitch services depend on the utility package `nodecg-io-twitch-auth`.
# In the repository the services depend on the latest development version which is not yet published.
# If someone installs the service using the published tarball npm would try to get the
# unpublished version of twitch-auth from the npm registry which is not possible.
# To fix this we update the version of the twitch-auth package in all usages
# to also reference the published tarball.
- name: Patch twitch-auth dependency to use published current tarball
run: |
# Get current version as it is needed for the tarball file name
TWITCH_AUTH_VERSION=$(cat utils/nodecg-io-twitch-auth/package.json | jq .version -r)
# Find usages in all package.json files and replace with the corresponding tarball url
find . -name 'package.json' -exec grep -q -E '"nodecg-io-twitch-auth": ".+"' {} \; -print # Print found files for debug purposes
find . -name 'package.json' -exec grep -q -E '"nodecg-io-twitch-auth": ".+"' {} \; -print0 | \
xargs -0 sed -i "s/\"nodecg-io-twitch-auth\": \".*\"/\"nodecg-io-twitch-auth\": \"https:\/\/codeoverflow-org.github.io\/nodecg-io-publish\/nodecg-io-twitch-auth-${TWITCH_AUTH_VERSION}.tgz\"/g"
- name: Create npm tarballs
run: npm pack --workspaces
- name: Clone publish repository
uses: actions/checkout@v4
with:
repository: codeoverflow-org/nodecg-io-publish
ssh-key: ${{ secrets.PUBLISH_SSH_KEY }}
path: publish
- name: Checkout branch in publish repository
working-directory: publish
# Create a local branch with the same name as in the nodecg-io repository
# If the branch already exists on the remote we set the upstream to it,
# if not we push the branch and set the upstream to it as well.
run: |
git fetch
git switch ${GITHUB_REF##refs/heads/} || (git checkout -b ${GITHUB_REF##refs/heads/} && git push -u origin ${GITHUB_REF##refs/heads/})
- name: Clear publish directory
run: rm -rf publish/*
- name: Copy tarballs into publish directory
run: cp *.tgz publish
- name: Extract tarballs
working-directory: publish
run: |
for tarPath in $(ls *.tgz); do
tar xf $tarPath package;
dirname=$(echo "$tarPath" | sed "s/-[0-9]\+\.[0-9]\+\.[0-9]\+\.tgz//"); # Strip away tgz extension and version
mv package $dirname;
done;
- name: Publish
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Publish codeoverflow-org/nodecg-io@${{ github.sha }}
commit_user_name: codeoverflow-org
commit_user_email: ""
commit_author: codeoverflow-org <>
repository: publish