-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaction.yaml
158 lines (154 loc) · 5.62 KB
/
action.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
name: 'pycoverage'
author: João Santos
description: >-
Check pytest coverage and fail if tests failed or file and/or total coverage below threshold.
branding:
color: 'purple'
icon: 'check-square'
inputs:
requirements-file:
description: 'Path to the requirements file if you use pip. ./requirements.txt by default'
required: false
default: './requirements.txt'
pytest-root-dir:
description: 'root directory to recursively search for .py files'
required: false
default: '.'
pytest-tests-dir:
description: 'directory with pytest tests. if left empty will identify test(s) dir by default'
required: false
default: './'
cov-omit-list:
description: 'list of directories and/or files to ignore'
required: false
default: ''
cov-threshold-single:
description: 'fail if any single file coverage is less than threshold'
required: false
default: 0
cov-threshold-total:
description: 'fail if the total coverage is less than threshold'
required: false
default: 0
async-tests:
description: 'Add support for async tests'
required: false
default: false
poetry-groups:
description: 'Poetry group names with the dependencies for the tests.'
required: false
default: 'dev,tests'
package-extras:
description: 'Package extras with the dependencies for the tests, or dev-requirement file if pip'
required: false
default: 'dev,tests'
output:
description: 'Output path to write the coverage badge.'
required: false
default: 'badges/coverage.svg'
overwrite:
description: 'Overwrite an existing coverage badge.'
required: false
default: 'true'
github_token:
description: 'GitHub writing token'
required: false
default: ''
working_branch:
description: 'Working branch'
required: false
default: 'main'
commit_badge:
description: 'Boolean to either make a commit on the coverage badge or not'
required: false
default: false
poetry-version:
description: 'Version of poetry. Latest if not specified.'
required: false
outputs:
output-table: # id of output
description: 'pytest-cov markdown output table'
cov-threshold-single-fail:
description: 'boolean if any single file coverage less than cov-threshold-single'
cov-threshold-total-fail:
description: 'boolean if total coverage less than cov-threshold-total'
runs:
using: "composite"
steps:
- id: copy-coverage-processor
run: cp ${{ github.action_path }}/coverage_handler.py ./coverage_handler
shell: bash
- id: run-tests
run: |
${{ github.action_path }}/entrypoint.sh \
"${{ inputs.requirements-file }}" \
"${{ inputs.pytest-root-dir }}" \
"${{ inputs.pytest-tests-dir }}" \
"${{ inputs.cov-omit-list }}" \
${{ inputs.cov-threshold-single }} \
${{ inputs.cov-threshold-total }} \
${{ inputs.async-tests }} \
${{ inputs.poetry-groups }} \
${{ inputs.package-extras }} \
${{ inputs.output }} \
${{ inputs.overwrite }} \
${{ inputs.poetry-version }} \
shell: bash
- run: |
echo "SHORT_SHA=`echo ${{github.event.after}} | cut -c1-7`" >> $GITHUB_ENV
echo "PULL_NUMBER=`echo ${{ github.event.pull_request.number }}`" >> $GITHUB_ENV
echo "COMMIT_URL=`echo https://github.com/${{ github.repository }}/pull/${{ github.event.pull_request.number }}/commits/${{ github.event.after }}`" >> $GITHUB_ENV
shell: bash
- uses: peter-evans/[email protected]
if: ${{ env.PULL_NUMBER }}
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
direction: last
- uses: peter-evans/[email protected]
if: ${{ env.PULL_NUMBER }}
with:
issue-number: ${{env.PULL_NUMBER}}
comment-id: ${{ steps.fc.outputs.comment-id }}
body: |
## Tests coverage table for [${{ env.SHORT_SHA }}](${{ env.COMMIT_URL }}) commit.
${{ steps.run-tests.outputs.output-table }}
edit-mode: replace
- name: Commit pytest coverage table
if: ${{ !env.PULL_NUMBER }}
uses: peter-evans/[email protected]
with:
body: ${{ steps.run-tests.outputs.output-table }}
- name: Verify Changed files
if: inputs.commit_badge == 'true'
uses: tj-actions/verify-changed-files@v14
id: verify-changed-files
with:
files: |
docs/build/html/*
- name: Commit files
if: ${{ (steps.verify-changed-files.outputs.files_changed == 'true') && (inputs.commit_badge == 'true') }}
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add "${{ inputs.output }}"
git commit -m "chore: updating coverage.svg" --no-verify
shell: bash
- name: Push changes
if: ${{ (steps.verify-changed-files.outputs.files_changed == 'true') && (inputs.commit_badge == 'true') }}
uses: ad-m/github-push-action@master
with:
github_token: ${{ inputs.github_token }}
branch: ${{ inputs.working_branch }}
force_with_lease: true
- id: check-threashold
run: |
if [ "${{ steps.run-tests.outputs.cov-threshold-single-fail }}" == "true" ]; then
echo "cov single fail ${{ steps.run-tests.outputs.cov-threshold-single-fail }}";
exit 1;
elif [ "${{ steps.run-tests.outputs.cov-threshold-total-fail }}" == "true" ]; then
echo "cov single fail ${{ steps.run-tests.outputs.cov-threshold-total-fail }}";
exit 1;
fi
shell: bash