-
Notifications
You must be signed in to change notification settings - Fork 4
125 lines (110 loc) · 4.36 KB
/
test.yaml
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
name: Run tests
on: [pull_request]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
postgres_version: ['14', '16']
services:
postgres:
image: postgres:${{ matrix.postgres_version }}
env:
POSTGRES_DB: ndoh_hub
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
redis:
image: redis:6.0
ports:
- 6379:6379
env:
HUB_DATABASE: postgres://postgres:postgres@localhost:5432/ndoh_hub
steps:
- uses: actions/checkout@v2
- name: Install gettext
run: sudo apt-get install gettext
- uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ hashFiles('requirements.txt', 'requirements-dev.txt') }}-pip
- uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependancies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt -r requirements-dev.txt
django-admin compilemessages
- name: Lint
run: |
flake8
python manage.py makemigrations registrations changes eventstore \
--dry-run | grep 'No changes detected' || \
(echo 'There are changes which require migrations.' && exit 1)
black --check .
isort -c -rc .
- name: Run tests and generate coverage report
run: |
py.test --cov --cov-report=term-missing | tee coverage.txt
- name: Extract coverage percentage
id: extract_coverage
run: |
COVERAGE=$(grep -oP 'TOTAL\s+\d+\s+\d+\s+\d+\s+\d+\s+\K\d+%' coverage.txt)
echo "COVERAGE=$COVERAGE" >> $GITHUB_ENV
- name: Get changed lines in the PR
id: get_diff
run: |
git fetch origin develop
git diff origin/develop --unified=0 > diff.txt
current_file=""
echo "Changes in files:" > changed_lines.txt
while IFS= read -r line; do
if [[ $line == diff* ]]; then
current_file=$(echo "$line" | awk '{print $3}' | sed 's|^b/||')
fi
if [[ $line == @@* ]]; then
# Get line numbers from the hunk header
line_numbers=$(echo "$line" | grep -oP '\d+(?=\s)' | xargs | tr ' ' ',')
echo "File: $current_file, Changed lines: $line_numbers" >> changed_lines.txt
fi
done < diff.txt
CONTENT=$(cat changed_lines.txt)
echo "changed_lines=$CONTENT" >> $GITHUB_ENV
cat changed_lines.txt
- name: Check for untested lines
id: check_coverage
run: |
UNTTESTED_LINES=""
# Assuming you have a way to get coverage data, replace 'coverage.txt' with your actual coverage file
while IFS= read -r line; do
line_number=$(echo "$line" | grep -oP '\d+')
# Check the coverage file for coverage info for this line number
coverage_info=$(grep -E "^ *$line_number " coverage.txt || true)
echo "Processing line: $line_number"
echo "Coverage info: $coverage_info"
# Check if the coverage info indicates the line is missed
if [[ $coverage_info == *"missed"* ]]; then
UNTTESTED_LINES="$UNTTESTED_LINES\nLine $line_number is not covered by tests."
fi
done < changed_lines.txt
# Save untested lines to the environment variable
echo -e "UNTTESTED_LINES=$UNTTESTED_LINES" >> $GITHUB_ENV
# Optional: Print untested lines for debugging
echo "Untested lines: $UNTTESTED_LINES"
- name: Post coverage comment on PR
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const coverage = process.env.COVERAGE;
const prNumber = context.payload.pull_request.number;
const untestedLines = process.env.UNTTESTED_LINES || "None";
const commentBody = `PR Untested Lines: ${untestedLines}\n\n\nOverall Test coverage: ${coverage}`;
await github.rest.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});