From 526f397b8a55f3b9c0c0a27b9dc8b6927f99c532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ezequiel=20P=C3=A1ssaro?= Date: Mon, 25 Apr 2022 17:49:57 -0300 Subject: [PATCH 1/8] Rename workflow yaml file --- .github/workflows/{docstr-coverage.yml => docstr-cov.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{docstr-coverage.yml => docstr-cov.yml} (100%) diff --git a/.github/workflows/docstr-coverage.yml b/.github/workflows/docstr-cov.yml similarity index 100% rename from .github/workflows/docstr-coverage.yml rename to .github/workflows/docstr-cov.yml From 7b5df855719db0d305558d5d734013be26fe89d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ezequiel=20P=C3=A1ssaro?= Date: Mon, 25 Apr 2022 17:51:02 -0300 Subject: [PATCH 2/8] Use new, nicer workflow from 2021 GA Hackathon --- .github/workflows/docstr-cov.yml | 94 +++++++++++++++++++++----------- 1 file changed, 61 insertions(+), 33 deletions(-) diff --git a/.github/workflows/docstr-cov.yml b/.github/workflows/docstr-cov.yml index 2f25d773db2..4c81fbe7650 100644 --- a/.github/workflows/docstr-cov.yml +++ b/.github/workflows/docstr-cov.yml @@ -1,19 +1,30 @@ -name: docstr-coverage +# 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///badges/docstr-cov + +name: docstr-cov on: push: branches: - - master + - main pull_request: branches: - - master + - main + +env: + RANGE: 50..75 + ENDPOINT: https://jsonbin.org/${{ github.repository_owner }}/${{ github.event.repository.name }} + TOKEN: ${{ secrets.JSONBIN_APIKEY }} jobs: check: runs-on: ubuntu-latest - if: ${{ github.event_name == 'pull_request' }} steps: + - uses: actions/checkout@v2 with: fetch-depth: 0 @@ -24,46 +35,63 @@ jobs: python-version: 3.x - name: Install docstr-coverage - run: pip 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 base coverage run: | - git checkout ${{ github.event.pull_request.base.sha }} + git checkout $BASE echo "BASE_COV=$(docstr-coverage -p)" >> $GITHUB_ENV - - - name: Get head coverage + - name: Test head coverage run: | - git checkout ${{ github.event.pull_request.head.sha }} + git checkout $HEAD 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 + git diff --name-only $(git merge-base $BASE $HEAD) | \ + xargs docstr-coverage --accept-empty + if: failure() - - 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) + - 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' - # 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\" }" + 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' - # 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! + - name: Show badge URL + run: echo "https://img.shields.io/endpoint?url=$ENDPOINT/badges/docstr-cov" + if: always() && github.event_name == 'push' \ No newline at end of file From 119df6a3d7d0c2719ca08f11db811f17a383a175 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ezequiel=20P=C3=A1ssaro?= Date: Mon, 25 Apr 2022 17:52:50 -0300 Subject: [PATCH 3/8] Rename `main` branch to `master` --- .github/workflows/docstr-cov.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docstr-cov.yml b/.github/workflows/docstr-cov.yml index 4c81fbe7650..68530894189 100644 --- a/.github/workflows/docstr-cov.yml +++ b/.github/workflows/docstr-cov.yml @@ -9,11 +9,11 @@ name: docstr-cov on: push: branches: - - main + - master pull_request: branches: - - main + - master env: RANGE: 50..75 From a0879dd479768970273b6c4e8a90b1791d499f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ezequiel=20P=C3=A1ssaro?= Date: Mon, 25 Apr 2022 17:58:45 -0300 Subject: [PATCH 4/8] Minor changes --- .github/workflows/docstr-cov.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docstr-cov.yml b/.github/workflows/docstr-cov.yml index 68530894189..ba145921a16 100644 --- a/.github/workflows/docstr-cov.yml +++ b/.github/workflows/docstr-cov.yml @@ -42,6 +42,7 @@ jobs: 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 @@ -50,14 +51,18 @@ jobs: echo "Unexpected event trigger" exit 1 fi - - name: Get base coverage + + - name: Get ${{ github.event.pull_request.base.sha }} coverage run: | git checkout $BASE echo "BASE_COV=$(docstr-coverage -p)" >> $GITHUB_ENV - - name: Test head coverage + echo "$BASE coverage is: $BASE_COV %" + + - name: Test ${{ github.event.pull_request.head.sha }} coverage run: | git checkout $HEAD docstr-coverage --fail-under=$BASE_COV + - name: Blame run: | git diff --name-only $(git merge-base $BASE $HEAD) | \ @@ -72,10 +77,13 @@ jobs: 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' @@ -94,4 +102,4 @@ jobs: - name: Show badge URL run: echo "https://img.shields.io/endpoint?url=$ENDPOINT/badges/docstr-cov" - if: always() && github.event_name == 'push' \ No newline at end of file + if: always() && github.event_name == 'push' From ae3b896a7c690e607cc99bbf9d0348d6e58575ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ezequiel=20P=C3=A1ssaro?= Date: Mon, 25 Apr 2022 18:07:42 -0300 Subject: [PATCH 5/8] Set up tardis-bot JSONbin.org account --- .github/workflows/docstr-cov.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docstr-cov.yml b/.github/workflows/docstr-cov.yml index ba145921a16..1656e4f7952 100644 --- a/.github/workflows/docstr-cov.yml +++ b/.github/workflows/docstr-cov.yml @@ -1,8 +1,8 @@ -# Log in to jsonbin.org with yout GitHub account to get an API key and +# 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///badges/docstr-cov +# https://img.shields.io/endpoint?url=https://jsonbin.org/tardis-bot/tardis/badges/docstr-cov name: docstr-cov @@ -17,7 +17,7 @@ on: env: RANGE: 50..75 - ENDPOINT: https://jsonbin.org/${{ github.repository_owner }}/${{ github.event.repository.name }} + ENDPOINT: https://jsonbin.org/tardis-bot/${{ github.event.repository.name }} TOKEN: ${{ secrets.JSONBIN_APIKEY }} jobs: From e14e0792c2b3326529971fd19fb383b38701f022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ezequiel=20P=C3=A1ssaro?= Date: Mon, 25 Apr 2022 18:23:42 -0300 Subject: [PATCH 6/8] Fix echo statement --- .github/workflows/docstr-cov.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docstr-cov.yml b/.github/workflows/docstr-cov.yml index 1656e4f7952..d2f7114abb4 100644 --- a/.github/workflows/docstr-cov.yml +++ b/.github/workflows/docstr-cov.yml @@ -56,10 +56,10 @@ jobs: run: | git checkout $BASE echo "BASE_COV=$(docstr-coverage -p)" >> $GITHUB_ENV - echo "$BASE coverage is: $BASE_COV %" - 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 From cbd8fd31734308ac21b22bbe1f06063b5c9242e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ezequiel=20P=C3=A1ssaro?= Date: Mon, 25 Apr 2022 18:45:53 -0300 Subject: [PATCH 7/8] Update badge endpoint in README.rst --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From ce37729fe3c9bfa2d66ecfbd5498ab1134de0a7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ezequiel=20P=C3=A1ssaro?= Date: Mon, 25 Apr 2022 19:01:58 -0300 Subject: [PATCH 8/8] Add echo statement --- .github/workflows/docstr-cov.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/docstr-cov.yml b/.github/workflows/docstr-cov.yml index d2f7114abb4..ba8b86566dc 100644 --- a/.github/workflows/docstr-cov.yml +++ b/.github/workflows/docstr-cov.yml @@ -89,6 +89,7 @@ jobs: - 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\", \