-
Notifications
You must be signed in to change notification settings - Fork 82
174 lines (172 loc) · 5.96 KB
/
ci.yaml
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
---
name: CI
on:
- push
- pull_request
jobs:
lint:
name: Run linters
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install dependencies
run: python -m pip install tox
- name: Run tox
run: tox -e pep8
test:
name: Run unit tests
runs-on: ubuntu-latest
strategy:
matrix:
python: ["3.8", "3.9", "3.10", "3.11"]
db: [postgres, mysql, sqlite3]
env:
DATABASE_TYPE: "${{ matrix.db }}"
DATABASE_HOST: "127.0.0.1"
DATABASE_NAME: ${{ matrix.db != 'sqlite3' && format('patchwork-db-{0}', github.run_id) || '/dev/shm/patchwork.test.db.sqlite3' }}
DATABASE_USER: patchwork-user-${{ github.run_id }}
DATABASE_PASSWORD: password-${{ github.run_id }}
MYSQL_ROOT_PASSWORD: root-${{ github.run_id }}
services:
postgres:
image: postgres:latest
env:
POSTGRES_DB: ${{ env.DATABASE_NAME }}
POSTGRES_PASSWORD: ${{ env.DATABASE_PASSWORD }}
POSTGRES_USER: ${{ env.DATABASE_USER }}
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
mysql:
image: mysql:latest
env:
MYSQL_DATABASE: ${{ env.DATABASE_NAME }}
MYSQL_USER: ${{ env.DATABASE_USER }}
MYSQL_PASSWORD: ${{ env.DATABASE_PASSWORD }}
MYSQL_ROOT_PASSWORD: ${{ env.MYSQL_ROOT_PASSWORD }}
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout source code
uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Install Python dependencies
run: python -m pip install tox tox-gh-actions
- name: Log database configuration (mysql)
if: ${{ matrix.db == 'mysql' }}
run: |
mysql -h 127.0.0.1 -e "SELECT VERSION(), CURRENT_USER();" \
-uroot -p${MYSQL_ROOT_PASSWORD} ${DATABASE_NAME}
- name: Log database configuration (postgres)
if: ${{ matrix.db == 'postgres' }}
run: |
psql -h 127.0.0.1 -c "SELECT VERSION(), CURRENT_USER, current_database()" \
-U ${DATABASE_USER} -d ${DATABASE_NAME}
env:
PGPASSWORD: ${{ env.DATABASE_PASSWORD }}
- name: Modify database user permissions (mysql)
if: ${{ matrix.db == 'mysql' }}
run: |
mysql -h 127.0.0.1 -e "GRANT ALL ON \`test\\_${DATABASE_NAME}%\`.* to '${DATABASE_USER}'@'%';" \
-uroot -p${MYSQL_ROOT_PASSWORD}
- name: Run unit tests (via tox)
run: tox
docs:
name: Build docs
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install dependencies
run: python -m pip install tox
- name: Build docs (via tox)
run: tox -e docs
- name: Archive build results
uses: actions/upload-artifact@v3
with:
name: html-docs-build
path: docs/_build/html
retention-days: 7
docker-compose:
name: Docker Image tests
runs-on: ubuntu-latest
strategy:
matrix:
db: [postgres, mysql, sqlite3]
env:
COMPOSE_FILE: ${{ matrix.db == 'mysql' && 'docker-compose.yml' || (matrix.db == 'postgres' && 'docker-compose-pg.yml') || 'docker-compose-sqlite3.yml' }}
steps:
- name: Checkout source code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Build docker-compose service
run: |
docker-compose build --build-arg UID=$(id -u) --build-arg GID=$(id -g)
- name: Test createsuperuser/changepassword
run: |
docker-compose run -T --rm web \
python manage.py createsuperuser \
--username patchwork --no-input --email [email protected]
{ echo patchwork; echo patchwork; } | \
docker-compose run -T --rm web \
python manage.py changepassword patchwork
# FIXME(stephenfin): Re-enable this once dbbackup supports Django 4.0
# - name: Test dbbackup/dbrestore
# run: |
# docker-compose run -T --rm web python manage.py dbbackup
# echo y | docker-compose run -T --rm web python manage.py dbrestore
- name: Modify database user permissions (mysql)
if: ${{ matrix.db == 'mysql' }}
run: |
docker-compose exec -T -- db \
sh -c "exec mysql -uroot -p\"\${MYSQL_ROOT_PASSWORD}\" -e \"GRANT ALL ON \\\`test\\_\${MYSQL_DATABASE}%\\\`.* to '\${MYSQL_USER}'@'%'; FLUSH PRIVILEGES;\""
- name: Run unittest
run: docker-compose run -T --rm web tox
- name: Test normal startup
run: |
docker-compose up --detach
for count in $(seq 50); do \
if curl --fail --silent "http://localhost:8000"; then \
break; \
fi; \
sleep 1; echo -n .; \
done
echo
docker-compose ps
- name: Test client access (git-pw)
run: |
python -m pip install git-pw
git pw --debug \
--server http://localhost:8000/api/1.2 --project patchwork \
--username patchwork --password patchwork series list
- name: Dump container logs
if: ${{ always() }}
run: docker-compose logs --no-color --timestamps