diff --git a/.github/workflows/docstr-cov.yml b/.github/workflows/docstr-cov.yml new file mode 100644 index 00000000000..ba8b86566dc --- /dev/null +++ b/.github/workflows/docstr-cov.yml @@ -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' diff --git a/.github/workflows/docstr-coverage.yml b/.github/workflows/docstr-coverage.yml deleted file mode 100644 index 2f25d773db2..00000000000 --- a/.github/workflows/docstr-coverage.yml +++ /dev/null @@ -1,69 +0,0 @@ -name: docstr-coverage - -on: - push: - branches: - - master - - pull_request: - branches: - - master - -jobs: - check: - runs-on: ubuntu-latest - if: ${{ github.event_name == 'pull_request' }} - 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 base coverage - run: | - git checkout ${{ github.event.pull_request.base.sha }} - echo "BASE_COV=$(docstr-coverage -p)" >> $GITHUB_ENV - - - name: Get head coverage - run: | - git checkout ${{ github.event.pull_request.head.sha }} - docstr-coverage --fail-under=$BASE_COV - - - name: Blame - if: ${{ failure() }} - run: | - git diff --name-only $(git merge-base ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }}) | xargs docstr-coverage --accept-empty - - post: - runs-on: ubuntu-latest - if: github.repository_owner == 'tardis-sn' && github.event_name == 'push' - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 1 - - - name: Setup Python - uses: actions/setup-python@v2 - with: - python-version: 3.x - - - name: Install docstr-coverage - run: pip install docstr-coverage - - - name: Get coverage (rounded) - run: echo "NEW_COV=$(printf "%.f" $(docstr-coverage -p))" >> $GITHUB_ENV - - # Using jsonbin.org with tardis-bot GitHub account - - name: Post results - run: | - curl -X POST https://jsonbin.org/tardis-bot/badges/tardis/docstr-coverage -H 'authorization: token ${{ secrets.JSONBIN_APIKEY }}' -d "{ \"schemaVersion\": 1, \"label\": \"docstr-coverage\", \"message\": \"$NEW_COV%\", \"color\": \"orange\" }" - - # Updated badge will be available at: https://img.shields.io/endpoint?url=https://jsonbin.org/tardis-bot/badges/tardis/docstr-coverage - # Could take some minutes! diff --git a/README.rst b/README.rst index 9c9c87a847f..6fe8d77c922 100644 --- a/README.rst +++ b/README.rst @@ -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