diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 70511cf8c..077f322ae 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -11,6 +11,12 @@ on: default: main required: false type: string + badge_branch: + description: 'The branch which contains the jacoco badge for above branch' + default: badge_main + required: false + type: string + jobs: build: @@ -20,7 +26,13 @@ jobs: java: ['21'] name: Java ${{ matrix.Java }} build steps: - - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v2 + - name: Checkout badges branch to a badges directory nested inside first checkout + uses: actions/checkout@v2 + with: + ref: ${{ inputs.badge_branch }} + path: badges - name: Setup java uses: actions/setup-java@v2 with: @@ -36,11 +48,23 @@ jobs: id: jacoco uses: cicirello/jacoco-badge-generator@v2.1.0 with: + badges-directory: badges jacoco-csv-file: build/reports/jacoco/test/jacocoTestReport.csv - name: Log coverage percentage run: | echo "coverage = ${{ steps.jacoco.outputs.coverage }}" echo "branch coverage = ${{ steps.jacoco.outputs.branches }}" + - name: Commit and push badge + if: ${{ github.event_name != 'pull_request' }} + run: | + cd badges + if [[ `git status --porcelain *.svg` ]]; then + git config --global user.name github_actions + git add *.svg + git commit -m "Autogenerated JaCoCo coverage badge" *.svg + git push + fi + cd .. - name: Upload JaCoCo coverage report uses: actions/upload-artifact@v4 with: diff --git a/.github/workflows/gradle_main.yml b/.github/workflows/gradle_main.yml index e32796a38..2af9e5265 100644 --- a/.github/workflows/gradle_main.yml +++ b/.github/workflows/gradle_main.yml @@ -1,7 +1,7 @@ # This workflow will build a Java project with Gradle # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle -name: Java CI with Gradle for master branch +name: Java CI with Gradle for main branch on: push: diff --git a/.github/workflows/gradle_v0.x.yml b/.github/workflows/gradle_v0.x.yml index c4cb8acf4..28257521f 100644 --- a/.github/workflows/gradle_v0.x.yml +++ b/.github/workflows/gradle_v0.x.yml @@ -14,3 +14,4 @@ jobs: uses: Yelp/nrtsearch/.github/workflows/gradle.yml@v0.x with: branch: v0.x + badge_branch: badge_v0.x