-
Notifications
You must be signed in to change notification settings - Fork 100
369 lines (315 loc) · 12.7 KB
/
ci.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
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
name: WebExtension Lint, Build, Release, Publish
on:
push:
branches:
- master
- dev
pull_request:
types:
- opened
- synchronize
- reopened
- labeled
workflow_dispatch:
inputs:
branch:
type: choice
description: "Branch"
options:
- nightly
- stable
default: nightly
store-upload:
type: boolean
default: false
description: "Upload to CWS/AMO"
deploy:
type: boolean
default: false
description: "Deploy Hosted Build"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.branch }}
env:
ARTIFACT_NAME: 7tv-webextension
EXTENSION_ID_CWS: ammjkodgmmoknidbanneddgankgfejfh
EXTENSION_ID_AMO: "[email protected]"
NIGHTLY_EXTENSION_ID_CWS: fphegifdehlodcepfkgofelcenelpedj
NIGHTLY_EXTENSION_ID_AMO: "[email protected]"
IS_MASTER_COMMIT: ${{ github.event_name == 'push' && github.ref_type == 'branch' && github.ref_name == 'master' }}
jobs:
ci:
name: WebExtension Lint, Build, Test
runs-on: ubuntu-latest
env:
installable: ${{ secrets.WEB_EXTENSION_CRX }}
concurrency:
group: ${{ github.workflow }}-ci-${{ github.ref }}
cancel-in-progress: true
steps:
- uses: actions/setup-node@v3
with:
node-version: "18"
- name: Install Yarn
run: npm install -g yarn
- name: Checkout code
uses: actions/checkout@v3
- name: Node Modules Cache
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('yarn.lock') }}
- name: Install Dependencies
run: |
yarn
- name: Run Linter
run: yarn lint
- name: Build App
env:
BRANCH: ${{ (inputs.branch != 'stable' && 'nightly') || '' }}
EXTENSION_ID_MOZ: ${{ (inputs.branch == 'stable' && env.EXTENSION_ID_AMO) || env.NIGHTLY_EXTENSION_ID_AMO }}
run: |
OUT_DIR=mv3 yarn build:prod
OUT_DIR=mv2 MOZILLA_ID=${{ env.EXTENSION_ID_MOZ }} MV2=true yarn build:prod
- name: Create Build Archives
run: |
apt-get update && apt-get install -y zip
cd dist/mv3 && zip -r ../mv3.zip . && cd ../../
cd dist/mv2 && zip -r ../mv2.zip .
# CRX is Chromium installer
- name: Create CRX (Chromium)
if: ${{ env.installable }}
uses: cardinalby/webext-buildtools-chrome-crx-action@v2
with:
zipFilePath: dist/mv3.zip
crxFilePath: dist/ext.crx
privateKey: ${{ secrets.WEB_EXTENSION_CRX }}
# XPI is Firefox installer
- name: Create XPI (Firefox)
if: ${{ env.installable }}
id: web-ext-build
uses: kewisch/action-web-ext@v1
with:
cmd: build
source: dist/mv2
filename: ext.xpi
- name: Move XPI (Firefox)
if: ${{ env.installable }}
run: mv ${{ steps.web-ext-build.outputs.target }} dist/ext.xpi
- name: Structure Files
run: |
mkdir -p dist/manifest
cp dist/mv2/manifest.json dist/manifest/manifest.mv2.json
cp dist/mv3/manifest.json dist/manifest/manifest.mv3.json
- name: "Upload Artifact: Installable"
if: ${{ env.installable }}
uses: actions/upload-artifact@v3
with:
name: installable
retention-days: 60
path: |
dist/ext.crx
dist/ext.xpi
- name: "Upload Artifact: Unpacked"
uses: actions/upload-artifact@v3
with:
name: build
retention-days: 60
path: |
dist/mv3.zip
dist/mv2.zip
- name: Upload Manifest
uses: actions/upload-artifact@v3
with:
name: manifest
path: dist/manifest
release:
name: Create Release
runs-on: ubuntu-latest
needs: [ci]
if: ${{ (inputs.branch) || (github.event_name == 'push' && github.ref_type == 'branch' && github.ref_name == 'master') }}
steps:
- uses: actions/checkout@v3
- name: Download Artifact
uses: actions/download-artifact@v3
with:
name: build
path: ext
- name: Download Artifact
uses: actions/download-artifact@v3
with:
name: installable
path: ext
- name: File Names
run: |
cd ext/
for file in *; do
mv "$file" "7tv-webextension-$file"
done
- run: |
echo 'PACKAGE_JSON<<EOF' >> $GITHUB_ENV
cat ./package.json >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- name: Define Release Tag
id: release-tag
run: |
echo "VERSION=${{ fromJson(env.PACKAGE_JSON).version }}" >> $GITHUB_OUTPUT
echo "DEV_VERSION=${{ fromJson(env.PACKAGE_JSON).dev_version }}" >> $GITHUB_OUTPUT
if [[ "${{ inputs.branch == 'nightly' || env.IS_MASTER_COMMIT == 'true' }}" == "true" ]]; then
echo "RELEASE_TAG=nightly-release" >> $GITHUB_OUTPUT
exit 0
fi
echo "RELEASE_TAG=${{ format('v{0}', fromJson(env.PACKAGE_JSON).version) }}" >> $GITHUB_OUTPUT
- name: Create Nightly Release
if: ${{ inputs.branch == 'nightly' || env.IS_MASTER_COMMIT == 'true' }}
id: create_nightly_release
uses: ncipollo/[email protected]
with:
removeArtifacts: true
allowUpdates: true
artifactErrorsFailBuild: true
artifacts: "ext/*"
body: ${{ github.event.head_commit.message }}
prerelease: true
name: Nightly Release
tag: ${{ steps.release-tag.outputs.RELEASE_TAG }}
- name: Update Nightly Tag
if: ${{ inputs.branch == 'nightly' || env.IS_MASTER_COMMIT == 'true' }}
run: |
git tag -f nightly-release
git push -f origin nightly-release
- name: Create Release
if: ${{ inputs.branch == 'stable' }}
id: create_release
uses: ncipollo/[email protected]
with:
artifactErrorsFailBuild: true
artifacts: "ext/*"
allowUpdates: true
prerelease: false
draft: true
omitBodyDuringUpdate: true
omitDraftDuringUpdate: true
omitNameDuringUpdate: true
omitPrereleaseDuringUpdate: true
replacesArtifacts: true
body: ${{ github.event.head_commit.message }}
name: ${{ steps.release-tag.outputs.RELEASE_TAG }}
tag: ${{ steps.release-tag.outputs.RELEASE_TAG }}
outputs:
release_tag: ${{ steps.release-tag.outputs.RELEASE_TAG }}
version: ${{ steps.release-tag.outputs.VERSION }}
dev_version: ${{ steps.release-tag.outputs.DEV_VERSION }}
deploy:
name: Deploy Hosted Build
runs-on: ubuntu-latest
needs: [ci, release]
if: ${{ inputs.deploy || (github.event_name == 'push' && github.ref_type == 'branch' && github.ref_name == 'master') }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "18"
- name: Install Yarn
run: npm install -g yarn
- name: Install Dependencies
run: |
yarn
- name: Build (Hosted)
env:
BRANCH: ${{ (inputs.branch != 'stable' && 'nightly') || '' }}
run: |
yarn build-hosted:prod
- name: Upload to Host
uses: shallwefootball/s3-upload-action@master
with:
endpoint: ${{ secrets.R2_API_ENDPOINT }}
aws_key_id: ${{ secrets.R2_API_AK }}
aws_secret_access_key: ${{ secrets.R2_API_SECRET }}
aws_bucket: 7tv-extension
source_dir: "dist-hosted/"
destination_dir: ""
push:
name: Submit to CWS / Sign XPI
runs-on: aws-runner
needs: [ci, release]
if: ${{ inputs.store-upload && inputs.branch }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: "18"
# Retrieve the non-CRX MV3 zip to be uploaded to CWS
- name: Download Artifact (Build)
uses: actions/download-artifact@v3
with:
name: build
path: ext
- name: Download Artifact (Installable)
uses: actions/download-artifact@v3
with:
name: installable
path: ext
# Get the XPI File for Firefox
# It will be uploaded to AMO
- name: Download Manifest
uses: actions/download-artifact@v3
with:
name: manifest
path: manifest
- name: CLI Setup
run: |
npm install -g chrome-webstore-upload-cli
- name: Upload to CWS
continue-on-error: true
env:
CREDENTIALS: ${{ secrets.CWS }}
EXTENSION_ID: ${{ (inputs.branch == 'stable' && env.EXTENSION_ID_CWS) || env.NIGHTLY_EXTENSION_ID_CWS }}
run: |
echo "${{ env.CREDENTIALS }}" >> c
chrome-webstore-upload upload \
--source ext/mv3.zip \
--extension-id $EXTENSION_ID \
--client-id "$(sed '1q;d' c)" \
--client-secret "$(sed '2q;d' c)" \
--refresh-token "$(sed '3q;d' c)"
- name: Copy Unsigned XPI
run: |
cp ext/ext.xpi ext/ext-signable.xpi
mkdir web-ext-artifacts/
- name: Sign XPI (Firefox)
id: xpi-sign
continue-on-error: true
uses: kewisch/action-web-ext@v1
with:
cmd: sign
source: ext/ext-signable.xpi
channel: unlisted
apiKey: ${{ secrets.AMO_API_KEY }}
apiSecret: ${{ secrets.AMO_API_SECRET }}
timeout: 900000
- name: Move Signed XPI (Firefox)
if: ${{ steps.xpi-sign.outputs.target }}
run: mv ${{ steps.xpi-sign.outputs.target }} ext/ext-signed.xpi
- name: "Upload Artifact: Signed XPI"
if: ${{ steps.xpi-sign.outputs.target }}
uses: actions/upload-artifact@v3
with:
name: installable
retention-days: 60
path: |
ext/ext-signed.xpi
- name: "Rename Signed Artifact"
if: ${{ steps.xpi-sign.outputs.target }}
run: cp ext/ext-signed.xpi ext/7tv-webextension-ext-signed.xpi
- name: Update Release
if: ${{ steps.xpi-sign.outputs.target && needs.release.outputs.release_tag }}
uses: ncipollo/[email protected]
with:
allowUpdates: true
artifacts: "ext/7tv-webextension-ext-signed.xpi"
body: ${{ github.event.head_commit.message }}
omitNameDuringUpdate: true
omitPrereleaseDuringUpdate: true
omitDraftDuringUpdate: true
omitBodyDuringUpdate: true
tag: ${{ needs.release.outputs.release_tag }}