-
Notifications
You must be signed in to change notification settings - Fork 2
132 lines (116 loc) · 4.89 KB
/
unit-tests.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
name: unit tests
on:
push: # run on every push or PR to any branch
pull_request:
schedule: # run automatically on main branch each Tuesday at 11am
- cron: "0 16 * * 2"
env:
NODE_VERSION: 16.15
DB_NAME: ppa
DB_USER: ppa
DB_PASSWORD: ppa
jobs:
js-unit:
name: javascript unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm ci
- run: npm run test:unit
- uses: codecov/codecov-action@v3
with:
flags: javascript
python-unit:
name: Python unit tests
runs-on: ubuntu-latest
services:
db:
image: postgres:12
env:
POSTGRES_DB: ppa
POSTGRES_USER: ppa
POSTGRES_PASSWORD: ppa
ports:
- 5432:5432
solr:
image: solr:8.4
ports:
- 8983:8983
steps:
# Set the value of DJANGO_DB_BACKEND which is used in ci/testsettings.py to
# configure django's ORM based on whether we're testing postgres or mysql
- name: Set django database backend adapter
env:
BACKEND: postgresql
run: echo "DJANGO_DB_BACKEND=$(echo "$BACKEND")" >> $GITHUB_ENV
- name: Checkout repository
uses: actions/checkout@v3
# use docker cp to copy the configset, then bash to set ownership to solr
- name: Copy Solr configset to solr service
run: |
docker cp solr_conf ${{ job.services.solr.id }}:/opt/solr/server/solr/configsets/ppa
docker exec --user root ${{ job.services.solr.id }} /bin/bash -c "chown -R solr:solr /opt/solr/server/solr/configsets/ppa"
- name: Copy solr configsets to solr home directory (Solr 8 only)
run: "docker exec -d ${{ job.services.solr.id }} cp -r /opt/solr/server/solr/configsets /var/solr/data"
# NOTE: Python version to use is stored in the .python-version file, which is the
# convention for pyenv: https://github.com/pyenv/pyenv
- name: Get Python version
run: echo "PYTHON_VERSION=$(cat .python-version)" >> $GITHUB_ENV
# use python version for current build
- name: Setup Python
uses: actions/setup-python@v3
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Cache pip
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: pip-${{ env.PYTHON_VERSION }}-${{ hashFiles('requirements.txt') }}
restore-keys: |
pip-${{ env.PYTHON_VERSION }}-${{ hashFiles('requirements.txt') }}
pip-${{ env.PYTHON_VERSION }}
pip-
- name: Install dependencies
run: |
pip install -r requirements.txt
pip install -r dev-requirements.txt
- name: Setup local_settings.py
run: |
cp ci/testsettings.py ppa/local_settings.py
python -c "import uuid; print('SECRET_KEY = \'%s\'' % uuid.uuid4())" >> ppa/local_settings.py
- name: Run pytest
run: py.test --cov=./ --cov-report=xml
- name: Upload test coverage to Codecov
uses: codecov/codecov-action@v3
with:
flags: python
# Set the color of the slack message used in the next step based on the
# status of the build: "warning" for failure and "good" for success
- name: Set Slack message color based on build status
if: ${{ always() }}
env:
JOB_STATUS: ${{ job.status }}
run: echo "SLACK_COLOR=$(if [ "$JOB_STATUS" == "success" ]; then echo "good"; elif [ "$JOB_STATUS" == "failure" ]; then echo "danger"; else echo "warning"; fi)" >> $GITHUB_ENV
# Send a message to slack to report the build status. The webhook is stored
# at the organization level and available to all repositories. Only run on
# scheduled builds & pushes, since PRs automatically report to Slack.
- name: Report status to Slack
uses: rtCamp/action-slack-notify@master
if: ${{ always() && (github.event_name == 'schedule' || github.event_name == 'push') }}
continue-on-error: true
env:
SLACK_COLOR: ${{ env.SLACK_COLOR }}
SLACK_WEBHOOK: ${{ secrets.ACTIONS_SLACK_WEBHOOK }}
SLACK_TITLE: "Run #${{ github.run_number }} for workflow `${{ github.workflow }}`: ${{ job.status }}"
SLACK_MESSAGE: "Run <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|#${{ github.run_number }}> on <https://github.com/${{ github.repository }}/|${{ github.repository }}@${{ github.ref }}>"
SLACK_FOOTER: "<https://github.com/${{ github.repository }}/commit/${{ github.sha }}|View commit>"
MSG_MINIMAL: true # use compact slack message format