-
Notifications
You must be signed in to change notification settings - Fork 8
273 lines (256 loc) · 9.29 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
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
name: CI/CD
on:
push:
pull_request:
workflow_dispatch:
env:
DEMO_BASE_URL_PREVIEW: dd-demo.vercel.app
DEMO_BASE_URL_PRODUCTION: datasette-dashboards-demo.vercel.app
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache Python modules
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade poetry
poetry install
- name: Run linting
run: |
poetry run black --check datasette_dashboards tests
poetry run flake8 datasette_dashboards tests
poetry run mypy --strict datasette_dashboards tests
- name: Run tests
run: |
poetry run pytest -v --cov=datasette_dashboards --cov=tests --cov-branch --cov-report=term-missing tests
poetry run coverage xml
- name: Publish code coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
deploy-demo-setup:
name: Deployment setup
runs-on: ubuntu-latest
needs: test
outputs:
github_ref_slug: ${{ steps.output_step.outputs.github_ref_slug }}
deployment_url: ${{ steps.output_step.outputs.deployment_url }}
steps:
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v5
- name: Set preview deployment url variable
if: ${{ !contains(github.ref, 'master') && !contains(github.ref, 'tags') }}
run: echo "DEPLOYMENT_URL=https://${GITHUB_REF_SLUG_URL}-${DEMO_BASE_URL_PREVIEW}" >> ${GITHUB_ENV}
- name: Set production deployment url variable
if: ${{ contains(github.ref, 'master') }}
run: echo "DEPLOYMENT_URL=https://${DEMO_BASE_URL_PRODUCTION}" >> ${GITHUB_ENV}
- id: output_step
run: |
echo "github_ref_slug=${GITHUB_REF_SLUG_URL}" >> $GITHUB_OUTPUT
echo "deployment_url=${DEPLOYMENT_URL}" >> $GITHUB_OUTPUT
deploy-demo-preview:
runs-on: ubuntu-latest
needs: [deploy-demo-setup]
if: ${{ github.event_name == 'push' && !contains(github.ref, 'master') && !contains(github.ref, 'tags') }}
environment:
name: preview/${{ needs.deploy-demo-setup.outputs.github_ref_slug }}
url: ${{ needs.deploy-demo-setup.outputs.deployment_url }}
steps:
- uses: actions/checkout@v4
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v5
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Cache Python modules
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/Pipfile.lock') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade poetry
poetry install
- name: Deploy to Vercel
run: |-
VERCEL_ALIAS=${GITHUB_REF_SLUG_URL}-${DEMO_BASE_URL_PREVIEW}
VERCEL_URL=$(poetry run datasette publish vercel demo/jobs.db \
--metadata demo/metadata.yml \
--template-dir demo/templates \
--install=datasette-cluster-map \
--install=datasette-vega \
--install=datasette-block-robots \
--install=datasette-sqlite-http \
--install=https://github.com/rclement/datasette-dashboards/archive/${GITHUB_SHA}.zip \
--project=${{ secrets.VERCEL_PROJECT }} \
--token=${{ secrets.VERCEL_TOKEN }} \
--no-prod)
vercel alias --token ${{ secrets.VERCEL_TOKEN }} set ${VERCEL_URL} ${VERCEL_ALIAS}
deploy-demo-production:
runs-on: ubuntu-latest
needs: [deploy-demo-setup]
if: contains(github.ref, 'master')
environment:
name: demo
url: ${{ needs.deploy-demo-setup.outputs.deployment_url }}
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Cache Python modules
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/Pipfile.lock') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade poetry
poetry install
- name: Deploy to Vercel
run: |-
poetry run datasette publish vercel demo/jobs.db \
--metadata demo/metadata.yml \
--template-dir demo/templates \
--install=datasette-cluster-map \
--install=datasette-vega \
--install=datasette-block-robots \
--install=datasette-sqlite-http \
--install=https://github.com/rclement/datasette-dashboards/archive/${GITHUB_SHA}.zip \
--project=${{ secrets.VERCEL_PROJECT }} \
--token=${{ secrets.VERCEL_TOKEN }}
publish-package-test:
runs-on: ubuntu-latest
needs: [test]
if: contains(github.ref, 'master')
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- uses: actions/cache@v4
name: Configure pip caching
with:
path: ~/.cache/pip
key: ${{ runner.os }}-publish-pip-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
${{ runner.os }}-publish-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade poetry
poetry install
- name: Build Python package
run: poetry build
- name: Publish Python package on PyPI
env:
POETRY_REPOSITORIES_TESTPYPI_URL: https://test.pypi.org/legacy/
POETRY_PYPI_TOKEN_TESTPYPI: ${{ secrets.PYPI_TOKEN_TEST }}
POETRY_HTTP_BASIC_TESTPYPI_USERNAME: __token__
POETRY_HTTP_BASIC_TESTPYPI_PASSWORD: ${{ secrets.PYPI_TOKEN_TEST }}
run: poetry publish -r testpypi --skip-existing
publish-package:
runs-on: ubuntu-latest
needs: [test]
if: contains(github.ref, 'tags')
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- uses: actions/cache@v4
name: Configure pip caching
with:
path: ~/.cache/pip
key: ${{ runner.os }}-publish-pip-${{ hashFiles('**/pyproject.toml') }}
restore-keys: |
${{ runner.os }}-publish-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade poetry
poetry install
- name: Build Python package
run: poetry build
- name: Publish Python package on PyPI
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
POETRY_HTTP_BASIC_PYPI_USERNAME: __token__
POETRY_HTTP_BASIC_PYPI_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: poetry publish
take-shots:
runs-on: ubuntu-latest
needs: [deploy-demo-production]
if: contains(github.ref, 'master')
permissions:
contents: write
steps:
- uses: actions/checkout@v4
# with:
# token: ${{ secrets.GH_PERSONAL_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- uses: actions/cache@v4
name: Configure pip caching
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip
- name: Cache Playwright browsers
uses: actions/cache@v4
with:
path: ~/.cache/ms-playwright/
key: ${{ runner.os }}-playwright
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade shot-scraper
shot-scraper install
- name: Demo dashboard screenshot
run: |
shot-scraper \
"https://${DEMO_BASE_URL_PRODUCTION}/-/dashboards/job-offers-stats?date_start=2021-01-01&date_end=2021-05-01&source=®ion=" \
--output demo/datasette-dashboards-demo.png \
--wait 1000 \
--width 1440 \
--retina
- name: Upload screenshot artifact
uses: actions/upload-artifact@v4
with:
name: screenshot
path: demo/datasette-dashboards-demo.png
# - name: Commit and push changes
# run: |
# git config user.name "Automated"
# git config user.email "actions@users.noreply.github.com"
# git add -A
# timestamp=$(date -u)
# git commit -m "Latest data: ${timestamp}" || exit 0
# git push