From f85a98d27432ff388d7c18a0c4191195bdb37b4e Mon Sep 17 00:00:00 2001 From: Luis <1105281+lpenap@users.noreply.github.com> Date: Wed, 16 Sep 2026 12:46:25 -0300 Subject: [PATCH] Replace badge workflows with a single maven build workflow Merge merged_master.yml and pull_request.yml into maven.yml, modelled on java-monitor-example. Builds run on pushes to master and on every pull request; badge generation, coverage logging and the dependency graph update run on master pushes only. The badge is committed through a short-lived branch and pull request instead of a direct push, the coverage log step now reads the generator outputs via its step id, and the README build badge points at the new workflow. Co-Authored-By: Claude Fable 5.1 --- .github/workflows/maven.yml | 74 +++++++++++++++++++++++++++++ .github/workflows/merged_master.yml | 47 ------------------ .github/workflows/pull_request.yml | 18 ------- README.md | 2 +- 4 files changed, 75 insertions(+), 66 deletions(-) create mode 100644 .github/workflows/maven.yml delete mode 100644 .github/workflows/merged_master.yml delete mode 100644 .github/workflows/pull_request.yml diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000..516de8b --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,74 @@ +name: maven build + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "**" ] + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + + steps: + - uses: actions/checkout@v7.0.1 + - name: Set up JDK 25 + uses: actions/setup-java@v6.0.1 + with: + java-version: '25' + distribution: 'zulu' + cache: maven + - name: Build with Maven + run: ./mvnw -B -ntp verify + + - name: Update dependency graph + # Refreshes the dependency snapshot Dependabot alerts and security + # updates are based on. Master only, so pull requests cannot rewrite it. + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + uses: advanced-security/maven-dependency-submission-action@v6.0.1 + + - name: Generate JaCoCo Badge + # Master only: pull request builds never commit the badge, so + # generating it there is wasted work. + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + id: jacoco + uses: cicirello/jacoco-badge-generator@v2.12.1 + with: + generate-branches-badge: true + + - name: Log coverage percentage + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + run: | + echo "coverage = ${{ steps.jacoco.outputs.coverage }}" + echo "branch coverage = ${{ steps.jacoco.outputs.branches }}" + + - name: Commit the badge through a pull request (if it changed) + # The badge is pushed to a short-lived branch and merged with the + # workflow token so master never receives a direct push. + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + env: + GH_TOKEN: ${{ github.token }} + run: | + if [[ `git status --porcelain` ]]; then + branch="ci/jacoco-badge-${GITHUB_SHA::7}" + git config --global user.name 'Luis' + git config --global user.email 'lpenap@users.noreply.github.com' + git checkout -b "$branch" + git add -A + git commit -m "Autogenerated JaCoCo coverage badge" + git push origin "$branch" + gh pr create --base master --head "$branch" \ + --title "Autogenerated JaCoCo coverage badge" \ + --body "Coverage badge regenerated by the maven build workflow for ${GITHUB_SHA::7}." + gh pr merge "$branch" --merge --delete-branch + fi + + - name: Upload JaCoCo coverage report + uses: actions/upload-artifact@v7.0.1 + with: + name: jacoco-report + path: target/site/jacoco/ diff --git a/.github/workflows/merged_master.yml b/.github/workflows/merged_master.yml deleted file mode 100644 index 090efce..0000000 --- a/.github/workflows/merged_master.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: maven build - -on: - pull_request: - types: [closed] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v7.0.1 - - name: Set up JDK 25 - uses: actions/setup-java@v6.0.1 - with: - java-version: '25' - distribution: 'zulu' - cache: maven - - name: Build with Maven - run: mvn -B package --file pom.xml - - - name: Generate JaCoCo Badge - uses: cicirello/jacoco-badge-generator@v2.12.1 - with: - generate-branches-badge: true - - - name: Log coverage percentage - run: | - echo "coverage = ${{ steps.jacoco.outputs.coverage }}" - echo "branch coverage = ${{ steps.jacoco.outputs.branches }}" - - - name: Commit the badge (if it changed) - run: | - if [[ `git status --porcelain` ]]; then - git config --global user.name 'Luis' - git config --global user.email 'lpenap@users.noreply.github.com' - git add -A - git commit -m "Autogenerated JaCoCo coverage badge" - git push - fi - - - name: Upload JaCoCo coverage report - uses: actions/upload-artifact@v7.0.1 - with: - name: jacoco-report - path: target/site/jacoco/ diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml deleted file mode 100644 index fa5078b..0000000 --- a/.github/workflows/pull_request.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: PR Build - -on: - pull_request: - branches: ['**'] - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v7.0.1 - - name: Set up JDK 25 - uses: actions/setup-java@v6.0.1 - with: - distribution: 'zulu' - java-version: '25' - - name: Build and Test - run: ./mvnw -B verify diff --git a/README.md b/README.md index 930a336..a0a54f7 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ [![CircleCI](https://dl.circleci.com/status-badge/img/gh/lpenap/java-patterns-and-constructs/tree/master.svg?style=shield)](https://dl.circleci.com/status-badge/redirect/gh/lpenap/java-patterns-and-constructs/tree/master) -[![Build](https://github.com/lpenap/java-patterns-and-constructs/actions/workflows/merged_master.yml/badge.svg)](https://github.com/lpenap/java-patterns-and-constructs/actions/workflows/merged_master.yml) +[![Build](https://github.com/lpenap/java-patterns-and-constructs/actions/workflows/maven.yml/badge.svg)](https://github.com/lpenap/java-patterns-and-constructs/actions/workflows/maven.yml) [![GitHub release](https://img.shields.io/github/release/lpenap/java-patterns-and-constructs)](//github.com/lpenap/java-patterns-and-constructs/releases/latest) ![Coverage](.github/badges/jacoco.svg) ![Branches](.github/badges/branches.svg)