forked from tardis-sn/tardis
-
Notifications
You must be signed in to change notification settings - Fork 0
104 lines (82 loc) · 3.34 KB
/
docstr-cov.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
# Log in to jsonbin.org with tardis-bot GitHub account to get an API key and
# store it as a repository secret.
# Updated badge will be available at:
# https://img.shields.io/endpoint?url=https://jsonbin.org/tardis-bot/tardis/badges/docstr-cov
name: docstr-cov
on:
push:
branches:
- master
pull_request:
branches:
- master
env:
THRESHOLD: 0.05
RANGE: 50..75
ENDPOINT: https://jsonbin.org/tardis-bot/${{ github.event.repository.name }}
TOKEN: ${{ secrets.JSONBIN_APIKEY }}
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Install interrogate
run: pip install interrogate==1.5.0 parse==1.19.0 setuptools
- name: Get SHAs
run: |
if [[ ${{ github.event_name }} == 'push' ]]; then
echo "BASE=$(git rev-parse HEAD^)" >> $GITHUB_ENV
echo "HEAD=$(git rev-parse HEAD)" >> $GITHUB_ENV
elif [[ ${{ github.event_name }} == 'pull_request' ]]; then
echo "BASE=${{ github.event.pull_request.base.sha }}" >> $GITHUB_ENV
echo "HEAD=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV
else
echo "Unexpected event trigger"
exit 1
fi
- name: Get ${{ github.event.pull_request.base.sha }} coverage
run: |
git checkout $BASE
echo "BASE_COV=$(interrogate tardis -c pyproject.toml | python .ci-helpers/get_min_docstr_cov.py)" >> $GITHUB_ENV
- name: Test ${{ github.event.pull_request.head.sha }} coverage
run: |
echo "$BASE coverage was: $BASE_COV%"
git checkout $HEAD
interrogate tardis -c pyproject.toml --fail-under=$BASE_COV -v
- name: Blame
run: git diff --name-only $(git merge-base $BASE $HEAD) -- 'tardis/**/*.py' | xargs -i interrogate {} -c pyproject.toml --fail-under=100 -v
if: failure()
- name: Get new coverage
run: echo "NEW_COV=$(interrogate tardis -c pyproject.toml | python .ci-helpers/get_min_docstr_cov.py)" >> $GITHUB_ENV
if: always() && github.event_name == 'push'
- name: Set label color
run: |
if [[ $NEW_COV -ge $(echo {${{ env.RANGE }}} | awk '{print $NF;}') ]]; then
echo "COLOR=green" >> $GITHUB_ENV
elif [[ $NEW_COV -lt $(echo {${{ env.RANGE }}} | awk '{print $1;}') ]]; then
echo "COLOR=red" >> $GITHUB_ENV
else
echo "COLOR=orange" >> $GITHUB_ENV
fi
if: always() && github.event_name == 'push'
- name: Post results
run: |
echo "New coverage is: $NEW_COV%"
curl -X POST $ENDPOINT/badges/docstr-cov \
-H "authorization: token $TOKEN" \
-d "{ \"schemaVersion\": 1, \"label\": \"docstr-cov\", \
\"message\": \"$NEW_COV%\", \"color\": \"$COLOR\" }"
if: always() && github.event_name == 'push'
- name: Set public endpoint
run: |
curl -X PUT $ENDPOINT/_perms -H "authorization: token $TOKEN"
if: always() && github.event_name == 'push'
- name: Show badge URL
run: echo "https://img.shields.io/endpoint?url=$ENDPOINT/badges/docstr-cov"
if: always() && github.event_name == 'push'