Skip to content

Commit 05ebbbb

Browse files
authored
replace custom coverage action with py-cov-comment (#113)
Signed-off-by: Grossberger Lukas (CR/AIR2.2) <Lukas.Grossberger@de.bosch.com>
1 parent 906c5a7 commit 05ebbbb

File tree

3 files changed

+86
-96
lines changed

3 files changed

+86
-96
lines changed

.github/workflows/python.yaml

+29-19
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ jobs:
3838
fail-fast: false
3939
matrix:
4040
os: [ubuntu-20.04]
41-
python-version: ["python:3.8", "python:3.9", "python:3.10", "python:3.11"]
42-
container: ${{ matrix.python-version }}-slim
41+
python-version: ["3.8", "3.9", "3.10", "3.11"]
42+
container: python:${{ matrix.python-version }}-slim
4343
steps:
4444
- uses: actions/checkout@v3
4545
- name: Install dependencies
@@ -48,34 +48,44 @@ jobs:
4848
poetry install --extras "all"
4949
- name: Run tests
5050
if: always()
51-
# pipefail ensures that this step still fails when pytest fails
52-
run: |
53-
set -o pipefail
54-
poetry run pytest --cov=blackboxopt tests | sed -n '/ -----------/,$p' > coverage.txt
55-
shell: bash
56-
# Note, this overrides the coverage file for each python version again.
57-
# If different coverage is expected per python version, log separate artifacts.
58-
- name: Upload coverage
51+
run: poetry run coverage run --branch -m pytest tests
52+
env:
53+
COVERAGE_FILE: ".coverage.${{ matrix.python-version }}"
54+
- name: Store coverage file
5955
uses: actions/upload-artifact@v3
6056
with:
61-
name: coverage-summary
62-
path: coverage.txt
57+
name: coverage
58+
path: .coverage.${{ matrix.python-version }}
6359
report:
6460
needs: [test]
6561
runs-on: ubuntu-20.04
6662
if: github.event_name == 'pull_request'
63+
permissions:
64+
# Gives the action the necessary permissions for publishing new
65+
# comments in pull requests.
66+
pull-requests: write
67+
# Gives the action the necessary permissions for pushing data to the
68+
# python-coverage-comment-action branch, and for editing existing
69+
# comments (to avoid publishing multiple comments in the same PR)
70+
contents: write
6771
steps:
72+
- uses: actions/checkout@v3
6873
- name: Download coverage summary
6974
uses: actions/download-artifact@v3
7075
with:
71-
name: coverage-summary
72-
- name: Markdown format
73-
run: echo -e "\`\`\`\n$(cat coverage.txt)\n\`\`\`" > coverage.md
74-
- name: Coverage to PR comment
75-
uses: thollander/actions-comment-pull-request@v2
76+
name: coverage
77+
- name: Coverage comment
78+
id: coverage_comment
79+
uses: py-cov-action/python-coverage-comment-action@v3
80+
with:
81+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
82+
MERGE_COVERAGE_FILES: true
83+
- name: Store Pull Request comment to be posted
84+
uses: actions/upload-artifact@v3
85+
if: steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true'
7686
with:
77-
filePath: coverage.md
78-
comment_tag: coverage-summary
87+
name: python-coverage-comment-action
88+
path: python-coverage-comment-action.txt
7989

8090
deploy:
8191
needs: [lint, test]

0 commit comments

Comments
 (0)