-
Notifications
You must be signed in to change notification settings - Fork 2
363 lines (299 loc) · 9.67 KB
/
main.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
name: CI/CD
# Enable Buildkit and let compose use it to speed up image building
env:
DOCKER_BUILDKIT: 1
COMPOSE_DOCKER_CLI_BUILD: 1
POETRY_VERSION: 1.8.3 # Make sure this matches the Dockerfile
on:
pull_request:
branches: ["main"]
paths-ignore: ["docs/**"]
push:
branches: ["main"]
paths-ignore: ["docs/**"]
tags:
- "v*"
jobs:
ruff:
runs-on: ubuntu-22.04
steps:
- name: Checkout Code Repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- id: poetry-cache
uses: actions/cache@v4
with:
path: .venv
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
- if: steps.poetry-cache.outputs.cache-hit != 'true'
name: Install Poetry and Dependencies
shell: bash
run: |
pip install --upgrade pip
pip install poetry==$POETRY_VERSION
python -m venv .venv
source .venv/bin/activate
poetry install --with dev
- name: ruff
shell: bash
run: |
source .venv/bin/activate
ruff check . --output-format=github
black:
runs-on: ubuntu-22.04
steps:
- name: Checkout Code Repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- id: poetry-cache
uses: actions/cache@v4
with:
path: .venv
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
- if: steps.poetry-cache.outputs.cache-hit != 'true'
name: Install Poetry and Dependencies
shell: bash
run: |
pip install --upgrade pip
pip install poetry==$POETRY_VERSION
python -m venv .venv
source .venv/bin/activate
poetry install --with dev
- name: black
shell: bash
run: |
source .venv/bin/activate
black . --check
stylelint:
runs-on: ubuntu-22.04
steps:
- name: Checkout Code Repository
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
- id: node-cache
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
- if: steps.node-cache.outputs.cache-hit != 'true'
run: |
npm ci --no-optional --no-audit --progress=false
- name: Stylelint
run: |
npm run lint:style
eslint:
runs-on: ubuntu-22.04
steps:
- name: Checkout Code Repository
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
- id: node-cache
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
- if: steps.node-cache.outputs.cache-hit != 'true'
run: |
npm ci --no-optional --no-audit --progress=false
- name: ESLint
run: |
npm run lint:js
prettier:
runs-on: ubuntu-22.04
steps:
- name: Checkout Code Repository
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
- id: node-cache
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
- if: steps.node-cache.outputs.cache-hit != 'true'
run: |
npm ci --no-optional --no-audit --progress=false
- name: Prettier
run: |
npm run lint:format
shellcheck:
runs-on: ubuntu-22.04
steps:
- name: Checkout Code Repository
uses: actions/checkout@v4
- name: Install Dependencies
shell: bash
run: |
sudo apt install shellcheck -y
- name: Run shellcheck
shell: bash
run: |
echo "${{ github.ref }}"
bash -c 'shopt -s globstar; shellcheck ./*.sh;'
# Runs the python test suite on the VM
test:
runs-on: ubuntu-22.04
needs: [ruff, black, stylelint, eslint, prettier, shellcheck]
steps:
- name: Checkout Code Repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- id: poetry-cache
uses: actions/cache@v4
with:
path: .venv
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
- name: System Dependencies
shell: bash
run: |
sudo apt update --yes --quiet
export DEBIAN_FRONTEND=noninteractive
export TZ=Africa/Lusaka
sudo apt install --yes --quiet --no-install-recommends ffmpeg
sudo sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen
sudo locale-gen
sudo ln -fs /usr/share/zoneinfo/Africa/Lusaka /etc/localtime
sudo dpkg-reconfigure tzdata
export LANG=en_US.UTF-8
export LANGUAGE=en_US:en
export LC_ALL=en_US.UTF-8
- if: steps.poetry-cache.outputs.cache-hit != 'true'
name: Install Poetry and Dependencies
shell: bash
run: |
pip install --upgrade pip
pip install poetry==$POETRY_VERSION
python -m venv .venv
source .venv/bin/activate
poetry install --with dev
- name: Test with unittest
shell: bash
env:
OPENAI_API_KEY: "fake_key"
COHERE_API_KEY: "another_fake_key"
TOGETHER_API_KEY: "some_key"
AWS_ACCESS_KEY_ID: "1234567890"
AWS_SECRET_ACCESS_KEY: "fake_secret_key"
AWS_REGION_NAME: "any-region"
AWS_BUCKET_NAME: "bucket-name"
run: |
source .venv/bin/activate
invoke test
- name: "Upload coverage data"
uses: actions/upload-artifact@v4
with:
name: covdata
path: coverage.*
coverage:
name: Coverage
needs: test
runs-on: ubuntu-22.04
steps:
- name: Checkout Code Repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- id: poetry-cache
uses: actions/cache@v4
with:
path: .venv
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
- if: steps.poetry-cache.outputs.cache-hit != 'true'
name: Install Poetry and Dependencies
shell: bash
run: |
pip install --upgrade pip
pip install poetry==$POETRY_VERSION
python -m venv .venv
source .venv/bin/activate
poetry install --with dev
- name: "Download coverage data"
uses: actions/download-artifact@v4
with:
name: covdata
- name: "Extract total coverage"
run: |
source .venv/bin/activate
export TOTAL=$(python -c "import json;print(round(json.load(open('coverage.json'))['totals']['percent_covered']))")
echo "total=$TOTAL" >> $GITHUB_ENV
echo "### Total coverage: ${TOTAL}%" >> $GITHUB_STEP_SUMMARY
- name: "Create coverage badge"
if: (github.repository == 'engineervix/zed-news') && (github.ref == 'refs/heads/main')
uses: schneegans/[email protected]
with:
# GIST_TOKEN is a GitHub personal access token with scope "gist".
auth: ${{ secrets.GIST_TOKEN }}
gistID: f4b1128b188c4e29722bc879e4ab6574
filename: covbadge.json
label: Coverage
message: ${{ env.total }}%
minColorRange: 50
maxColorRange: 90
valColorRange: ${{ env.total }}
# Runs the next steps on the VM
# Creates a GitHub Release when the lint & test jobs succeeds, and only on pushes to tags.
release:
needs: [ruff, black, stylelint, eslint, prettier, shellcheck, test]
permissions:
contents: write
if: needs.test.result == 'success' && startsWith( github.ref, 'refs/tags/v' )
runs-on: ubuntu-22.04
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- id: poetry-cache
uses: actions/cache@v4
with:
path: .venv
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
- if: steps.poetry-cache.outputs.cache-hit != 'true'
name: Install Poetry and Dependencies
shell: bash
run: |
pip install --upgrade pip
pip install poetry==$POETRY_VERSION
python -m venv .venv
source .venv/bin/activate
poetry install --with dev
- name: Get the version
id: get_version
run: |
echo "${{ github.ref }}"
echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
- name: Generate Release Title
id: get_release_title
shell: bash
run: |
export TODAY="($(TZ=Africa/Lusaka date --iso))"
echo ::set-output name=RELEASE_NAME::"${{ steps.get_version.outputs.VERSION }} $TODAY"
- name: Extract Release Notes
# This creates a file LATEST_RELEASE_NOTES.md in the parent directory (../)
shell: bash
run: |
source .venv/bin/activate
invoke get-release-notes
- name: GitHub Release
uses: softprops/action-gh-release@v1
with:
name: ${{ steps.get_release_title.outputs.RELEASE_NAME }}
body_path: ../LATEST_RELEASE_NOTES.md