Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix workflows for PRs coming from forked repositories #154

Merged
merged 2 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,23 @@ jobs:
id: build
run: mvn -B -U "-Dsurefire.rerunFailingTestsCount=5" clean install

- name: Archive Test Results on Failure
- name: Archive Test Results
uses: actions/upload-artifact@v2
if: always()
with:
name: Unit Test Results ${{ matrix.os }}
path: target/surefire-reports/
retention-days: 7

publish-test-results:
name: Publish Unit Test Results
runs-on: ubuntu-latest
needs: build-and-test
if: always()

steps:
- name: Download Artifacts
uses: actions/download-artifact@v2
with:
path: artifacts

- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v1.26
with:
files: artifacts/**/*.xml

# We need to upload the event file as an artifact in order to support publishing the results of
# forked repositories (https://github.com/EnricoMi/publish-unit-test-result-action#support-fork-repositories-and-dependabot-branches)
event_file:
name: "Event File"
runs-on: ubuntu-latest
steps:
- name: Upload
uses: actions/upload-artifact@v2
with:
name: Event File
path: ${{ github.event_path }}
retention-days: 1
37 changes: 37 additions & 0 deletions .github/workflows/publish-test-results.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Publishing of unit test results has to be a separate workflow in order to support forked PRs
# See https://github.com/EnricoMi/publish-unit-test-result-action#support-fork-repositories-and-dependabot-branches
name: Publish Unit Test Results
on:
workflow_run:
workflows: [Build and test]
types:
- completed
jobs:
unit-test-results:
name: Unit Test Results
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion != 'skipped'

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 "$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 Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
with:
commit: ${{ github.event.workflow_run.head_sha }}
event_file: artifacts/Event File/event.json
event_name: ${{ github.event.workflow_run.event }}
files: "artifacts/**/*.xml"