forked from bcgov/bcregistry-sre
-
Notifications
You must be signed in to change notification settings - Fork 0
204 lines (184 loc) · 6.41 KB
/
api-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
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
name: API CI
on:
workflow_call:
inputs:
app_name:
required: true
type: string
working_directory:
type: string
default: "."
codecov_flag:
type: string
jobs:
linting:
strategy:
fail-fast: true
matrix:
os: [ "ubuntu-latest" ]
python-version: [ "3.11" ]
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
working-directory: ${{ inputs.working_directory }}
steps:
#----------------------------------------------
# check-out repo and set-up python
#----------------------------------------------
- uses: actions/checkout@v4
- name: Set up python
id: setup-python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
#----------------------------------------------
# ----- install & configure poetry -----
#----------------------------------------------
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
#----------------------------------------------
# load cached venv if cache exists
#----------------------------------------------
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: ${{ inputs.working_directory }}/.venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
#----------------------------------------------
# install dependencies if cache does not exist
#----------------------------------------------
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
#----------------------------------------------
# install your root project, if required
#----------------------------------------------
- name: Install project
run: poetry install --no-interaction
#----------------------------------------------
# install and run linters
#----------------------------------------------
- name: Run isort
run: |
poetry run isort src tests --check
- name: Run black
run: |
poetry run black src tests --check
- name: Run pylint (src)
run: |
poetry run pylint src
- name: Run pylint (tests)
continue-on-error: true
run: |
poetry run pylint tests
- name: Run flake8 (src)
run: |
poetry run flake8 src
- name: Run flake8 (tests)
continue-on-error: true
run: |
poetry run flake8 tests
testing:
needs: linting
defaults:
run:
shell: bash
working-directory: ${{ inputs.working_directory }}
strategy:
fail-fast: true
matrix:
os: [ "ubuntu-latest" ]
python-version: [ "3.11" ]
env:
DATABASE_TEST_USERNAME: "postgres"
DATABASE_TEST_PASSWORD: "postgres"
DATABASE_TEST_NAME: "postgres"
DATABASE_TEST_HOST: "localhost"
DATABASE_TEST_PORT: "5432"
services:
postgres:
image: postgres:15
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
runs-on: ${{ matrix.os }}
steps:
#----------------------------------------------
# check-out repo and set-up python
#----------------------------------------------
- name: Check out repository
uses: actions/checkout@v4
- name: Set up python ${{ matrix.python-version }}
id: setup-python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
#----------------------------------------------
# ----- install & configure poetry -----
#----------------------------------------------
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
#----------------------------------------------
# load cached venv if cache exists
#----------------------------------------------
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: ${{ inputs.working_directory }}/.venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
#----------------------------------------------
# install dependencies if cache does not exist
#----------------------------------------------
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
#----------------------------------------------
# install your root project, if required
#----------------------------------------------
- name: Install library
run: poetry install --no-interaction
#----------------------------------------------
# add matrix specifics and run test suite
#----------------------------------------------
- name: Run tests
run: |
poetry run pytest
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ${{ inputs.working_directory }}/coverage.xml
flags: ${{ inputs.codecov_flag }}
name: codecov-${{ inputs.app_name }}
fail_ci_if_error: true
verify-build:
needs: linting
defaults:
run:
shell: bash
working-directory: ${{ inputs.working_directory }}
runs-on: ubuntu-latest
steps:
#----------------------------------------------
# check-out repo and set-up python
#----------------------------------------------
- name: Check out repository
uses: actions/checkout@v4
- name: build to check strictness
id: build
run: |
docker build --no-cache -t ${{ inputs.app_name }} .