generated from bcgov/bcrs-template-ui
-
Notifications
You must be signed in to change notification settings - Fork 14
202 lines (194 loc) · 6.49 KB
/
backend-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
name: Backend Application CI
on:
workflow_call:
inputs:
app_name:
required: true
type: string
working_directory:
type: string
default: "."
codecov_flag:
type: string
skip_isort:
type: string
default: "false"
skip_black:
type: string
default: "false"
jobs:
linting:
strategy:
fail-fast: true
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: ${{ inputs.working_directory }}
steps:
- uses: actions/checkout@v4
- name: Install Poetry
run: |
pipx install poetry
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: ${{ inputs.working_directory }}/pyproject.toml
cache: poetry
cache-dependency-path: ${{ inputs.working_directory }}/poetry.lock
- id: poetry_installs
name: Install dependencies
run: |
poetry update
poetry install
# Function to check if a library is installed
check_library_installed() {
if poetry show "$1" > /dev/null 2>&1; then
echo "true"
else
echo "false"
fi
}
echo "ruff_installed=$(check_library_installed ruff)" >> "$GITHUB_OUTPUT"
echo "isort_installed=$(check_library_installed isort)" >> "$GITHUB_OUTPUT"
echo "black_installed=$(check_library_installed black)" >> "$GITHUB_OUTPUT"
echo "pylint_installed=$(check_library_installed pylint)" >> "$GITHUB_OUTPUT"
echo "flake8_installed=$(check_library_installed flake8)" >> "$GITHUB_OUTPUT"
- name: Run Ruff
if: |
steps.poetry_installs.outputs.ruff_installed == 'true'
run: |
poetry run ruff check
- name: Run isort
if: |
steps.poetry_installs.outputs.ruff_installed == 'false' &&
steps.poetry_installs.outputs.isort_installed == 'true' &&
inputs.skip_isort == 'false'
run: |
poetry run isort . --check -v
- name: Run black
if: |
steps.poetry_installs.outputs.ruff_installed == 'false' &&
steps.poetry_installs.outputs.black_installed == 'true' &&
inputs.skip_black == 'false'
run: |
poetry run black . --check
- name: Run pylint
if: |
steps.poetry_installs.outputs.ruff_installed == 'false' &&
steps.poetry_installs.outputs.pylint_installed == 'true'
run: |
poetry run pylint .
- name: Run flake8
if: |
steps.poetry_installs.outputs.ruff_installed == 'false' &&
steps.poetry_installs.outputs.flake8_installed == 'true'
run: |
poetry run flake8 .
unit-testing:
needs: linting
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: ${{ inputs.working_directory }}
strategy:
fail-fast: true
env:
DATABASE_TEST_USERNAME: "postgres"
DATABASE_TEST_PASSWORD: "postgres"
DATABASE_TEST_NAME: "unittesting"
DATABASE_TEST_HOST: "localhost"
DATABASE_TEST_PORT: "5432"
FLASK_ENV: "testing"
DEPLOYMENT_ENV: "testing"
DATABASE_TEST_URL: "postgresql://postgres:postgres@localhost:5432/unittesting"
JWT_OIDC_TEST_ISSUER: "http://localhost:8081/auth/realms/demo"
JWT_OIDC_TEST_WELL_KNOWN_CONFIG: "http://localhost:8081/auth/realms/demo/.well-known/openid-configuration"
JWT_OIDC_TEST_ALGORITHMS: "RS256"
JWT_OIDC_TEST_AUDIENCE: "sbc-auth-web"
JWT_OIDC_TEST_CLIENT_SECRET: "1111111111"
JWT_OIDC_TEST_JWKS_CACHE_TIMEOUT: "6000"
KEYCLOAK_TEST_ADMIN_CLIENTID: "sbc-auth-admin"
KEYCLOAK_TEST_ADMIN_SECRET: "2222222222"
KEYCLOAK_TEST_AUTH_AUDIENCE: "sbc-auth-web"
KEYCLOAK_TEST_AUTH_CLIENT_SECRET: "1111111111"
KEYCLOAK_TEST_BASE_URL: "http://localhost:8081"
KEYCLOAK_TEST_REALMNAME: "demo"
TOKEN_EXPIRY_PERIOD: 7
EMAIL_SECURITY_PASSWORD_SALT: "my_pwd_salt"
EMAIL_TOKEN_SECRET_KEY: "mySecretKey"
USE_TEST_KEYCLOAK_DOCKER: "YES"
USE_DOCKER_MOCK: "YES"
STAFF_ADMIN_EMAIL: "[email protected]"
services:
postgres:
image: postgis/postgis:15-master
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: unittesting
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
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Install docker-compose
run: |
sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose version
- name: Install Poetry
run: |
pipx install poetry
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: ${{ inputs.working_directory }}/pyproject.toml
cache: poetry
cache-dependency-path: ${{ inputs.working_directory }}/poetry.lock
- name: Install dependencies
run: |
poetry update
poetry install
- name: Run tests
run: |
poetry run pytest
- uses: actions/upload-artifact@v4
if: ${{ hashFiles('coverage.xml') != '' }}
with:
name: coveragefile
path: ${{ inputs.working_directory }}/coverage.xml
retention-days: 1
code-coverage:
needs: unit-testing
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/download-artifact@v4
with:
name: coveragefile
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: coverage.xml
flags: ${{ inputs.codecov_flag }}
name: codecov-${{ inputs.app_name }}
token: ${{ vars.CODECOV_TOKEN }}
fail_ci_if_error: false
verify-build:
needs: linting
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: ${{ inputs.working_directory }}
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: build to check strictness
id: build
run: |
docker build --no-cache -t ${{ inputs.app_name }} .