From 945eb8dc5c05dcf95f8ddc9377bfda67c226ddd3 Mon Sep 17 00:00:00 2001 From: Esteban Maya Date: Thu, 7 Mar 2024 18:03:15 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20Add=20coverage=20with=20Smokesho?= =?UTF-8?q?w=20to=20CI=20and=20badge=20(#638)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sebastián Ramírez --- .github/workflows/smokeshow.yml | 35 +++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 19 +++++++++++++++++- README.md | 8 ++++++++ backend/scripts/test.sh | 4 +++- 4 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/smokeshow.yml diff --git a/.github/workflows/smokeshow.yml b/.github/workflows/smokeshow.yml new file mode 100644 index 0000000000..b685a1c680 --- /dev/null +++ b/.github/workflows/smokeshow.yml @@ -0,0 +1,35 @@ +name: Smokeshow + +on: + workflow_run: + workflows: [Test] + types: [completed] + +permissions: + statuses: write + +jobs: + smokeshow: + if: ${{ github.event.workflow_run.conclusion == 'success' }} + runs-on: ubuntu-latest + + steps: + - uses: actions/setup-python@v4 + with: + python-version: '3.9' + + - run: pip install smokeshow + + - uses: dawidd6/action-download-artifact@v2.28.0 + with: + workflow: test.yml + commit: ${{ github.event.workflow_run.head_sha }} + + - run: smokeshow upload coverage-html + env: + SMOKESHOW_GITHUB_STATUS_DESCRIPTION: Coverage {coverage-percentage} + SMOKESHOW_GITHUB_COVERAGE_THRESHOLD: 90 + SMOKESHOW_GITHUB_CONTEXT: coverage + SMOKESHOW_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SMOKESHOW_GITHUB_PR_HEAD_SHA: ${{ github.event.workflow_run.head_sha }} + SMOKESHOW_AUTH_KEY: ${{ secrets.SMOKESHOW_AUTH_KEY }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index febd40de88..1f25ec92d3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,6 +29,23 @@ jobs: - name: Docker Compose up run: docker compose up -d - name: Docker Compose run tests - run: docker compose exec -T backend bash /app/tests-start.sh + run: docker compose exec -T backend bash /app/tests-start.sh "Coverage for ${{ github.sha }}" - name: Docker Compose cleanup run: docker compose down -v --remove-orphans + - name: Store coverage files + uses: actions/upload-artifact@v3 + with: + name: coverage-html + path: backend/htmlcov + + # https://github.com/marketplace/actions/alls-green#why + alls-green: # This job does nothing and is only used for the branch protection + if: always() + needs: + - test + runs-on: ubuntu-latest + steps: + - name: Decide whether the needed jobs succeeded or failed + uses: re-actors/alls-green@release/v1 + with: + jobs: ${{ toJSON(needs) }} diff --git a/README.md b/README.md index ae468dac79..7b8eeb9b35 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ +

+ + Test + + + Coverage +

+ # FastAPI Project Template ## 🚨 Warning: in (re) construction 😎 🏗️ diff --git a/backend/scripts/test.sh b/backend/scripts/test.sh index fba8e95576..afc004c8cd 100755 --- a/backend/scripts/test.sh +++ b/backend/scripts/test.sh @@ -3,4 +3,6 @@ set -e set -x -pytest --cov=app --cov-report=term-missing app/tests "${@}" +coverage run --source=app -m pytest +coverage report --show-missing +coverage html --title "${@}"