-
-
Notifications
You must be signed in to change notification settings - Fork 8
365 lines (316 loc) · 17 KB
/
extension.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
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
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
# MPC_PRODUCT_ID (v3) c5bd8ac5-4b9b-4aa2-8cdb-dd91b6e22a5d, (v2) 2eb9e4aa-4247-4a90-8f11-39c25390f701
# GOOGLE_APP_ID (v3) fbbpbfibkcdehkkkcoileebbgbamjelh, (v2) gnhhdgbaldcilmgcpfddgdbkhjohddkj
name: extension
on:
workflow_dispatch:
push:
tags:
- '*'
branches: ['main']
paths-ignore:
- '.github/**'
pull_request:
branches: ['main']
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci --legacy-peer-deps
- run: npm run build --if-present
- run: cat manifest.json
- name: Cache build files
uses: actions/cache@v4
id: build-cache
with:
path: |
dist
src
manifest.json
_locales
key: nim-cache-build-${{ github.sha }}
test:
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x]
shard: [1, 2, 3, 4, 5]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Restore cache build files
uses: actions/cache@v4
id: build-cache
with:
path: |
dist
src
manifest.json
_locales
key: nim-cache-build-${{ github.sha }}
- run: npm ci --legacy-peer-deps
- name: Update system (Ubuntu)
if: matrix.os == 'ubuntu-20.04' || matrix.os == 'ubuntu-18.04'
run: sudo apt update && sudo apt upgrade -y
- run: npx playwright install-deps
- run: npx playwright install
- run: xvfb-run npm run test -- --shard=${{ matrix.shard }}/${{ strategy.job-total }}
package:
needs: build
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Restore cache build files
uses: actions/cache@v4
id: build-cache
with:
path: |
dist
src
manifest.json
_locales
key: nim-cache-build-${{ github.sha }}
- name: Set zip name
run: echo "ZIP_NAME=$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_ENV
- name: Zip
run: zip -r ${ZIP_NAME}.zip ./dist ./src/*.js ./manifest.json ./_locales
shell: bash
- name: Upload zip artifact
uses: actions/upload-artifact@v4
with:
path: ${{ env.ZIP_NAME }}.zip
post-package-test:
needs: package
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x]
shard: [1, 2, 3, 4, 5]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Download package
uses: actions/download-artifact@v4
with:
path: '/tmp'
- name: Unzip
run: unzip /tmp/artifact/*.zip -d /tmp/artifact
- name: Set PATH_TO_EXTENSION env
run: echo "PATH_TO_EXTENSION=/tmp/artifact" >> $GITHUB_ENV
- run: npm ci --legacy-peer-deps
- run: npx playwright install-deps
- run: npx playwright install
- run: ls ${{env.PATH_TO_EXTENSION}}
- run: export PATH_TO_EXTENSION=${{env.PATH_TO_EXTENSION}} && xvfb-run npm run test:post -- --shard=${{ matrix.shard }}/${{ strategy.job-total }}
deploy-edge:
needs: post-package-test
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Download package
uses: actions/download-artifact@v4
with:
path: '/tmp'
- name: Set zip name
run: echo "ZIP_NAME=$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_ENV
- name: Publish using Microsoft Partner Center Publish API (V2)
run: |
certificationNotes=$(echo "{
\"notes\": \"Submitted via GitHub Actions. Commit: $GITHUB_SHA on ref: $GITHUB_REF\"
}")
ls -laR /tmp/artifact
response=$(curl https://login.microsoftonline.com/5c9eedce-81bc-42f3-8823-48ba6258b391/oauth2/v2.0/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "client_id=${{ vars.MPC_CLIENT_ID }}" \
-d "scope=https://api.addons.microsoftedge.microsoft.com/.default" \
-d "client_secret=${{ secrets.MPC_CLIENT_SECRET }}" \
-d "grant_type=client_credentials")
token=$(echo $response | jq -r '.access_token')
# Uploading a package to update an existing submission
echo "Uploading a package to update an existing submission"
response=$(curl -s -i -D /tmp/headers -w 'status: %{response_code}\n' -X POST https://api.addons.microsoftedge.microsoft.com/v1/products/${{ vars.MPC_PRODUCT_ID_V2 }}/submissions/draft/package \
-H "Authorization: Bearer $token" \
-H 'Content-Type: application/zip' \
-T /tmp/artifact/${{ env.ZIP_NAME }}.zip)
if [ -n "$(echo $response | egrep "status:\s*202")" ]; then
operationID=$(cat /tmp/headers | egrep -i "location:\s*" | cut -f2 -d":" | awk '{$1=$1};1' | tr -d '\r')
# Checking the status of a package upload
echo "Checking the status of a package upload"
response=$(curl -s -w 'status: %{response_code}\n' -o /dev/null https://api.addons.microsoftedge.microsoft.com/v1/products/${{ vars.MPC_PRODUCT_ID_V2 }}/submissions/draft/package/operations/$operationID \
-H "Authorization: Bearer $token")
echo $response
retries=0
while [ -z $(echo $response | egrep "status:\s*200")]; do
if [ $retries -gt 10 ]; then
echo "Exiting (Checking the status of a package upload) after 10 retries!"
exit 1
fi
sleep 5
response=$(curl -w 'status: %{response_code}\n' -v https://api.addons.microsoftedge.microsoft.com/v1/products/${{ vars.MPC_PRODUCT_ID_V2 }}/submissions/draft/package/operations/$operationID \
-H "Authorization: Bearer $token")
retries=$(($retries+1))
done
# Publishing the submission
echo "Publishing the submission"
response=$(curl -s -i -D /tmp/headers2 -w 'status: %{response_code}\n' -o /dev/null https://api.addons.microsoftedge.microsoft.com/v1/products/${{ vars.MPC_PRODUCT_ID_V2 }}/submissions \
-H "Authorization: Bearer $token" \
-d "$certificationNotes")
if [ -n "$(echo $response | egrep "status:\s*202")" ]; then
operationID=$(cat /tmp/headers2 | egrep -i "location:\s*" | cut -f2 -d":" | awk '{$1=$1};1' | tr -d '\r')
# Checking the publishing status
response=$(curl -s -w 'status: %{response_code}\n' -o /dev/null https://api.addons.microsoftedge.microsoft.com/v1/products/${{ vars.MPC_PRODUCT_ID_V2 }}/submissions/operations/$operationID \
-H "Authorization: Bearer $token")
retries=0
while [ -z $(echo $response | egrep "status:\s*200")]; do
if [ $retries -gt 10 ]; then
echo "Exiting (Checking the publishing status) after 10 retries!"
exit 1
fi
sleep 5
response=$(curl -w 'status: %{response_code}\n' -v https://api.addons.microsoftedge.microsoft.com/v1/products/${{ vars.MPC_PRODUCT_ID_V2 }}/submissions/operations/$operationID \
-H "Authorization: Bearer $token")
retries=$(($retries+1))
done
fi
else
echo "Package upload failed"
echo $response
exit 1
fi
exit 0
shell: bash
- name: Publish using Microsoft Partner Center Publish API (V3)
run: |
certificationNotes=$(echo "{
\"notes\": \"Submitted via GitHub Actions. Commit: $GITHUB_SHA on ref: $GITHUB_REF\"
}")
ls -laR /tmp/artifact
response=$(curl https://login.microsoftonline.com/5c9eedce-81bc-42f3-8823-48ba6258b391/oauth2/v2.0/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "client_id=${{ vars.MPC_CLIENT_ID }}" \
-d "scope=https://api.addons.microsoftedge.microsoft.com/.default" \
-d "client_secret=${{ secrets.MPC_CLIENT_SECRET }}" \
-d "grant_type=client_credentials")
token=$(echo $response | jq -r '.access_token')
# Uploading a package to update an existing submission
echo "Uploading a package to update an existing submission"
response=$(curl -s -i -D /tmp/headers -w 'status: %{response_code}\n' -X POST https://api.addons.microsoftedge.microsoft.com/v1/products/${{ vars.MPC_PRODUCT_ID_V3 }}/submissions/draft/package \
-H "Authorization: Bearer $token" \
-H 'Content-Type: application/zip' \
-T /tmp/artifact/${{ env.ZIP_NAME }}.zip)
if [ -n "$(echo $response | egrep "status:\s*202")" ]; then
operationID=$(cat /tmp/headers | egrep -i "location:\s*" | cut -f2 -d":" | awk '{$1=$1};1' | tr -d '\r')
# Checking the status of a package upload
echo "Checking the status of a package upload"
response=$(curl -s -w 'status: %{response_code}\n' -o /dev/null https://api.addons.microsoftedge.microsoft.com/v1/products/${{ vars.MPC_PRODUCT_ID_V3 }}/submissions/draft/package/operations/$operationID \
-H "Authorization: Bearer $token")
echo $response
retries=0
while [ -z $(echo $response | egrep "status:\s*200")]; do
if [ $retries -gt 10 ]; then
echo "Exiting (Checking the status of a package upload) after 10 retries!"
exit 1
fi
sleep 5
response=$(curl -w 'status: %{response_code}\n' -v https://api.addons.microsoftedge.microsoft.com/v1/products/${{ vars.MPC_PRODUCT_ID_V3 }}/submissions/draft/package/operations/$operationID \
-H "Authorization: Bearer $token")
retries=$(($retries+1))
done
# Publishing the submission
echo "Publishing the submission"
response=$(curl -s -i -D /tmp/headers2 -w 'status: %{response_code}\n' -o /dev/null https://api.addons.microsoftedge.microsoft.com/v1/products/${{ vars.MPC_PRODUCT_ID_V3 }}/submissions \
-H "Authorization: Bearer $token" \
-d "$certificationNotes")
if [ -n "$(echo $response | egrep "status:\s*202")" ]; then
operationID=$(cat /tmp/headers2 | egrep -i "location:\s*" | cut -f2 -d":" | awk '{$1=$1};1' | tr -d '\r')
# Checking the publishing status
response=$(curl -s -w 'status: %{response_code}\n' -o /dev/null https://api.addons.microsoftedge.microsoft.com/v1/products/${{ vars.MPC_PRODUCT_ID_V3 }}/submissions/operations/$operationID \
-H "Authorization: Bearer $token")
retries=0
while [ -z $(echo $response | egrep "status:\s*200")]; do
if [ $retries -gt 10 ]; then
echo "Exiting (Checking the publishing status) after 10 retries!"
exit 1
fi
sleep 5
response=$(curl -w 'status: %{response_code}\n' -v https://api.addons.microsoftedge.microsoft.com/v1/products/${{ vars.MPC_PRODUCT_ID_V3 }}/submissions/operations/$operationID \
-H "Authorization: Bearer $token")
retries=$(($retries+1))
done
fi
else
echo "Package upload failed"
echo $response
exit 1
fi
exit 0
shell: bash
deploy-chrome:
needs: post-package-test
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Download package
uses: actions/download-artifact@v4
with:
path: '/tmp'
- name: Set zip name
run: echo "ZIP_NAME=$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_ENV
- name: Publish to Google Web Store (V2)
run: |
# Generate a JWT (JSON Web Token)
WEBSTORE_API_URL="https://www.googleapis.com/upload/chromewebstore/v1.1/items/${{vars.GOOGLE_APP_ID_V2}}"
ACCESS_TOKEN=$(curl "https://accounts.google.com/o/oauth2/token" -d "client_id=${{ vars.GOOGLE_CLIENT_ID }}&client_secret=${{ secrets.GOOGLE_CLIENT_SECRET }}&refresh_token=${{ secrets.GOOGLE_REFRESH_TOKEN }}&grant_type=refresh_token&redirect_uri=urn:ietf:wg:oauth:2.0:oob" | jq -r .access_token)
curl -H "Authorization: Bearer ${ACCESS_TOKEN}" -H "x-goog-api-version: 2" -X PUT -T /tmp/artifact/${{ env.ZIP_NAME }}.zip -v "${WEBSTORE_API_URL}"
curl -H "Authorization: Bearer ${ACCESS_TOKEN}" -H "x-goog-api-version: 2" -H "Content-Length: 0" -X POST -v "${WEBSTORE_API_URL}/publish"
shell: bash
- name: Publish to Google Web Store (V3)
run: |
# Generate a JWT (JSON Web Token)
WEBSTORE_API_URL="https://www.googleapis.com/upload/chromewebstore/v1.1/items/${{vars.GOOGLE_APP_ID}}"
ACCESS_TOKEN=$(curl "https://accounts.google.com/o/oauth2/token" -d "client_id=${{ vars.GOOGLE_CLIENT_ID }}&client_secret=${{ secrets.GOOGLE_CLIENT_SECRET }}&refresh_token=${{ secrets.GOOGLE_REFRESH_TOKEN }}&grant_type=refresh_token&redirect_uri=urn:ietf:wg:oauth:2.0:oob" | jq -r .access_token)
curl -H "Authorization: Bearer ${ACCESS_TOKEN}" -H "x-goog-api-version: 2" -X PUT -T /tmp/artifact/${{ env.ZIP_NAME }}.zip -v "${WEBSTORE_API_URL}"
curl -H "Authorization: Bearer ${ACCESS_TOKEN}" -H "x-goog-api-version: 2" -H "Content-Length: 0" -X POST -v "${WEBSTORE_API_URL}/publish"
shell: bash
deploy-github:
needs: post-package-test
runs-on: ubuntu-latest
steps:
- name: Download package
uses: actions/download-artifact@v4
with:
path: '/tmp'
- name: Set zip name
run: echo "ZIP_NAME=$(echo $GITHUB_SHA | cut -c 1-6)" >> $GITHUB_ENV
- name: Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: '/tmp/artifact/${{ env.ZIP_NAME }}.zip'