Skip to content

Commit

Permalink
Added JUnit as part of reusable pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
hirenkp2000 committed Nov 23, 2023
1 parent fa601b8 commit 97f036d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 75 deletions.
55 changes: 48 additions & 7 deletions .github/workflows/reusable-build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ on:
description: 'Unique version which should be used in next step(s) for CodeDeploy artifact (e.g. 20230528-144100_d63fd762704ef242d9827662b872b305744f753e)'
value: ${{ jobs.main.outputs.codedeploy-artifact-version }}


permissions:
checks: write # for junit reporting
pull-requests: write # for jacoco PR comments

env:
MIN_COVERAGE_OVERALL: 25
MIN_COVERAGE_CHANGED_FILES: 65
SERVICE_JAR_DIR: ${{ github.workspace }}/build/libs
CODEDEPLOY_DIR: ${{ github.workspace }}/deployment/codedeploy
GITHUB_CODEDEPLOY_ARTIFACT_NAME: codedeploy-artifact
Expand All @@ -23,6 +30,20 @@ jobs:
pipeline-artifact-name: ${{ steps.save-artifact-name.outputs.name }}
app-version: ${{ steps.save-app-version.outputs.version }}
codedeploy-artifact-version: ${{ steps.save-artifact-version.outputs.version }}
services:
postgres:
image: postgis/postgis # Postgres with PostGIS extension
env:
POSTGRES_PASSWORD: password
POSTGRES_USER: postgres
POSTGRES_DB: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- run: echo "[${{ github.triggering_actor }}] triggered [${{ github.event_name }}] event on ${{ github.ref_type }}/PR# [${{ github.ref_name }}]"
- run: echo "🎉 This job is running on a ${{ runner.os }} server hosted by GitHub!"
Expand All @@ -31,16 +52,36 @@ jobs:
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: adopt
java-version: 17
java-package: jdk
cache: gradle
### TODO : Include JUnit tests & verify code coverage
- name: Build package, execute tests & verify overall coverage
distribution: 'temurin'
java-version: '17'
java-package: 'jdk'
cache: 'gradle'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
arguments: shadowJar -x test
gradle-version: 8.2
### Build, Test, Coverage Verification
- name: Build fat jar, including Unit tests, coverage verification
run: gradle shadowJar jacocoTestReport jacocoTestCoverageVerification
- name: Publish Test Report
uses: mikepenz/action-junit-report@v4
if: success() || failure() # always run even if the previous step fails
with:
report_paths: '**/build/test-results/test/TEST-*.xml'
- name: Publish code coverage report as PR comment
id: jacoco
uses: madrapps/[email protected]
with:
paths: '**/build/reports/jacoco/test/jacocoTestReport.xml'
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: $MIN_COVERAGE_OVERALL
min-coverage-changed-files: $MIN_COVERAGE_CHANGED_FILES
title: Code Coverage
- name: Fail when coverage of changed files is too low
run: |
CHANGED_FILES_FAILED=$(echo '${{ steps.jacoco.outputs.coverage-changed-files }} < ${{ env.MIN_COVERAGE_CHANGED_FILES }}' | bc)
[[ $CHANGED_FILES_FAILED -ne 0 ]] && echo 'Changed files coverage ${{ steps.jacoco.outputs.coverage-changed-files }}% is smaller than required ${{ env.MIN_COVERAGE_CHANGED_FILES }}%'
[[ $CHANGED_FILES_FAILED -ne 0 ]] && exit 1 || exit 0
- name: List generated artifacts
run: |
ls -l $SERVICE_JAR_DIR/*
Expand Down
68 changes: 0 additions & 68 deletions .github/workflows/test.yaml

This file was deleted.

0 comments on commit 97f036d

Please sign in to comment.