forked from plussub/plussub
-
Notifications
You must be signed in to change notification settings - Fork 1
142 lines (122 loc) · 4.77 KB
/
build.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
name: build and deploy
on:
push:
workflow_dispatch:
env:
CHROME_APP_ID: gbagdbjhcmodnokmjfhkhagnhgmmpgan
FIREFOX_WEB_EXT_ID: "{fa13934b-65d0-4632-b49e-5e4f6cba9168}"
jobs:
build:
strategy:
matrix:
target: [ "chrome", "firefox" ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '16.x'
- run: npm ci
- run: npm run gen
- run: npm test
- run: npm run tscheck
- run: npm run eslint
- run: npm run build:${{ matrix.target }}
- uses: actions/upload-artifact@v2
with:
name: dist-${{ matrix.target }}
path: dist-${{ matrix.target }}/
deploy-chrome:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
needs:
- build
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v2
with:
name: dist-chrome
- run: zip -r extension.zip .
- id: access_token
run: |
ACCESS_TOKEN=$(curl -s "https://accounts.google.com/o/oauth2/token" -d "client_id=$CHROME_CLIENT_ID&client_secret=$CHROME_CLIENT_SECRET&refresh_token=$CHROME_REFRESH_TOKEN&grant_type=refresh_token&redirect_uri=urn:ietf:wg:oauth:2.0:oob")
# the following lines are only required for multi line json
ACCESS_TOKEN="${ACCESS_TOKEN//'%'/'%25'}"
ACCESS_TOKEN="${ACCESS_TOKEN//$'\n'/'%0A'}"
ACCESS_TOKEN="${ACCESS_TOKEN//$'\r'/'%0D'}"
echo "::set-output name=ACCESS_TOKEN::$ACCESS_TOKEN"
env:
CHROME_CLIENT_ID: ${{ secrets.CHROME_CLIENT_ID }}
CHROME_CLIENT_SECRET: ${{ secrets.CHROME_CLIENT_SECRET }}
CHROME_REFRESH_TOKEN: ${{ secrets.CHROME_REFRESH_TOKEN }}
- run: >
curl -s
-H "Authorization: Bearer $ACCESS_TOKEN"
-H "x-goog-api-version: 2"
-X PUT
-T extension.zip
-v https://www.googleapis.com/upload/chromewebstore/v1.1/items/$APP_ID
env:
APP_ID: ${{ env.CHROME_APP_ID }}
ACCESS_TOKEN: ${{ fromJson(steps.access_token.outputs.ACCESS_TOKEN).access_token }}
- run: >
curl -s
-H "Authorization: Bearer $ACCESS_TOKEN"
-H "x-goog-api-version: 2"
-H "Content-Length: 0"
-X POST
-v https://www.googleapis.com/upload/chromewebstore/v1.1/items/$APP_ID/publish
env:
APP_ID: ${{ env.CHROME_APP_ID }}
ACCESS_TOKEN: ${{ fromJson(steps.access_token.outputs.ACCESS_TOKEN).access_token }}
deploy-firefox:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
needs:
- build
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v2
with:
name: dist-firefox
- run: npx web-ext sign --source-dir ./ || true
env:
WEB_EXT_API_KEY: ${{ secrets.FIREFOX_JWT_ISSUER }}
WEB_EXT_API_SECRET: ${{ secrets.FIREFOX_JWT_SECRET }}
WEB_EXT_ID: ${{ env.FIREFOX_WEB_EXT_ID }}
- run: >
curl
https://github.com/${{ github.repository }}/zipball/${GITHUB_REF#refs/heads/}/
-L
-o extension_src.zip
-v
- run: |
echo "::set-output name=current::$(date +%s)"
echo "::set-output name=later::$(date -d '5 minutes' +%s)"
id: time
- name: JWT Generator
id: firefoxJWT0
uses: morzzz007/[email protected]
with:
secret: ${{ secrets.FIREFOX_JWT_SECRET }}
payload: '{"iss":"${{ secrets.FIREFOX_JWT_ISSUER }}", "jti": "${{ steps.time.outputs.current }}", "iat": ${{ steps.time.outputs.current }}, "exp": ${{ steps.time.outputs.later }} }'
- run: >
curl
-H "Authorization: JWT ${{ steps.firefoxJWT0.outputs.token }}"
https://addons.mozilla.org/api/v5/addons/addon/%7B${{ env.FIREFOX_WEB_EXT_ID }}%7D/versions?filter=all_with_unlisted
-L
-o response.json
-v
- run: echo "::set-output name=latest::$(cat response.json | jq .results[0].id)"
id: version
- name: JWT Generator
id: firefoxJWT1
uses: morzzz007/[email protected]
with:
secret: ${{ secrets.FIREFOX_JWT_SECRET }}
payload: '{"iss":"${{ secrets.FIREFOX_JWT_ISSUER }}", "jti": "${{ steps.time.outputs.current }}", "iat": ${{ steps.time.outputs.current }}, "exp": ${{ steps.time.outputs.later }} }'
- run: >
curl
-H "Authorization: JWT ${{ steps.firefoxJWT1.outputs.token }}"
-X PATCH https://addons.mozilla.org/api/v5/addons/addon/%7B${{ env.FIREFOX_WEB_EXT_ID }}%7D/versions/${{ steps.version.outputs.latest }}/
-F "source=@extension_src.zip"
-L
-v