Skip to content

Commit 736d14e

Browse files
Add coverage comment workflow.
1 parent 56342c1 commit 736d14e

4 files changed

Lines changed: 103 additions & 11 deletions

File tree

.github/workflows/coverage.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Post coverage comment
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Django Tests on PR"]
6+
types:
7+
- completed
8+
9+
jobs:
10+
test:
11+
name: Run tests & display coverage
12+
runs-on: ubuntu-latest
13+
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
14+
permissions:
15+
# Gives the action the necessary permissions for publishing new
16+
# comments in pull requests.
17+
pull-requests: write
18+
# Gives the action the necessary permissions for editing existing
19+
# comments (to avoid publishing multiple comments in the same PR)
20+
contents: write
21+
# Gives the action the necessary permissions for looking up the
22+
# workflow that launched this workflow, and download the related
23+
# artifact that contains the comment to be published
24+
actions: read
25+
steps:
26+
# DO NOT run actions/checkout here, for security reasons
27+
# For details, refer to https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
28+
- name: Post comment
29+
uses: py-cov-action/python-coverage-comment-action@v3
30+
with:
31+
COVERAGE_PATH: django
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
GITHUB_PR_RUN_ID: ${{ github.event.workflow_run.id }}
34+
# Update those if you changed the default values:
35+
# COMMENT_ARTIFACT_NAME: python-coverage-comment-action
36+
# COMMENT_FILENAME: python-coverage-comment-action.txt

.github/workflows/test-django.yml

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ name: Django Tests on PR
22

33
# trigger: every pull-request
44
on:
5-
push: ## FOR TESTING PURPOSES ONLY
6-
branches: [fix/ci_test]
5+
push:
76
pull_request:
8-
branches: [develop]
7+
branches:
8+
- main
9+
- develop
10+
- fix/ci_test
911
workflow_dispatch: # allow manual trigger
1012

1113
permissions:
12-
contents: read
14+
pull-requests: write
15+
contents: write
1316

1417
jobs:
1518
test:
@@ -71,10 +74,56 @@ jobs:
7174
run: |
7275
set -e
7376
cd django
77+
touch .coverage
7478
docker run --rm \
7579
--network host \
7680
-e GITHUB_ACTIONS=true \
7781
-e COVERAGE=true \
82+
-v ./.coverage:/cohiva/.coverage_output_for_github_action \
83+
-v ./htmlcov:/cohiva/htmlcov \
7884
cohiva:test \
7985
sh -c "cp /cohiva/cohiva/base_config_for_tests.py /cohiva/cohiva/base_config.py && /cohiva/setup.py --use-default-certs && /cohiva/run-tests.sh"
8086
exit $?
87+
88+
- name: Coverage comment
89+
id: coverage_comment
90+
uses: py-cov-action/python-coverage-comment-action@v3
91+
with:
92+
COVERAGE_PATH: django
93+
GITHUB_TOKEN: ${{ github.token }}
94+
95+
- name: Store Pull Request comment to be posted
96+
uses: actions/upload-artifact@v4
97+
if: steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true'
98+
with:
99+
# If you use a different name, update COMMENT_ARTIFACT_NAME accordingly
100+
name: python-coverage-comment-action
101+
# If you use a different name, update COMMENT_FILENAME accordingly
102+
path: python-coverage-comment-action.txt
103+
104+
105+
# - name: Upload coverage to Codecov
106+
# uses: codecov/codecov-action@v3.1.0
107+
# with:
108+
# files: ./django/coverage.xml
109+
# fail_ci_if_error: true
110+
# verbose: true
111+
# flags: unittests
112+
# name: codecov-umbrella
113+
# token: ${{ secrets.CODECOV_TOKEN }}
114+
# directory: ./django/
115+
# workdir: ./django/
116+
#
117+
# - name: Upload coverage html report
118+
# #uses: actions/upload-artifact@v3
119+
# uses: actions/upload-pages-artifact@v3
120+
# with:
121+
# #name: coverage-html-report
122+
# path: ./django/htmlcov/
123+
#
124+
#
125+
# - name: Publish to GitHub pages
126+
# #uses: peaceiris/actions-gh-pages@v3
127+
# uses: actions/deploy-pages@v3
128+
# #with:
129+
# # artifact_name: coverage-html-report

django/requirements-docker.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ defusedxml==0.7.1
9292
# willow
9393
dj-rest-auth==7.0.1
9494
# via -r requirements.in
95-
django==4.2.26
95+
django==4.2.27
9696
# via
9797
# -r requirements.in
9898
# dj-rest-auth

django/run-tests.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ COVERAGE_OPTS=()
2121
#COVERAGE_OPTS=(--source "$INSTALL_DIR/django")
2222
#COVERAGE_OPTS=(--append)
2323
if [ -n "$GITHUB_ACTIONS" ] ; then
24-
COVERAGE_OPTS=(--source "/cohiva/")
24+
#COVERAGE_OPTS=(--source "/cohiva/")
25+
cat <<EOT >.coveragerc
26+
[run]
27+
source = /cohiva/
28+
relative_files = True
29+
EOT
30+
2531
fi
2632

2733
if [ -n "$COVERAGE" ] ; then
@@ -40,7 +46,7 @@ TEST_OPTS=""
4046
## Select test to run (leave emtpy to run all tests)
4147
SELECTED_TESTS=""
4248
# Examples:
43-
#SELECTED_TESTS="finance.tests geno.tests.test_documents.DocumentSendTest.test_send_member_bill"
49+
SELECTED_TESTS="finance.tests geno.tests.test_documents.DocumentSendTest.test_send_member_bill"
4450

4551
## Full test suite incl. migrations
4652
# Run tests and capture the exit code of the test runner even though output is piped to tee.
@@ -52,11 +58,12 @@ set -e
5258

5359
if [ -n "$COVERAGE_CMD" ] ; then
5460
if [ -n "$GITHUB_ACTIONS" ] ; then
55-
coverage html 2>&1 | tee coverage.log
56-
echo "TODO: Publish coverage report to GitHub"
57-
else
5861
#coverage html 2>&1 | tee coverage.log
59-
coverage report
62+
# Copy the output to the mounted docker host file
63+
cp .coverage .coverage_output_for_github_action
64+
else
65+
coverage html 2>&1 | tee coverage.log
66+
#coverage report
6067
fi
6168
fi
6269

0 commit comments

Comments
 (0)