1+ name : ci-cd-kotlin.yml
2+ on :
3+ workflow_call :
4+ inputs :
5+ uploadJarArtifact :
6+ required : false
7+ type : boolean
8+ default : false
9+ jarArtifactName :
10+ required : false
11+ type : string
12+ jarArtifactPath :
13+ required : false
14+ type : string
15+
16+ env :
17+ IMAGE_NAME_MIXED_CASE : " ${{ github.repository }}"
18+
19+ jobs :
20+ build-check-test-push :
21+ name : Build, check, test, push
22+ runs-on : ubuntu-latest
23+ steps :
24+ - name : Checkout
25+ uses : actions/checkout@v4
26+ with :
27+ clean : ' true'
28+ fetch-depth : 2
29+
30+ - name : Setup JDK
31+ uses : actions/setup-java@v4
32+ with :
33+ distribution : ' temurin'
34+ java-version : ' 11'
35+ cache : ' maven'
36+
37+ - name : Check code format and lint
38+ run : ./gradlew spotlessApply
39+ env :
40+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
41+
42+ - name : Run tests
43+ run : ./gradlew test
44+
45+ - name : Upload .jar artifact
46+ if : ${{ inputs.uploadJarArtifact }}
47+ uses : actions/upload-artifact@v4
48+ with :
49+ name : ${{ inputs.jarArtifactName }}
50+ path : ${{ inputs.jarArtifactPath }}
51+
52+ - name : Build artifact
53+ run : ./gradlew build -x test
54+
55+ - name : Lowercase Docker Image Name
56+ run : |
57+ echo "IMAGE_NAME=${IMAGE_NAME_MIXED_CASE,,}" >> "${GITHUB_ENV}"
58+ - name : Build Docker Image
59+ uses : docker/build-push-action@v6
60+ with :
61+ context : .
62+ push : ' false'
63+ tags : ' hsldevcom/${{ env.IMAGE_NAME }}:${{ github.sha }}'
64+
65+ - name : Setup Docker Buildx
66+ if : github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop'
67+ uses : docker/setup-buildx-action@v3
68+
69+ - name : Extract Docker metadata
70+ if : github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop'
71+ id : meta
72+ uses : docker/metadata-action@v5
73+ with :
74+ images : ${{ env.IMAGE_NAME }}
75+ tags : |
76+ type=ref,event=branch
77+ type=sha
78+ type=semver,pattern={{version}}
79+ labels : |
80+ org.opencontainers.image.title=${{ env.IMAGE_NAME }}
81+ org.opencontainers.image.vendor=hsldevcom
82+ - name : Login to Github Container Registry
83+ if : github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop'
84+ uses : docker/login-action@v3
85+ with :
86+ registry : hsldevcom
87+ username : ${{ github.actor }}
88+ password : ${{ secrets.GITHUB_TOKEN }}
89+
90+ - name : Build & Push Docker image
91+ if : github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop'
92+ uses : docker/build-push-action@v6
93+ with :
94+ context : .
95+ push : ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' }}
96+ tags : ${{ steps.meta.outputs.tags }}
97+ labels : ${{ steps.meta.outputs.labels }}
0 commit comments