-
Notifications
You must be signed in to change notification settings - Fork 0
128 lines (128 loc) · 4.82 KB
/
_check-coverage-action.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
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
126
127
128
name: 'Test Coverage Definition'
on:
workflow_call:
inputs:
coverage-module:
description: "Module to test coverage for"
type: string
required: true
python-version:
description: Python version to set up'
default: '3.11'
type: string
runner-os:
description: 'Runner OS'
default: 'ubuntu-latest'
type: string
upload-coverage:
description: 'Upload coverage results'
default: true
type: boolean
required-coverage:
description: 'Required coverage percentage'
default: 100
type: string
show-test-traceback:
description: "Show traceback for failed tests"
type: string
default: "no"
jobs:
check_coverage:
runs-on: ${{ inputs.runner-os }}
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ inputs.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python-version }}
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
if [[ "$RUNNER_OS" == "macOS" ]]; then
echo "/Users/runner/.local/bin:$PATH" >> $GITHUB_PATH
fi
- name: Configure Poetry
run: poetry config virtualenvs.create false
- name: Install dependencies with Poetry
run: poetry install
- name: Test with pytest
run: |
poetry run pytest tests \
--tb=${{ inputs.show-test-traceback }} \
--cov=${{ inputs.coverage-module }} \
--cov-report=term \
--cov-report=html \
--cov-fail-under=${{ inputs.required-coverage }} > coverage_report.txt
- name: Upload coverage report
if: '!cancelled()'
uses: actions/upload-artifact@v3
with:
name: coverage-report
path: coverage_report.txt
- name: Upload coverage report
if: '!cancelled()'
uses: actions/upload-artifact@v3
with:
name: coverage-report-html
path: htmlcov
- name: Upload coverage to Compass
run: |
METRIC_VALUE=$(cat coverage_report.txt | grep 'Total coverage:' | awk '{print $NF}' | sed 's/%//')
curl --request POST \
--url https://jacksonlaboratory.atlassian.net/gateway/api/compass/v1/metrics \
--user "${{ vars.ATLASSIAN_COMPASS_EMAIL }}:${{ secrets.ATLASSIAN_COMPASS_KEY }}" \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data "{
\"metricSourceId\": \"ari:cloud:compass:44257862-6c68-4d47-8211-da38d2bb001b:metric-source/90bb0329-f6c5-429a-abbc-8d174535ad21/f2a60ca2-5065-4c10-ae99-cb844715b5e3\",
\"value\": $METRIC_VALUE,
\"timestamp\": \"$(date -u +'%Y-%m-%dT%H:%M:%SZ')\"
}"
- name: Upload complexity to Compass
run: |
METRIC_VALUE=$(poetry run radon cc src --total-average | grep 'Average complexity:' | awk '{print $NF}' | sed 's/[\(\)]//g')
curl --request POST \
--url https://jacksonlaboratory.atlassian.net/gateway/api/compass/v1/metrics \
--user "${{ vars.ATLASSIAN_COMPASS_EMAIL }}:${{ secrets.ATLASSIAN_COMPASS_KEY }}" \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data "{
\"metricSourceId\": \"ari:cloud:compass:44257862-6c68-4d47-8211-da38d2bb001b:metric-source/90bb0329-f6c5-429a-abbc-8d174535ad21/480dd6d8-7e86-492f-b929-3cea59711691\",
\"value\": $METRIC_VALUE,
\"timestamp\": \"$(date -u +'%Y-%m-%dT%H:%M:%SZ')\"
}"
comment-coverage-report:
needs: [ check_coverage ]
runs-on: ubuntu-latest
if: ${{always() && github.event_name == 'pull_request'}}
permissions:
pull-requests: write
steps:
- name: Download coverage report artifact
uses: actions/download-artifact@v3
with:
name: coverage-report
- name: Read coverage report
id: read-coverage
run: |
echo "COVERAGE_REPORT<<EOF" >> $GITHUB_ENV
cat coverage_report.txt >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Find Comment
uses: peter-evans/find-comment@v2
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: '### Test Coverage Report'
- name: Create or update comment
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
edit-mode: replace
body: |
### Test Coverage Report
```
${{ env.COVERAGE_REPORT }}
```