-
Notifications
You must be signed in to change notification settings - Fork 1
237 lines (207 loc) · 6.75 KB
/
ci-cd.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
name: CI/CD
on:
push:
tags:
- 'v*'
branches-ignore:
- dependabot/**
- actions/**
paths:
- src/**
- tests/**
- i18n/**
- data/types
- .github/workflows/ci-cd.yml
- package.json
- package-lock.json
pull_request:
jobs:
build:
name: Build Deputy
if: ${{ !contains(github.event.head_commit.message, '[failing]') }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: true
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: ^20.11
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
env:
NODE_ENV: production
- name: Upload transpiled code
uses: actions/upload-artifact@v4
with:
name: builds
path: build/*.js
- name: Upload sourcemaps
uses: actions/upload-artifact@v4
with:
name: sourcemaps
path: build/*.js.map
tests:
name: Perform tests
needs: build
strategy:
fail-fast: false
matrix:
os: [ windows-latest, ubuntu-latest ]
browser:
# Chrome stable
- product: chrome
version: stable
# Chrome Canary
- product: chrome
version: canary
# Firefox stable
- product: firefox
version: latest
# Firefox beta
- product: firefox
version: latest-beta
# Firefox ESR
- product: firefox
version: latest-esr
runs-on: ${{ matrix.os }}
if: ${{ !contains(github.event.head_commit.message, '[failing]') }}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}--${{ matrix.os }}-${{ matrix.browser.product }}-${{ matrix.browser.version }}
cancel-in-progress: true
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Firefox
if: matrix.browser.product == 'firefox'
uses: browser-actions/setup-firefox@latest
with:
firefox-version: ${{ matrix.browser.version }}
- name: Install geckodriver
if: matrix.browser.product == 'firefox'
uses: browser-actions/setup-geckodriver@latest
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Install chromedriver
if: matrix.browser.product == 'chrome'
uses: nanasess/setup-chromedriver@v2
- name: Setup Node
if: matrix.browser.product != 'firefox' || matrix.os != 'windows-latest'
uses: actions/setup-node@v4
with:
node-version: ^20.11
cache: 'npm'
- name: Install dependencies
run: npm ci
env:
NODE_ENV: development
- name: Download transpiled code
uses: actions/download-artifact@v4
with:
name: builds
path: build/
- name: Download sourcemaps
uses: actions/download-artifact@v4
with:
name: sourcemaps
path: build/
- name: Run tests
run: npm run test:jest
env:
BROWSER: ${{ matrix.browser.product }}
- name: Upload test artifacts
uses: actions/upload-artifact@v4
with:
name: test-artifacts--${{ matrix.os }}-${{ matrix.browser.product }}-${{ matrix.browser.version }}
path: tests/artifacts/*
release:
name: Draft release
needs: tests
runs-on: ubuntu-latest
if: ${{ startsWith( github.ref, 'refs/tags/v' ) }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
path: repo/
- name: Download transpiled code
uses: actions/download-artifact@v4
with:
name: builds
path: artifacts/
- name: Download sourcemaps
uses: actions/download-artifact@v4
with:
name: sourcemaps
path: artifacts/
- name: Extract CHANGELOG section
run: |
cat repo/CHANGELOG.md | node -p "require('fs').readFileSync(0).toString('utf-8').match(/# [\s\S]+?(?=\s#\s)/g)[1].trim().split('\n').slice(1).join('\n')" > CHANGELOG_EXTRACT.md
- name: Read CHANGELOG extract
id: changelog
uses: juliangruber/read-file-action@v1
with:
path: ./CHANGELOG_EXTRACT.md
- name: Check if CHANGELOG is formed
if: ${{ !contains( steps.changelog.outputs.content, 'deputy/compare/' ) }}
uses: actions/github-script@v7
with:
script: |
core.setFailed('CHANGELOG.md does not have a comparison link. Are there still parts in Unreleased?')
- name: Draft release
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
name: ${{ github.ref_name }}
prerelease: ${{ contains( github.ref_name, '-rc' ) }}
makeLatest: ${{ !contains( github.ref_name, '-rc' ) }}
draft: true
body: ${{ steps.changelog.outputs.content }}
artifacts: "artifacts/*"
allowUpdates: true
replacesArtifacts: true
deploy:
name: Deploy (English Wikipedia)
needs: tests
runs-on: ubuntu-latest
environment: en.wikipedia
# `main` branch or version release only
if: ${{ (
startsWith( github.ref, 'refs/tags/v' ) || github.ref == 'refs/heads/main'
) && github.event.head_commit.author.name != 'dependabot[bot]' }}
concurrency:
group: deploy-en.wikipedia
cancel-in-progress: true
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download transpiled code
uses: actions/download-artifact@v4
with:
name: builds
- name: Wipe sourcemap references
run: sed -i 's/\/\/# sourceMappingURL=.*//' deputy*.js
- name: Get edit summary
id: edit-summary
run: |
if [ $GITHUB_REF == refs/tags/v* ]; then
echo "message=$(git show -s --format="[%h] %s" $GITHUB_REF)" >> $GITHUB_OUTPUT
else
TAG=$(echo $GITHUB_REF | sed -E 's/^refs\/tags\/(.*)\/.*/\1/')
echo "message=$TAG; https://github.com/ChlodAlejandro/deputy/releases/tag/$TAG " >> $GITHUB_OUTPUT
fi
- name: Deploy to Wikipedia
uses: wikimedia-gadgets/deploy-action@v1.1.0
with:
paths: |
deputy.js User:Chlod/Scripts/Deputy.js
deputy-ante.js User:Chlod/Scripts/Deputy/AttributionNoticeTemplateEditor.js
deputy-ia.js User:Chlod/Scripts/Deputy/InfringementAssistant.js
apiUrl: 'https://en.wikipedia.org/w/api.php'
oauth2Token: ${{ secrets.OAUTH_ACCESS_TOKEN }}
editSummary: '${{ steps.edit-summary.output.message }} (bot/CD)'