-
Notifications
You must be signed in to change notification settings - Fork 0
104 lines (81 loc) · 2.93 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 yout 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/<username>/<repository>/badges/docstr-cov
name: docstr-cov
on:
push:
branches:
- main
pull_request:
branches:
- main
env:
RANGE: 50..75
ENDPOINT: https://api.jsonbin.io/v3
TOKEN: ${{ secrets.JSONBIN_APIKEY }}
ID_BIN: 62e15eac8ebcdb758843f9af
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.x
- name: Install docstr-coverage
run: pip install docstr-coverage
- 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 base coverage
run: |
git checkout $BASE
echo "BASE_COV=$(docstr-coverage -p)" >> $GITHUB_ENV
- name: Test head coverage
run: |
git checkout $HEAD
docstr-coverage --fail-under=$BASE_COV
- name: Blame
run: |
git diff --name-only $(git merge-base $BASE $HEAD) | \
xargs docstr-coverage --accept-empty
if: failure()
- name: Get new coverage
run: echo "NEW_COV=$(printf "%.f" $(docstr-coverage -p))" >> $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: Set post result endpoint
run: |
curl -v -H "Content-Type: application/json" \
-H "X-Master-key: $TOKEN" \
-H "X-Bin-Private: false" \
--request PUT \
--data "{ \"schemaVersion\": 1, \"label\": \"docstr-cov\", \
\"message\": \"$NEW_COV%\", \"color\": \"$COLOR\" }" \
$ENDPOINT/b/$ID_BIN
if: always() && github.event_name == 'push'
- name: Show badge URL
run: echo "https://img.shields.io/endpoint?url=$ENDPOINT/b/$ID_BIN?meta=false"
if: always() && github.event_name == 'push'