38
38
fail-fast : false
39
39
matrix :
40
40
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
43
43
steps :
44
44
- uses : actions/checkout@v3
45
45
- name : Install dependencies
@@ -48,34 +48,44 @@ jobs:
48
48
poetry install --extras "all"
49
49
- name : Run tests
50
50
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
59
55
uses : actions/upload-artifact@v3
60
56
with :
61
- name : coverage-summary
62
- path : coverage.txt
57
+ name : coverage
58
+ path : . coverage.${{ matrix.python-version }}
63
59
report :
64
60
needs : [test]
65
61
runs-on : ubuntu-20.04
66
62
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
67
71
steps :
72
+ - uses : actions/checkout@v3
68
73
- name : Download coverage summary
69
74
uses : actions/download-artifact@v3
70
75
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'
76
86
with :
77
- filePath : coverage.md
78
- comment_tag : coverage-summary
87
+ name : python- coverage-comment-action
88
+ path : python- coverage-comment-action.txt
79
89
80
90
deploy :
81
91
needs : [lint, test]
0 commit comments