Last active
September 6, 2022 06:07
-
-
Save daveteu/f032dd6d3c88266c9b07c5573705a465 to your computer and use it in GitHub Desktop.
GitHub Actions to run tests and post results on Pull Request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: gotestsum | |
# This action works only on pull request | |
# since the reporter requires the PR id to | |
# generate a Checks report. | |
# Using other events will likely fail the action | |
on: [pull_request] | |
jobs: | |
build: | |
name: Run Tests | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
# The steps here are to run test for Go. | |
# You may ammend the steps to run test for your | |
# own language. | |
- name: Set up Go | |
uses: actions/setup-go@v3 | |
with: | |
go-version: 1.19 | |
- name: Setup gotestsum | |
uses: autero1/[email protected] | |
with: | |
gotestsum_version: 1.8.2 | |
- name: Build and Run Tests | |
run: gotestsum --junitfile test-reports/unit-tests.xml | |
# This is a test reporter which crunches | |
# the numbers generated by the jUnit test. | |
# It also generates the $output that can be used in our PR comments | |
- name: Publish Test Report | |
id: test-reports | |
uses: mikepenz/action-junit-report@v3 | |
if: always() # always run even if the previous step fails | |
with: | |
report_paths: '**/test-reports/unit-tests.xml' | |
detailed_summary: true | |
# These steps post comments on PR. | |
# Search and Delete is implemented to prevent | |
# post being flooded with test results | |
- name: Search for previous action comment. | |
uses: sandeshjangam/comment-actions@v1 | |
id: find_comment | |
with: | |
type: 'find' | |
search_term: 'Latest Test Results' | |
number: ${{ github.event.pull_request.number }} | |
- name: Delete previous action comment. | |
uses: sandeshjangam/comment-actions@v1 | |
id: delete_comment | |
if: ${{ steps.find_comment.outputs.comment_id != '' }} | |
with: | |
type: 'delete' | |
comment_id: ${{ steps.find_comment.outputs.comment_id }} | |
- name: Create Test Results comment | |
uses: thollander/actions-comment-pull-request@v1 | |
with: | |
message: | | |
#### Latest Test Results | |
|| Total | Pass ✅ | Skipped ↪️ | Failed ❌ | | |
|---|---|---|---|---| | |
|Test Report| ${{steps.test-reports.outputs.total}} run | ${{steps.test-reports.outputs.passed}} passed | ${{steps.test-reports.outputs.skipped}} skipped | ${{steps.test-reports.outputs.failed}} failed | | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample Report
Latest Test Results