Skip to content

Merge branch 'main' into feature/59649-measure-test-coverage #2

Merge branch 'main' into feature/59649-measure-test-coverage

Merge branch 'main' into feature/59649-measure-test-coverage #2

Workflow file for this run

name: ci-cd-kotlin.yml

Check failure on line 1 in .github/workflows/ci-cd-kotlin.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/ci-cd-kotlin.yml

Invalid workflow file

(Line: 69, Col: 14): Unrecognized named-value: 'JACOCO_VERSION'. Located at position 1 within expression: JACOCO_VERSION
on:
workflow_call:
secrets:
DOCKER_USERNAME:
required: true
DOCKER_PASSWORD:
required: true
CODECOV_TOKEN:
required: false
inputs:
uploadJarArtifact:
required: false
type: boolean
default: false
jarArtifactName:
required: false
type: string
jarArtifactPath:
required: false
type: string
performRelease:
required: false
type: boolean
default: false
codeCoverageEnabled:
required: false
type: boolean
default: false
codeCoverageExcludes:
required: false
type: string
default: ""
env:
IMAGE_NAME_MIXED_CASE: "${{ github.repository }}"
JACOCO_VERSION: "0.8.14"
JACOCO_REPORTS: "**/build/reports/jacoco/test/jacocoTestReport.xml,**/build/reports/jacoco/jacoco.xml"
jobs:
build-check-test-push:
name: Build, check, test, push
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
clean: 'true'
fetch-depth: 2
- name: Setup JDK
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
cache: 'gradle'
- name: Check code format and lint
run: ./gradlew spotlessApply
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Run tests
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CODE_COVERAGE_ENABLED: ${{ inputs.codeCoverageEnabled }}
JACOCO_VERSION: ${{ env.JACOCO_VERSION }}
JACOCO_EXCLUDES: ${{ inputs.codeCoverageExcludes }}
run: |
if [[ "${CODE_COVERAGE_ENABLED}" == "true" ]]; then
./gradlew test jacocoTestReport \
-PjacocoVersion="${{ JACOCO_VERSION }}" \
${JACOCO_EXCLUDES:+-PjacocoExcludes=${JACOCO_EXCLUDES}}
else
./gradlew test
fi
- name: Upload coverage reports to Codecov
if: ${{ inputs.codeCoverageEnabled }}
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ${{ env.JACOCO_REPORTS }}
fail_ci_if_error: true
verbose: true
- name: Upload .jar artifact
if: ${{ inputs.uploadJarArtifact }}
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.jarArtifactName }}
path: ${{ inputs.jarArtifactPath }}
- name: Build artifact
run: ./gradlew build -x test
- name: Lowercase Docker Image Name
run: |
echo "IMAGE_NAME=${IMAGE_NAME_MIXED_CASE,,}" >> "${GITHUB_ENV}"
- name: Build Docker Image
uses: docker/build-push-action@v6
with:
context: .
push: 'false'
tags: 'hsldevcom/${{ env.IMAGE_NAME }}:${{ github.sha }}'
- name: Check if perform release
id: perform_release
run: |
PERFORM_RELEASE=false
if [[ "${GITHUB_REF}" == "refs/heads/main" || "${GITHUB_REF}" == "refs/heads/develop" || "${GITHUB_REF}" == "refs/heads/aks-dev" ]]; then
PERFORM_RELEASE=true
elif [[ "${GITHUB_REF}" == refs/tags/* ]]; then
PERFORM_RELEASE=true
elif [[ "${{ inputs.performRelease }}" == "true" ]]; then
PERFORM_RELEASE=true
fi
echo "PERFORM_RELEASE=${PERFORM_RELEASE}" >> $GITHUB_ENV
echo "Perform release: ${PERFORM_RELEASE}"
- name: Setup Docker Buildx
if: env.PERFORM_RELEASE == 'true'
uses: docker/setup-buildx-action@v3
- name: Extract Docker metadata
if: env.PERFORM_RELEASE == 'true'
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=sha
type=semver,pattern={{version}}
labels: |
org.opencontainers.image.title=${{ env.IMAGE_NAME }}
org.opencontainers.image.vendor=hsldevcom
- name: Login to Docker Hub
if: env.PERFORM_RELEASE == 'true'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build & Push Docker image
if: env.PERFORM_RELEASE == 'true'
uses: docker/build-push-action@v6
with:
context: .
push: ${{ env.PERFORM_RELEASE }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}