-
Notifications
You must be signed in to change notification settings - Fork 4
224 lines (201 loc) · 7.43 KB
/
test.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
name: Inyoka CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-24.04
env:
DEFAULT_BRANCH: 'refs/heads/staging'
REQUIREMENTS_FILE: extra/requirements/linux-py${{ matrix.python-version }}-development.txt
strategy:
matrix:
python-version: ['3.12', '3.11', '3.10', '3.9']
database: ['postgresql', 'sqlite']
theme: ['', 'theme-ubuntuusers']
include:
- python-version: 3.12
database: 'postgresql'
theme: ''
build_docs: true
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
# - name: Dump github.event.pull_request context
# env:
# GITHUB_CONTEXT: ${{ toJSON(github.event.pull_request) }}
# run: echo "$GITHUB_CONTEXT"
- name: Checkout theme from repo branch # (e.g. staging)
id: checkout-branch
continue-on-error: true
if: ${{ !github.event.pull_request && matrix.theme != '' }}
uses: actions/checkout@v4
with:
repository: inyokaproject/${{ matrix.theme }}
ref: ${{ github.ref }}
path: ${{ matrix.theme }}
persist-credentials: false
- name: Checkout theme in PR
id: checkout-pr
continue-on-error: true
if: ${{ github.event.pull_request && matrix.theme != '' }}
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.owner.login }}/${{ matrix.theme }}
ref: ${{ github.head_ref }}
path: ${{ matrix.theme }}
persist-credentials: false
- name: "Checkout fallback theme: repo theme-ubuntuusers, staging branch"
if: ${{ matrix.theme != '' && (steps.checkout-branch.outcome == 'failure' || steps.checkout-pr.outcome == 'failure') }}
uses: actions/checkout@v4
with:
repository: inyokaproject/${{ matrix.theme }}
ref: staging
path: ${{ matrix.theme }}
persist-credentials: false
# if theme == '', the default theme inside inyoka is used
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: 'extra/requirements/*.txt'
- name: Build virtualenv
run: |
python -m venv ~/venv
. ~/venv/bin/activate
python -m pip install --upgrade pip
pip install --no-deps --require-hashes -r ${{ env.REQUIREMENTS_FILE }}
- name: Build static files
run: |
npm ci
npm run all
- name: Link theme
working-directory: ./${{ matrix.theme }}
if: ${{ matrix.theme != '' }}
run: |
. ~/venv/bin/activate
pip install -e .
- name: Build static files theme
working-directory: ./${{ matrix.theme }}
if: ${{ matrix.theme != '' }}
run: |
npm ci
npm run all
- name: Start postgres
if: ${{ matrix.database == 'postgresql' }}
run: |
cat << '__EOF__' | sudo tee /etc/postgresql/16/main/pg_hba.conf > /dev/null
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
__EOF__
sudo systemctl start postgresql.service
pg_isready
- name: Install redis (server and cli)
run: |
sudo apt-get install redis-server
- name: Check for missing migrations (postgresql)
if: ${{ matrix.database == 'postgresql' }}
run: |
. ~/venv/bin/activate
python manage.py makemigrations --check --dry-run --settings tests.settings.${{ matrix.database }}_staticdbname
- name: Check for missing migrations (no postgresql)
if: ${{ matrix.database != 'postgresql' }}
run: |
. ~/venv/bin/activate
python manage.py makemigrations --check --dry-run --settings tests.settings.${{ matrix.database }}
- name: Run Tests
env:
PYTHONWARNINGS: 'always'
INYOKA_THEME: ${{ matrix.theme }}
run: |
. ~/venv/bin/activate
coverage run manage.py test --settings tests.settings.${{ matrix.database }}
coverage html
- name: Save coverage report for tests
uses: actions/upload-artifact@v4
with:
name: coverage-py${{ matrix.python-version }}-${{ matrix.database }}-${{ matrix.theme }}
path: htmlcov
- name: Run BDD tests
if: ${{ matrix.database == 'postgresql' }}
env:
DJANGO_SETTINGS_MODULE: 'tests.bdd.settings.headless'
INYOKA_THEME: ${{ matrix.theme }}
COVERAGE_RCFILE: 'tests/bdd/settings/.coveragerc'
run: |
. ~/venv/bin/activate
cat << '__EOF__' | sudo tee -a /etc/hosts > /dev/null
127.0.0.1 ubuntuusers.local forum.ubuntuusers.local paste.ubuntuusers.local wiki.ubuntuusers.local planet.ubuntuusers.local ikhaya.ubuntuusers.local static.ubuntuusers.local media.ubuntuusers.local
__EOF__
python manage.py collectstatic --noinput
coverage run -m behave --tags=-skip
coverage html -d bdd_coverage
- name: Save BDD results
if: ${{ matrix.database == 'postgresql' }}
uses: actions/upload-artifact@v4
with:
name: BDD-coverage-py${{ matrix.python-version }}-${{ matrix.database }}-${{ matrix.theme }}
path: bdd_coverage
- name: Build documentation
if: ${{ matrix.build_docs }}
env:
DJANGO_SETTINGS_MODULE: tests.settings.${{ matrix.database }}
INYOKA_THEME: ${{ matrix.theme }}
run: |
. ~/venv/bin/activate
make -C docs html
- name: Save documentation
if: ${{ matrix.build_docs }}
uses: actions/upload-artifact@v4
with:
name: 'Inyoka_Documentation'
path: docs/build/html
- name: Lint
run: |
. ~/venv/bin/activate
ruff check
- name: Save statics
if: ${{ startsWith(github.ref, 'refs/tags/') && matrix.build_docs }}
uses: actions/upload-artifact@v4
with:
name: 'Static_files'
path: inyoka/static-collected
# Deploy documentation to GitHub Pages
deploy_docu:
if: github.ref_name == 'staging'
needs: test
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
pages: write
id-token: write
actions: read
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Download documentation artifact from previous job
uses: actions/download-artifact@v4
with:
name: 'Inyoka_Documentation'
path: 'docs'
- name: Upload artifact for GitHub pages
uses: actions/upload-pages-artifact@v3
with:
path: 'docs'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4