Skip to content

Commit 6852cd6

Browse files
committed
feat/modernize the ci-cd-kotlin flow
1 parent 0835817 commit 6852cd6

1 file changed

Lines changed: 53 additions & 17 deletions

File tree

‎.github/workflows/ci-cd-kotlin.yml‎

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ on:
99
required: false
1010
type: boolean
1111
default: false
12+
workingDirectory:
13+
required: false
14+
type: string
15+
default: .
16+
imageName:
17+
required: false
18+
type: string
1219
runTestsInsideDocker:
1320
required: false
1421
type: boolean
@@ -38,6 +45,7 @@ jobs:
3845

3946
# Required since custom scripts from /scripts are being used
4047
- name: Resolve shared workflow ref
48+
id: resolve_shared_workflow_ref
4149
run: |
4250
set -euo pipefail
4351
SHARED_WORKFLOW_REF=$(grep -roh \
@@ -51,13 +59,13 @@ jobs:
5159
fi
5260
5361
echo "Resolved shared workflow ref: ${SHARED_WORKFLOW_REF}"
54-
echo "SHARED_WORKFLOW_REF=${SHARED_WORKFLOW_REF}" >> "$GITHUB_ENV"
62+
echo "shared_workflow_ref=${SHARED_WORKFLOW_REF}" >> "$GITHUB_OUTPUT"
5563
5664
- name: Checkout shared workflow scripts
5765
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
5866
with:
5967
repository: HSLdevcom/transitdata-shared-workflows
60-
ref: ${{ env.SHARED_WORKFLOW_REF }}
68+
ref: ${{ steps.resolve_shared_workflow_ref.outputs.shared_workflow_ref }}
6169
path: .shared-workflows
6270
persist-credentials: false
6371

@@ -69,18 +77,23 @@ jobs:
6977
cache: 'gradle'
7078

7179
- name: Validate Java version consistency
80+
working-directory: ${{ inputs.workingDirectory }}
7281
env:
82+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7383
JAVA_TOOL_OPTIONS: ""
7484
run: python3 "${GITHUB_WORKSPACE}/.shared-workflows/scripts/validate_java_version_consistency.py"
7585

7686
- name: Check code format and lint
77-
run: ./gradlew spotlessCheck
87+
working-directory: ${{ inputs.workingDirectory }}
7888
env:
79-
GITHUB_ACTOR: ${{ github.actor }}
8089
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
90+
GITHUB_ACTOR: ${{ github.actor }}
91+
JAVA_TOOL_OPTIONS: ""
92+
run: ./gradlew spotlessCheck --stacktrace
8193

8294
- name: Run unit tests inside Docker
8395
if: ${{ inputs.runTestsInsideDocker }}
96+
working-directory: ${{ inputs.workingDirectory }}
8497
env:
8598
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8699
GITHUB_ACTOR: ${{ github.actor }}
@@ -104,18 +117,34 @@ jobs:
104117
-f /tmp/Dockerfile.test \
105118
.
106119
107-
- name: Run unit tests
108-
if: ${{ inputs.hasIntegrationTests == false }}
120+
- name: Run unit tests outside Docker
121+
if: ${{ !inputs.runTestsInsideDocker }}
122+
working-directory: ${{ inputs.workingDirectory }}
109123
env:
124+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
110125
GITHUB_ACTOR: ${{ github.actor }}
126+
JAVA_TOOL_OPTIONS: ""
127+
run: ./gradlew test --stacktrace
128+
129+
# Equivalent of `mvn verify`: produces the Jacoco coverage report consumed by Codecov
130+
- name: Generate coverage report
131+
if: ${{ !inputs.hasIntegrationTests }}
132+
working-directory: ${{ inputs.workingDirectory }}
133+
env:
111134
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
135+
GITHUB_ACTOR: ${{ github.actor }}
136+
JAVA_TOOL_OPTIONS: ""
112137
run: ./gradlew test jacocoTestReport --stacktrace
113138

114-
- name: Run unit tests and integration tests
139+
- name: Run Integration tests (Testcontainers)
115140
if: ${{ inputs.hasIntegrationTests }}
141+
working-directory: ${{ inputs.workingDirectory }}
116142
env:
117-
GITHUB_ACTOR: ${{ github.actor }}
118143
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
144+
GITHUB_ACTOR: ${{ github.actor }}
145+
DOCKER_HOST: unix:///var/run/docker.sock
146+
TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE: /var/run/docker.sock
147+
JAVA_TOOL_OPTIONS: ""
119148
run: ./gradlew test integrationTest jacocoTestReport --stacktrace
120149

121150
- name: Upload coverage reports to Codecov
@@ -133,12 +162,6 @@ jobs:
133162
fail_ci_if_error: true
134163
report_type: test_results
135164

136-
- name: Build artifact
137-
run: ./gradlew build -x test
138-
env:
139-
GITHUB_ACTOR: ${{ github.actor }}
140-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
141-
142165
release:
143166
name: Build & push Docker image
144167
needs: ci
@@ -157,9 +180,19 @@ jobs:
157180
clean: 'true'
158181
persist-credentials: false
159182

160-
- name: Lowercase Docker Image Name
183+
- name: Set Docker Image Name
184+
env:
185+
IMAGE_NAME_INPUT: ${{ inputs.imageName }}
161186
run: |
162-
echo "IMAGE_NAME=${IMAGE_NAME_MIXED_CASE,,}" >> "${GITHUB_ENV}"
187+
OWNER="${GITHUB_REPOSITORY%%/*}"
188+
189+
if [[ -n "${IMAGE_NAME_INPUT}" ]]; then
190+
IMAGE_NAME="${OWNER,,}/${IMAGE_NAME_INPUT}"
191+
else
192+
IMAGE_NAME="${GITHUB_REPOSITORY,,}"
193+
fi
194+
195+
echo "IMAGE_NAME=${IMAGE_NAME}" >> "$GITHUB_ENV"
163196
164197
- name: Setup Docker Buildx
165198
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
@@ -186,7 +219,10 @@ jobs:
186219
- name: Build & Push Docker image
187220
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
188221
with:
189-
context: .
222+
context: ${{ inputs.workingDirectory }}
190223
push: true
191224
tags: ${{ steps.meta.outputs.tags }}
192225
labels: ${{ steps.meta.outputs.labels }}
226+
secrets: |
227+
github_token=${{ secrets.GITHUB_TOKEN }}
228+
github_actor=${{ github.actor }}

0 commit comments

Comments
 (0)