-
Notifications
You must be signed in to change notification settings - Fork 2
193 lines (163 loc) · 5.25 KB
/
ci.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
name: "Hitas CI"
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches:
- master
pull_request:
branches:
- master
merge_group:
branches:
- master
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
frontend:
name: "Frontend checks"
runs-on: ubuntu-latest
steps:
- name: "Checkout code"
uses: actions/checkout@v3
- name: "Frontend - Set Node.js 18.x"
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: "Frontend - Install dependencies"
uses: borales/actions-yarn@v4
with:
dir: "frontend"
cmd: install
- name: "Frontend - Check for ESLint issues"
uses: borales/actions-yarn@v4
with:
dir: "frontend"
cmd: eslint-check
- name: "Frontend - Check for Prettier issues"
uses: borales/actions-yarn@v4
with:
dir: "frontend"
cmd: prettier-check
build-frontend:
name: "Test building frontend docker image"
runs-on: ubuntu-latest
steps:
- name: "Checkout code"
uses: actions/checkout@v3
- name: "Set up Docker Buildx"
uses: docker/setup-buildx-action@v1
- name: "Build frontend container"
uses: docker/build-push-action@v2
with:
context: frontend
push: false
tags: hitas-frontend
cache-from: type=gha,scope=frontend
cache-to: type=gha,scope=frontend
backend:
name: "Backend checks"
runs-on: ubuntu-latest
env:
POETRY_VERSION: 1.3.1
POETRY_VIRTUALENVS_CREATE: 0
POETRY_HOME: ~/.local
POETRY_CACHE_DIR: ~/.cache/pypoetry
PRE_COMMIT_HOME: ~/.cache/pre-commit
SECRET_KEY: xxx
DATABASE_URL: postgres://postgres:postgres@localhost:5432/github_actions
# Majority of the tests require database
services:
postgres:
image: postgres:13.7
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: github_actions
ports:
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: "Checkout code"
uses: actions/checkout@v3
with:
# Disable shallow cloning to improving relevancy of reporting for SonarCloud
fetch-depth: 0
- name: "Set up Python 3.11"
id: setup-python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: "Load cached dependencies and pre-commit hooks"
id: cache
uses: actions/cache@v3
with:
path: |
${{ env.pythonLocation }}
${{ env.POETRY_HOME }}
${{ env.POETRY_CACHE_DIR }}
${{ env.PRE_COMMIT_HOME }}
# Invalidate cache when any of these changes:
# - python version
# - poetry version
# - dependencies
# - pre-commit config
# - manually changed "cache-v1" prefix
key: cache-v1-${{ hashFiles('**/poetry.lock', '**/.pre-commit-config.yaml') }}-poetry${{ env.POETRY_VERSION }}-python${{ steps.setup-python.outputs.python-version }}
- name: "Install Poetry"
if: steps.cache.outputs.cache-hit != 'true'
run: curl -sSL https://install.python-poetry.org | python -
- name: "Add poetry install directory to path"
run: echo "${{ env.POETRY_HOME }}" >> $GITHUB_PATH
- name: "Install dependencies"
if: steps.cache.outputs.cache-hit != 'true'
run: >
cd backend
&& poetry install --no-root
- name: "Install pre-commit hook environments"
if: steps.cache.outputs.cache-hit != 'true'
run: >
cd backend
&& pre-commit install-hooks
- name: "Run pre-commit hooks against all files"
run: >
cd backend
&& pre-commit run --all-files
- name: "Test for migration issues"
run: >
cd backend
&& ./manage.py makemigrations --check --no-color --no-input --dry-run
- name: "Run tests and create coverage report"
run: >
cd backend
&& pytest -s -vvv --cov=. --cov-report=xml --cov-branch .
# Without this workaround Sonar reports a warning about an incorrect source path
- name: "Override coverage report source path for Sonar"
run: sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' backend/coverage.xml
- name: "SonarCloud Scan"
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
build-backend:
name: "Test building backend docker image"
runs-on: ubuntu-latest
steps:
- name: "Checkout code"
uses: actions/checkout@v3
- name: "Set up Docker Buildx"
uses: docker/setup-buildx-action@v1
- name: "Build backend container"
uses: docker/build-push-action@v2
with:
context: backend
push: false
tags: hitas-backend
cache-from: type=gha,scope=backend
cache-to: type=gha,scope=backend