Skip to content

Commit

Permalink
Upload test coverage for PRs via separate workflow
Browse files Browse the repository at this point in the history
Relates to DependencyTrack#3516

Signed-off-by: nscuro <[email protected]>
Signed-off-by: Mikael Carneholm <[email protected]>
  • Loading branch information
nscuro authored and mikael-carneholm-2-wcar committed Mar 15, 2024
1 parent ade8fe0 commit b871088
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
34 changes: 34 additions & 0 deletions .github/workflows/ci-test-pr-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Report PR Test Coverage

on:
workflow_run:
workflows:
- Tests CI
types:
- completed

permissions: { }

jobs:
publish:
name: Report Coverage
runs-on: ubuntu-latest
if: |-
github.event.workflow_run.event == 'pull_request'
&& github.event.workflow_run.conclusion == 'success'
steps:
- name: Download PR test coverage report
uses: actions/download-artifact@87c55149d96e628cc2ef7e6fc2aab372015aec85 # tag=v4.1.3
with:
name: pr-test-coverage-report
run-id: ${{ github.event.workflow_run.id }}
- name: Report Coverage to Codacy
run: |-
bash <(curl -Ls https://coverage.codacy.com/get.sh) report \
--organization-provider gh \
--username "${GITHUB_REPOSITORY_OWNER}" \
--project-name "${GITHUB_REPOSITORY##*/}" \
--project-token ${{ secrets.CODACY_PROJECT_TOKEN }} \
--commit-uuid "$(cat ./pr-commit.txt)" \
--coverage-reports ./jacoco.xml \
--language Java
21 changes: 20 additions & 1 deletion .github/workflows/ci-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,29 @@ jobs:
mvn clean
mvn test -P enhance
# Publishing coverage to Codacy is only possible for builds of push events.
# PRs from forks do not get access to repository secrets.
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
- name: Publish test coverage
if: ${{ contains(github.repository, 'DependencyTrack/') }}
if: ${{ github.event_name != 'pull_request' && github.repository_owner == 'DependencyTrack' }}
uses: codacy/[email protected]
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
language: Java
coverage-reports: target/jacoco-ut/jacoco.xml

- name: Save PR details
if: ${{ github.event_name == 'pull_request' }}
run: |-
echo ${{ github.sha }} > pr-commit.txt
echo ${{ github.event.number }} > pr-number.txt
- name: Upload PR test coverage report
if: ${{ github.event_name == 'pull_request' }}
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # tag=v4.3.1
with:
name: pr-test-coverage-report
path: |-
pr-commit.txt
pr-number.txt
target/jacoco-ut/jacoco.xml

0 comments on commit b871088

Please sign in to comment.