Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better docstring coverage workflow from 2021 GA Hackathon #1981

Merged
merged 8 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions .github/workflows/docstr-cov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# 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:
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@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==2.2.0

- 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=$(docstr-coverage -p)" >> $GITHUB_ENV

- name: Test ${{ github.event.pull_request.head.sha }} coverage
run: |
echo "$BASE coverage was: $BASE_COV%"
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: 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'
69 changes: 0 additions & 69 deletions .github/workflows/docstr-coverage.yml

This file was deleted.

4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ stars (*supernovae*).
.. image:: https://codecov.io/gh/tardis-sn/tardis/branch/master/graph/badge.svg
:target: https://codecov.io/gh/tardis-sn/tardis

.. image:: https://img.shields.io/endpoint?url=https://jsonbin.org/tardis-bot/badges/tardis/docstr-coverage
:target: https://github.com/tardis-sn/tardis/actions/workflows/docstr-coverage.yml?query=branch%3Amaster
.. image:: https://img.shields.io/endpoint?url=https://jsonbin.org/tardis-bot/tardis/badges/docstr-cov
:target: https://github.com/tardis-sn/tardis/actions/workflows/docstr-cov.yml?query=branch%3Amaster

.. image:: https://img.shields.io/badge/DOI-10.5281%2Fzenodo.592480-blue
:target: https://doi.org/10.5281/zenodo.592480
Expand Down