forked from nutanix/calm-dsl
-
Notifications
You must be signed in to change notification settings - Fork 0
77 lines (77 loc) · 2.3 KB
/
pre_commit_test.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
name: run pre commit tests
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python-version: ['3.9']
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
node-version: 16
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: black
uses: psf/black@stable
with:
version: "22.6.0"
options: "--check --extend-exclude tests/escript/scripts/"
- name: Setup env
run: |
python -m pip install --upgrade pip
pip install virtualenv
- name: Install requirements
run: |
make dev
- name: Set environment variables
shell: bash
run: |
value="MOCK"
echo "CALM_DSL_TESTS=$value" >> $GITHUB_ENV
- name: Build test environment
run: |
source venv/bin/activate
cd tests/mock && make mock-db-location && make mock-db
- name: Run Tests and Calculate Coverage
id: pytest
run: |
source venv/bin/activate
echo -e "\npython_files = tests/unit/*" >> pytest.ini
echo -e "filterwarnings = ignore::DeprecationWarning" >> pytest.ini
set +e
pytest -m pre_commit > logs.txt
exit_code=$?
echo "PYTEST_EXIT_CODE=$exit_code" >> $GITHUB_ENV
set -e
coverage_percentage=$(coverage report -m | awk '/TOTAL/ {print $6}')
echo "COVERAGE_PERCENTAGE=$coverage_percentage" >> $GITHUB_ENV
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: test-logs
path: logs.txt
retention-days: 5
- name: Check threshold coverage
run: |
if [ $PYTEST_EXIT_CODE -ne 0 ]; then
echo "Pytest failed check test-logs for details."
exit 1
fi
coverage=$(echo "$COVERAGE_PERCENTAGE" | sed 's/%//')
if [ "$coverage" -lt 10 ]; then
echo "Code coverage is below the threshold (10%). Blocking PR."
exit 1
fi
env:
CI: true