-
Notifications
You must be signed in to change notification settings - Fork 0
151 lines (137 loc) · 4.49 KB
/
Copy pathci-cd-kotlin.yml
File metadata and controls
151 lines (137 loc) · 4.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
name: ci-cd-kotlin.yml
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: |
if [[ "${GITHUB_REF}" == "refs/heads/main" || "${GITHUB_REF}" == "refs/heads/develop" || "${GITHUB_REF}" == "refs/heads/aks-dev"]]; then
echo "PERFORM_RELEASE=true" >> $GITHUB_ENV
elif [[ "${{ inputs.performRelease }}" == "true" ]]; then
echo "PERFORM_RELEASE=true" >> $GITHUB_ENV
else
echo "PERFORM_RELEASE=false" >> $GITHUB_ENV
fi
echo "Perform release condition: 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 }}