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

Feature/docstr cicd #19

Merged
merged 6 commits into from
Apr 25, 2024
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
27 changes: 27 additions & 0 deletions .docstr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
paths:
- PQAnalysis
#badge: docs
#exclude: .*/test # regex
verbose: 2 # int (0-3)
skip_magic: True
skip_file_doc: True
skip_init: True
skip_class_def: False
skip_private: True
follow_links: True
#ignore_names_file: .*/test # regex
#fail_under: 90
percentage_only: False
#ignore_patterns: # Dict with key/value pairs of file-pattern/node-pattern
# .*: method_to_ignore_in_all_files
# FileWhereWeWantToIgnoreAllSpecialMethods: "__.+__"
# SomeFile:
# - method_to_ignore1
# - method_to_ignore2
# - method_to_ignore3
# a_very_important_view_file:
# - "^get$"
# - "^set$"
# - "^post$"
# detect_.*:
# - "get_val.*"
102 changes: 102 additions & 0 deletions .github/workflows/docstr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: CI

on:
push:
branches: [dev, main]
pull_request:
branches: [dev, main]
workflow_dispatch:

env:
RANGE: 95..100
ENDPOINT: https://jsonbin.org/${{ github.repository_owner }}/${{ github.event.repository.name }}
TOKEN: ${{ secrets.JSONBIN_APIKEY }}
BRANCH_NAME: ${{ github.head_ref || github.ref_name}}


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 ${{ github.event.pull_request.base.sha }} coverage
run: |
git checkout $BASE
echo "BASE_COV=$(docstr-coverage PQAnalysis -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' && ${{ env.BRANCH_NAME }} == 'main'

- name: Set public endpoint
run: |
curl -X PUT $ENDPOINT/_perms -H "authorization: token $TOKEN"
if: always() && github.event_name == 'push' && ${{ env.BRANCH_NAME }} == 'main'

- name: Show badge URL
run: echo "https://img.shields.io/endpoint?url=$ENDPOINT/badges/docstr-cov"
if: always() && github.event_name == 'push' && ${{ env.BRANCH_NAME }} == 'main'
Loading