Skip to content

Commit

Permalink
Switch to better test reporter, and make it work with PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
ianroberts committed Feb 10, 2023
1 parent 6d68e95 commit 4177256
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 6 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

# Sets permissions of the GITHUB_TOKEN to allow publishing of workflow checks
permissions:
contents: read
id-token: write
checks: write

jobs:
build:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -96,9 +102,10 @@ jobs:
run: mvn --batch-mode -e clean install

- name: Publish Test Report
uses: scacap/action-surefire-report@v1
if: success() || failure()
uses: EnricoMi/publish-unit-test-result-action@v2
with:
fail_if_no_tests: false
junit_files: "target/surefire-reports/*.xml"

- name: Build site
run: mvn --batch-mode -e -DskipTests site
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/pull-request-test-reports.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Test Reports (PR)

on:
workflow_run:
workflows: ["Pull Request"]
types:
- completed

permissions: {}

jobs:
test-results:
name: Test Results
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion != 'skipped'

permissions:
checks: write
pull-requests: write
actions: read

steps:
- name: Download and Extract Artifacts
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: |
mkdir -p artifacts && cd artifacts
artifacts_url=${{ github.event.workflow_run.artifacts_url }}
gh api --paginate "$artifacts_url" -q '.artifacts[] | [.name, .archive_download_url] | @tsv' | while read artifact
do
IFS=$'\t' read name url <<< "$artifact"
gh api $url > "$name.zip"
unzip -d "$name" "$name.zip"
done
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
with:
commit: ${{ github.event.workflow_run.head_sha }}
event_file: artifacts/Event File/event.json
event_name: ${{ github.event.workflow_run.event }}
junit_files: "artifacts/Test Results/**/*.xml"
20 changes: 16 additions & 4 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: Pull Request

on:
pull_request:
Expand Down Expand Up @@ -79,11 +79,13 @@ jobs:
- name: Build with Maven
run: mvn --batch-mode -e clean install

- name: Publish Test Report
uses: scacap/action-surefire-report@v1
- name: Upload Test Results
if: success() || failure()
uses: actions/upload-artifact@v3
with:
fail_if_no_tests: false
name: Test Results
path: |
target/surefire-reports/*.xml
- name: Build site
run: mvn --batch-mode -e -DskipTests site
Expand All @@ -95,3 +97,13 @@ jobs:
if: always()
run: |
find ~/.m2/repository -name \*-SNAPSHOT -type d -exec rm -rf {} \+ || :
event_file:
name: "Event File"
runs-on: ubuntu-latest
steps:
- name: Upload
uses: actions/upload-artifact@v3
with:
name: Event File
path: ${{ github.event_path }}

0 comments on commit 4177256

Please sign in to comment.