Update pipeline-sun.yml #114
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Budgeting service | |
on: | |
push: | |
branches: | |
- main | |
- ci-cd | |
pull_request: | |
branches: | |
- main | |
jobs: | |
style: | |
runs-on: ubuntu-latest | |
name: Check style | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Run maven checkstyle | |
run: mvn checkstyle:checkstyle | |
compile: | |
runs-on: ubuntu-latest | |
name: Compile project | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
cache: maven | |
- name: Compile project | |
run: mvn clean compile | |
unit-tests: | |
runs-on: ubuntu-latest | |
name: Unit tests | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
cache: maven | |
- name: Running unit tests | |
run: mvn test jacoco:report | |
build: | |
runs-on: ubuntu-latest | |
name: Build project | |
needs: [compile, unit-tests] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
cache: maven | |
- name: Building project | |
run: mvn package | |
coverage: | |
runs-on: ubuntu-latest | |
env: | |
FROM_ORIGINAL_REPOSITORY: ${{ github.event.pull_request.head.repo.full_name == github.repository || github.ref == 'refs/heads/main' }} | |
permissions: | |
pull-requests: write | |
packages: write | |
name: Coverage and Package | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
cache: maven | |
- name: Building project | |
run: mvn package | |
- name: Add coverage report to PR | |
uses: madrapps/jacoco-report@v1.6.1 | |
if: ${{ env.FROM_ORIGINAL_REPOSITORY == 'true' }} | |
with: | |
paths: ${{github.workspace}}/target/site/jacoco/jacoco.xml | |
token: ${{secrets.GITHUB_TOKEN}} | |
min-coverage-overall: 30 | |
min-coverage-changed-files: 20 | |
title: 'Sunrise Coverage Report' | |
update-comment: true | |
- name: Log in to the Container registry | |
if: ${{ github.ref == 'refs/heads/main' }} | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push Docker images | |
if: ${{ github.ref == 'refs/heads/main' }} | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
push: true | |
file: Dockerfile | |
platforms: linux/amd64 | |
tags: ghcr.io/${{ github.repository_owner }}/sun-rise:latest | |
- name: Update README with Coverage Badge | |
run: | | |
# Extract coverage percentage from the coverage report | |
coverage=$(grep -oP '(?<=Coverage: )[0-9]+(?=%)' target/site/jacoco/jacoco.xml | head -1) | |
# Define the badge URL with coverage percentage | |
badge_url="https://img.shields.io/badge/coverage-${coverage}%25-brightgreen" | |
# Define the README path | |
readme_path="README.md" | |
# Check if the README file exists | |
if [ -f "$readme_path" ]; then | |
# Update the README with the new badge | |
sed -i "/\[![coverage\](.*)\]/d" $readme_path | |
echo "[![coverage](${badge_url})](https://github.com/${{ github.repository }}/actions/workflows/pipeline-sun.yml)" >> $readme_path | |
else | |
echo "# Coverage Badge" > $readme_path | |
echo "[![coverage](${badge_url})](https://github.com/${{ github.repository }}/actions/workflows/pipeline-sun.yml)" >> $readme_path | |
fi | |
- name: Commit and push changes | |
uses: EndBug/add-and-commit@v7 | |
with: | |
author_name: github-actions | |
author_email: github-actions@github.com | |
message: 'Update README with coverage badge' |