diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..370ea48 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,13 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + - package-ecosystem: "maven" + directory: "/" + schedule: + interval: "weekly" + groups: + maven-minor-and-patch: + update-types: [ "minor", "patch" ] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..cac1f27 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,93 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + workflow_dispatch: + +permissions: + contents: read + +# Supersede outdated PR runs; queue runs on main in order so badges never regress +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +jobs: + test: + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Set up JDK 25 + uses: actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad # v6.1.0 + with: + java-version: '25' + distribution: 'temurin' + cache: 'maven' + + - name: Run tests with coverage + run: ./mvnw -B clean test + + - name: Upload coverage report + if: github.ref == 'refs/heads/main' + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: jacoco-report + path: target/site/jacoco/jacoco.csv + if-no-files-found: error + retention-days: 1 + + # Only this job gets a write token, and only on main + badges: + needs: test + if: github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + timeout-minutes: 10 + permissions: + contents: write + steps: + # Check out the branch tip (not the triggering SHA) so the badge commit fast-forwards + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: main + fetch-depth: 50 + + # A re-run of an older commit must not replace the badges of newer code + - name: Check commit is still the latest on main + id: latest + run: | + if ! git merge-base --is-ancestor "$GITHUB_SHA" HEAD; then + echo "is_latest=false" >> "$GITHUB_OUTPUT" + elif git log --format=%s "$GITHUB_SHA"..HEAD | grep -qvx 'chore: update JaCoCo coverage badges'; then + echo "is_latest=false" >> "$GITHUB_OUTPUT" + else + echo "is_latest=true" >> "$GITHUB_OUTPUT" + fi + + - name: Download coverage report + if: steps.latest.outputs.is_latest == 'true' + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + name: jacoco-report + path: target/site/jacoco + + - name: Generate JaCoCo badge + if: steps.latest.outputs.is_latest == 'true' + uses: cicirello/jacoco-badge-generator@72266185b7ee48a6fd74eaf0238395cc8b14fef8 # v2.12.1 + with: + generate-branches-badge: true + jacoco-csv-file: target/site/jacoco/jacoco.csv + badges-directory: .github/badges + + - name: Commit updated badges + if: steps.latest.outputs.is_latest == 'true' + uses: stefanzweifel/git-auto-commit-action@4a55954c782fc1ea30b9056cd3e7a2b40ca8887d # v7.2.0 + with: + commit_message: "chore: update JaCoCo coverage badges" + file_pattern: '.github/badges/*.svg' diff --git a/README.md b/README.md index 8a62a2d..af60ac0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,8 @@ # java-spring-rest +![CI](https://github.com/andreasarf/java-spring-rest/actions/workflows/ci.yml/badge.svg?branch=main) +![Coverage](.github/badges/jacoco.svg) +![Branches](.github/badges/branches.svg) + Example for implementation Rest API using Spring Boot. ## Requirement diff --git a/lombok.config b/lombok.config new file mode 100644 index 0000000..df71bb6 --- /dev/null +++ b/lombok.config @@ -0,0 +1,2 @@ +config.stopBubbling = true +lombok.addLombokGeneratedAnnotation = true diff --git a/pom.xml b/pom.xml index d8d9d9e..a3b8a0d 100755 --- a/pom.xml +++ b/pom.xml @@ -17,6 +17,7 @@ 25 2.2.55 + 0.8.15 @@ -119,6 +120,25 @@ + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + + prepare-agent + + + + report + test + + report + + + +