-
Notifications
You must be signed in to change notification settings - Fork 20
226 lines (214 loc) · 7.81 KB
/
pythonapp.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
name: Python application
on: [push, pull_request, merge_group]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
test:
name: Databaseless tests
runs-on: ubuntu-latest
if: ${{ github.repository_owner != 'Karaage-Cluster' || github.event_name != 'pull_request' }}
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install system dependancies
run: |
sudo apt-get update
sudo apt-get install libcrack2-dev
- name: Install poetry
uses: abatilo/actions-poetry@v2.3.0
with:
poetry-version: 1.3.0
- name: Install python dependancies
run: |
poetry install --extras=docs
- name: Run tests
run: |
poetry run make -C docs/admin html
poetry run black --check karaage
poetry run flake8 karaage
poetry run ./manage.py makemigrations --settings=karaage.tests.settings --check --dry-run
test-mysql:
name: Mysql tests
runs-on: ubuntu-latest
if: ${{ github.repository_owner != 'Karaage-Cluster' || github.event_name != 'pull_request' }}
env:
DATABASE_URL: mysql://root:z9Pm29jg9EfJ6m@127.0.0.1/test
steps:
- name: Shutdown Ubuntu MySQL
run: sudo service mysql stop
- name: Install mysql
uses: mirromutth/mysql-action@v1.1
with:
mysql version: '8.0'
mysql database: 'test'
mysql user: 'test'
mysql password: 'z9Pm29jg9EfJ6m'
mysql root password: 'z9Pm29jg9EfJ6m'
- name: Checkout source code
uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install system dependancies
run: |
sudo apt-get update
sudo apt-get install libcrack2-dev slapd ldap-utils
- name: Remove apparmor restrictions on slapd
run: |
sudo apt-get install apparmor-utils
sudo aa-complain /usr/sbin/slapd
- name: Install poetry
uses: abatilo/actions-poetry@v2.3.0
with:
poetry-version: 1.3.0
- name: Install python dependancies
run: |
poetry install
- name: Run tests
run: |
poetry run ./manage.py collectstatic --settings=karaage.tests.settings --noinput
poetry run ./manage.py migrate --settings=karaage.tests.settings
mkdir test-reports
poetry run python -m tldap.test.slapd python -m pytest --cov=karaage --junitxml=test-reports/junit.xml
- name: Upload pytest test results
uses: actions/upload-artifact@v3
with:
name: pytest-results
path: test-reports/junit.xml
test-postgresql:
name: Postgresql tests
runs-on: ubuntu-latest
if: ${{ github.repository_owner != 'Karaage-Cluster' || github.event_name != 'pull_request' }}
env:
DATABASE_URL: postgresql://test:z9Pm29jg9EfJ6m@localhost/test?sslmode=disable
steps:
- name: Install postgresql
uses: harmon758/postgresql-action@v1
with:
postgresql version: '12'
postgresql db: 'test'
postgresql user: 'test'
postgresql password: 'z9Pm29jg9EfJ6m'
- name: Checkout source code
uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install system dependancies
run: |
sudo apt-get update
sudo apt-get install libcrack2-dev slapd ldap-utils
- name: Remove apparmor restrictions on slapd
run: |
sudo apt-get install apparmor-utils
sudo aa-complain /usr/sbin/slapd
- name: Install poetry
uses: abatilo/actions-poetry@v2.3.0
with:
poetry-version: 1.3.0
- name: Install python dependancies
run: |
poetry install
- name: Run tests
run: |
poetry run ./manage.py collectstatic --settings=karaage.tests.settings --noinput
poetry run ./manage.py migrate --settings=karaage.tests.settings
mkdir test-reports
poetry run python -m tldap.test.slapd python -m pytest --cov=karaage --junitxml=test-reports/junit.xml
- name: Upload pytest test results
uses: actions/upload-artifact@v3
with:
name: pytest-results
path: test-reports/junit.xml
setup-build-publish-deploy:
name: Setup, Build, Publish, and Deploy
runs-on: ubuntu-latest
needs: [test, test-mysql, test-postgresql]
if: ${{ github.repository_owner != 'Karaage-Cluster' || github.event_name == 'push' }}
steps:
- name: downcase IMAGE_NAME
run: |
echo "IMAGE_NAME_LC=${IMAGE_NAME,,}" >>${GITHUB_ENV}
- name: Checkout
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LC }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=sha, format=long
- name: Docker meta
id: brianmay_meta
uses: brianmay/docker-meta@main
- name: Set up QEMU
uses: docker/setup-qemu-action@v3.0.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3.0.0
- name: Login to DockerHub
uses: docker/login-action@v3.0.0
if: ${{ github.repository_owner == 'Karaage-Cluster' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags')) && github.event_name == 'push' }}
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v5.0.0
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
push: ${{ github.repository_owner == 'Karaage-Cluster' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags')) && github.event_name == 'push' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LC }}:main
cache-to: type=inline
build-args: ${{ steps.brianmay_meta.outputs.build-args }}
publish-pypi-prod:
name: Publish Pypi Prod
runs-on: ubuntu-latest
needs: [test, test-mysql, test-postgresql]
if: github.repository_owner == 'Karaage-Cluster' && startsWith(github.ref, 'refs/tags') && github.event_name == 'push'
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install poetry
uses: abatilo/actions-poetry@v2.3.0
with:
poetry-version: 1.3.0
- name: Install system dependancies
run: |
sudo apt-get update
sudo apt-get install libcrack2-dev
- name: Install python dependancies
run: |
poetry install
- name: Verify git tag vs. version
run: |
VERSION=${GITHUB_REF#refs/tags/}
test "$(poetry version)" = "karaage ${VERSION}"
- name: Create packages
run: |
poetry build
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_PASSWORD }}