Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

Replace direct main branch push with PR workflow and auto-merge in re… #124

Replace direct main branch push with PR workflow and auto-merge in re…

Replace direct main branch push with PR workflow and auto-merge in re… #124

Workflow file for this run

name: Build
on:
pull_request:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
cache: 'maven'
- name: Build with Maven
run: ./mvnw clean package --file pom.xml --no-transfer-progress
- name: Run tests with coverage
run: ./mvnw test --no-transfer-progress
- name: Generate JaCoCo Badge
id: jacoco
uses: cicirello/jacoco-badge-generator@v2
with:
jacoco-csv-file: target/site/jacoco/jacoco.csv
badges-directory: .github/badges
generate-branches-badge: true
generate-summary: true
- name: Log coverage percentage
run: |
echo "coverage = ${{ steps.jacoco.outputs.coverage }}"
echo "branch coverage = ${{ steps.jacoco.outputs.branches }}"
- name: Upload JaCoCo coverage report
uses: actions/upload-artifact@v4
if: always()
with:
name: jacoco-report
path: target/site/jacoco/
retention-days: 7
- name: Add coverage to PR comment
id: jacoco-comment
uses: madrapps/[email protected]
if: github.event_name == 'pull_request'
with:
paths: |
${{ github.workspace }}/target/site/jacoco/jacoco.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 60
min-coverage-changed-files: 60
title: 'Code Coverage Report'
update-comment: true
- name: Upload build artifacts
uses: actions/upload-artifact@v4
if: success()
with:
name: kottpd-jar
path: target/kottpd-*.jar
retention-days: 7
- name: Commit and push badge (if on main branch)
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
cd .github/badges
if [[ $(git status --porcelain '*.svg') ]]; then
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add *.svg
git commit -m "Autogenerated JaCoCo coverage badge [skip ci]"
git push
fi