Skip to content

Commit f5dde3f

Browse files
authored
ci: speed up tests in (vas3k#1000)
* Get rid of `docker-compose` execution for tests. Use `postgres` and `redis` services instead * Use python 3.8 and node 14 to replicate `docker-compose` setup * Use cache for pip packages and webpack build. * postgres 12 as in prod docker-compose
1 parent 0523b00 commit f5dde3f

File tree

1 file changed

+89
-19
lines changed

1 file changed

+89
-19
lines changed

.github/workflows/tests.yml

+89-19
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,28 @@ on:
66
- master
77
pull_request:
88

9+
concurrency:
10+
# For pull requests, cancel all currently-running jobs for this workflow
11+
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#concurrency
12+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
13+
cancel-in-progress: true
14+
915
jobs:
1016
lint:
1117
runs-on: ubuntu-latest
1218
steps:
13-
- uses: actions/checkout@master
14-
- uses: actions/setup-python@v2
19+
20+
- uses: actions/checkout@v3
21+
22+
- uses: actions/setup-python@v4
23+
id: setup-python
1524
with:
1625
python-version: '3.8'
17-
architecture: 'x64'
26+
1827
- name: Install requirements
1928
run: |
2029
pip install --no-cache-dir flake8
30+
2131
- name: run flake8
2232
run: |
2333
# stop the build if there are Python syntax errors or undefined names
@@ -27,24 +37,84 @@ jobs:
2737
2838
test:
2939
runs-on: ubuntu-latest
40+
services:
41+
postgres:
42+
image: postgres:12-alpine
43+
env:
44+
POSTGRES_USER: postgres
45+
POSTGRES_PASSWORD: postgres
46+
POSTGRES_DB: vas3k_club
47+
options: >-
48+
--health-cmd pg_isready
49+
--health-interval 10s
50+
--health-timeout 5s
51+
--health-retries 5
52+
ports:
53+
- 5432:5432
54+
redis:
55+
image: redis:6-alpine
56+
env:
57+
ALLOW_EMPTY_PASSWORD: yes
58+
ports:
59+
- 6379:6379
60+
3061
steps:
31-
- uses: actions/checkout@master
32-
- name: Build image
33-
run: |
34-
docker-compose -f docker-compose.test.yml build
35-
- name: Run postgres
36-
run: |
37-
docker-compose -f docker-compose.test.yml up -d postgres
38-
- name: Run redis
39-
run: |
40-
docker-compose -f docker-compose.test.yml up -d redis
41-
- name: Run frontend
62+
- uses: actions/checkout@v3
63+
64+
- uses: actions/setup-python@v4
65+
id: setup-python
66+
with:
67+
python-version: '3.8'
68+
69+
- uses: actions/setup-node@v3
70+
with:
71+
node-version: '14'
72+
73+
- name: ⚡️ Cache webpack build
74+
uses: actions/cache@v3
75+
id: cache-webpack
76+
with:
77+
path: |
78+
frontend/static/dist
79+
frontend/webpack-stats.json
80+
key: ${{ runner.os }}-webpack-${{ hashFiles('frontend/package*.json', 'frontend/webpack*.js') }}
81+
82+
- name: 🏗 Webpack build
83+
if: steps.cache-webpack.outputs.cache-hit != 'true'
84+
working-directory: ./frontend
4285
run: |
43-
docker-compose -f docker-compose.test.yml up -d webpack
44-
- name: Wait postgres
45-
uses: jakejarvis/wait-action@master
86+
node -v
87+
npm -v
88+
npm ci
89+
npm run build
90+
91+
- name: ⚡️ Cache python virtualenv
92+
uses: actions/cache@v3
93+
id: cache-venv
4694
with:
47-
time: '20s'
95+
path: |
96+
venv
97+
key: ${{ runner.os }}-venv-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('Pipfile.lock') }}
98+
99+
- name: Install pip dependencies
100+
if: steps.cache-venv.outputs.cache-hit != 'true'
101+
run: |
102+
python -m venv venv
103+
. venv/bin/activate
104+
pip install --upgrade pip pipenv==2021.5.29
105+
pipenv lock --dev --requirements > requirements.txt
106+
pip install -r requirements.txt
107+
48108
- name: Run tests
109+
env:
110+
POSTGRES_USER: postgres
111+
POSTGRES_PASSWORD: postgres
112+
POSTGRES_DB: vas3k_club
113+
POSTGRES_HOST: localhost
114+
REDIS_DB: 0
115+
REDIS_HOST: localhost
116+
PYTHONUNBUFFERED: 1
117+
TESTS_RUN: da
49118
run: |
50-
docker-compose -f docker-compose.test.yml run --rm tests
119+
. venv/bin/activate
120+
make test-ci

0 commit comments

Comments
 (0)