Skip to content

Commit

Permalink
✨ Update to new Python tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jemrobinson committed Sep 24, 2024
1 parent 7b9f3d5 commit e429cd8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 14 deletions.
42 changes: 28 additions & 14 deletions .github/workflows/test_code.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,32 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install bats
run: sudo apt-get update && sudo apt-get install bats
- name: Install ruby
uses: ruby/setup-ruby@v1

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.11

- name: Install hatch
run: pip install hatch

- name: Test Python
run: hatch run test:all

# For security reasons, PRs created from forks cannot generate PR comments directly
# (see https://securitylab.github.com/research/github-actions-preventing-pwn-requests/).
# Instead we need to trigger another workflow after this one completes.
- name: Generate coverage comment
id: coverage_comment
uses: py-cov-action/python-coverage-comment-action@v3
with:
GITHUB_TOKEN: ${{ github.token }}

# Save the coverage comment for later use
# See https://github.com/py-cov-action/python-coverage-comment-action/blob/main/README.md
- name: Save coverage comment as an artifact
uses: actions/upload-artifact@v4
if: steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true'
with:
ruby-version: 3.4
- name: Install ruby dependencies
run: gem install mustache
- name: Install yq
run: |
VERSION=v4.44.1
BINARY=yq_linux_amd64
wget https://github.com/mikefarah/yq/releases/download/${VERSION}/${BINARY}.tar.gz -O - | tar xz && sudo mv ${BINARY} /usr/bin/yq
- name: Run tests
run: bats tests
name: python-coverage-comment-action
path: python-coverage-comment-action.txt
32 changes: 32 additions & 0 deletions .github/workflows/test_coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
name: Test code - post coverage comment

# Run workflow after test_code has completed
on: # yamllint disable-line rule:truthy
workflow_run:
workflows: ["Test code"]
types:
- completed

jobs:
coverage:
runs-on: ubuntu-latest
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
permissions:
# Gives the action the necessary permissions for publishing new
# comments in pull requests.
pull-requests: write
# Gives the action the necessary permissions for editing existing
# comments (to avoid publishing multiple comments in the same PR)
contents: write
# Gives the action the necessary permissions for looking up the
# workflow that launched this workflow, and download the related
# artifact that contains the comment to be published
actions: read
steps:
# Post the pre-generated coverage comment
- name: Post coverage comment
uses: py-cov-action/python-coverage-comment-action@v3
with:
GITHUB_TOKEN: ${{ github.token }}
GITHUB_PR_RUN_ID: ${{ github.event.workflow_run.id }}

0 comments on commit e429cd8

Please sign in to comment.