-
Notifications
You must be signed in to change notification settings - Fork 52
150 lines (142 loc) · 5.47 KB
/
pytest.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
# This workflow will install Python dependencies and run tests with Python
# For more information see:
# https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: Pytest
on:
push:
paths:
- '**.py'
- '**.js'
- '**.scss'
- '**.jinja2'
- '.flaskenv'
- '.testenv'
- 'package-lock.json'
- 'requirements/base.txt'
- 'requirements/test.txt'
- '.github/workflows/pytest.yml'
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
test:
runs-on: ${{ matrix.os }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest] # TODO: Figure out macos-latest and Docker
python-version: ['3.11', '3.12']
services:
redis:
image: redis
ports:
- 6379:6379
options: --entrypoint redis-server
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
POSTGRES_HOST_AUTH_METHOD: trust
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Setup Docker on macOS
uses: docker-practice/[email protected]
if: ${{ matrix.os == 'macos-latest' }}
- name: Checkout code
uses: actions/checkout@v3
- name: Install Chrome (for browser testing)
uses: browser-actions/setup-chrome@latest
- name: Install Chromedriver (for browser testing)
uses: nanasess/setup-chromedriver@v2
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: 'requirements/*.txt'
- name: Cache python packages
uses: actions/cache@v3
with:
path: ${{ env.pythonLocation }}
key: ${{ matrix.os }}-${{ env.pythonLocation }}-${{ hashFiles('requirements/base.txt') }}-${{ hashFiles('requirements.txt/test.txt') }}
- name: Install Python dependencies
run: make install-python-test
- name: Install Playwright browser
run: make install-playwright
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: 20
cache: npm
- name: Cache node modules
uses: actions/cache@v3
with:
path: node_modules
key: ${{ join(matrix.*, '-') }}-node_modules-${{ hashFiles('package-lock.json') }}
- name: Cache built assets
uses: actions/cache@v3
with:
path: funnel/static/build
key: ${{ join(matrix.*, '-') }}-assets-build
- name: Cache .webpack_cache
uses: actions/cache@v3
with:
path: .webpack_cache
key: ${{ join(matrix.*, '-') }}-webpack_cache
- name: Install Node dependencies
run: make install-npm
- name: Build Webpack assets
run: make assets
- name: Annotate Pytest failures in PR
run: pip install pytest-github-actions-annotate-failures
- name: Setup hostnames
run: |
sudo -- sh -c "echo '127.0.0.1 funnel.test' >> /etc/hosts"
sudo -- sh -c "echo '127.0.0.1 f.test' >> /etc/hosts"
- name: Create PostgreSQL databases
run: |
sudo apt-get install postgresql-client -y
psql -h localhost -U postgres -c "create user $(whoami);"
psql -h localhost -U postgres -c "create database funnel_testing;"
psql -h localhost -U postgres -c "create database geoname_testing;"
set -a; source .testenv; set +a
FLASK_ENV=testing flask dbconfig | psql -h localhost -U postgres funnel_testing
FLASK_ENV=testing flask dbconfig | psql -h localhost -U postgres geoname_testing
psql -h localhost -U postgres -c "grant all privileges on database funnel_testing to $(whoami);"
psql -h localhost -U postgres -c "grant all privileges on database geoname_testing to $(whoami);"
psql -h localhost -U postgres funnel_testing -c "grant all privileges on schema public to $(whoami); grant all privileges on all tables in schema public to $(whoami); grant all privileges on all sequences in schema public to $(whoami);"
psql -h localhost -U postgres geoname_testing -c "grant all privileges on schema public to $(whoami); grant all privileges on all tables in schema public to $(whoami); grant all privileges on all sequences in schema public to $(whoami);"
- name: Test with pytest
run: |
pytest --disable-warnings --gherkin-terminal-reporter -vv --showlocals --cov=funnel
- name: Prepare coverage report
run: |
mkdir -p coverage
coverage lcov -o coverage/funnel.lcov
- name: Upload coverage report to Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
path-to-lcov: ./coverage/funnel.lcov
flag-name: python-${{ matrix.python-version }}
parallel: true
finish:
needs: test
runs-on: ubuntu-latest
steps:
- name: Publish to Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
path-to-lcov: ./coverage/funnel.lcov
parallel-finished: true