Skip to content

Commit

Permalink
fix(ci): separate workflow "Test application (test + coverage)" for P…
Browse files Browse the repository at this point in the history
…R and repo

Separate the one workflow into two single ones to avoid pipeline failure during report generation because of missing permissions.
At the same time make all necessary/dependent changes to gradle.build and the Taskfile tasks.
  • Loading branch information
pmoscode committed Nov 21, 2023
1 parent 406fcff commit 6de785b
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 110 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/app-test-coverage-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
## /********************************************************************************
## * Copyright (c) 2023 Contributors to the Eclipse Foundation
## *
## * See the NOTICE file(s) distributed with this work for additional
## * information regarding copyright ownership.
## *
## * This program and the accompanying materials are made available under the
## * terms of the Apache License, Version 2.0 which is available at
## * https://www.apache.org/licenses/LICENSE-2.0.
## *
## * Unless required by applicable law or agreed to in writing, software
## * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
## * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
## * License for the specific language governing permissions and limitations
## * under the License.
## *
## * SPDX-License-Identifier: Apache-2.0
## ********************************************************************************/

name: Application test and coverage -- PR context

on:
pull_request:
paths:
- 'src/**'

jobs:
test-app:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Java 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'

- name: Test app
env:
GITHUB_USERNAME: ${{ vars.GITHUB_ACTOR }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew test

- name: Get coverage
if: success() || failure()
env:
GITHUB_USERNAME: ${{ vars.GITHUB_ACTOR }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew jacocoTestReport

- name: Upload test results
uses: actions/upload-artifact@v3
if: success() || failure()
with:
name: test-results
path: ${{ github.workspace }}/build/

- name: Publish code coverage report as PR comment
uses: madrapps/jacoco-report@v1.6.1
if: success() || failure()
with:
paths: |
${{ github.workspace }}/build/reports/xml/jacoco
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 80
min-coverage-changed-files: 80
title: Coverage Report
72 changes: 72 additions & 0 deletions .github/workflows/app-test-coverage-repo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
## /********************************************************************************
## * Copyright (c) 2023 Contributors to the Eclipse Foundation
## *
## * See the NOTICE file(s) distributed with this work for additional
## * information regarding copyright ownership.
## *
## * This program and the accompanying materials are made available under the
## * terms of the Apache License, Version 2.0 which is available at
## * https://www.apache.org/licenses/LICENSE-2.0.
## *
## * Unless required by applicable law or agreed to in writing, software
## * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
## * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
## * License for the specific language governing permissions and limitations
## * under the License.
## *
## * SPDX-License-Identifier: Apache-2.0
## ********************************************************************************/

name: Application test and coverage -- Repository context

on:
workflow_run:
workflows: [ 'Application test and coverage -- PR context' ]
types:
- completed

permissions:
contents: read
actions: read
checks: write

jobs:
test-app:
runs-on: ubuntu-latest

steps:
- name: Download test results
uses: actions/download-artifact@v3
with:
name: test-results
path: ${{ github.workspace }}/

- name: Setup .NET Core # Required to execute ReportGenerator
uses: actions/setup-dotnet@v3
if: success() || failure()
with:
dotnet-version: 6.x
dotnet-quality: 'ga'

- name: Generate test report
uses: dorny/test-reporter@v1.6.0
if: success() || failure()
with:
name: Test results
path: 'test-results/test/*.xml'
reporter: java-junit
fail-on-error: false

- name: Generate code coverage report
uses: danielpalme/ReportGenerator-GitHub-Action@5.1.25
if: success() || failure()
with:
reports: reports/xml/jacoco
targetdir: coveragereport
reporttypes: MarkdownSummaryGithub
sourcedirs: src/main/java
title: 'Code Coverage'

- name: Publish code coverage report as job summary
if: success() || failure()
run: cat coveragereport/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
101 changes: 0 additions & 101 deletions .github/workflows/app-test-coverage.yml

This file was deleted.

14 changes: 6 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,6 @@ dependencyManagement {
}
}

tasks.named('test', Test) {
useJUnitPlatform()
}

// 'build' task comes from the 'java' plugin
// docs: https://docs.gradle.org/current/userguide/java_plugin.html
build {
Expand All @@ -209,6 +205,7 @@ bootJar {
// 'test' comes from the 'java' plugin
// docs: https://docs.gradle.org/current/userguide/java_plugin.html
test {
useJUnitPlatform()
finalizedBy jacocoTestReport
}

Expand All @@ -221,12 +218,13 @@ htmlDependencyReport {
// 'jacocoTestReport' is provided by the 'jacoco' plugin
// docs: https://docs.gradle.org/current/userguide/jacoco_plugin.html
jacocoTestReport {
dependsOn test

reports {
xml.required = false
csv.required = false
html.required = true
xml.enabled true
csv.enabled false
html.enabled true
html.destination file("${buildDir}/reports/html/jacoco")
xml.destination file("${buildDir}/reports/xml/jacoco")
}

afterEvaluate {
Expand Down
5 changes: 4 additions & 1 deletion dev-assets/tasks/darwin/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,18 @@ tasks:

test-report:
desc: Generates the test report for MIW
ignore_error: true
cmds:
- ./gradlew test
- ./gradlew jacocoTestReport

coverage:
desc: Runs the coverage check
cmds:
- task: test-report
- ./gradlew jacocoTestCoverageVerification

clean:
desc: Cleans the build directory
cmds:
- ./gradlew clean
- ./gradlew clean
3 changes: 3 additions & 0 deletions dev-assets/tasks/linux/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ tasks:

test-report:
desc: Generates the test report for MIW
ignore_error: true
cmds:
- ./gradlew test
- ./gradlew jacocoTestReport

coverage:
desc: Runs the coverage check
cmds:
- task: test-report
- ./gradlew jacocoTestCoverageVerification

clean:
Expand Down

0 comments on commit 6de785b

Please sign in to comment.