Skip to content
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
74 changes: 74 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -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/
47 changes: 0 additions & 47 deletions .github/workflows/merged_master.yml

This file was deleted.

18 changes: 0 additions & 18 deletions .github/workflows/pull_request.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Loading