Skip to content

Commit 57072cf

Browse files
committed
feat(76477): remove the jarArtifactName and jarArtifact Path and hardcode them
feat(76471): check Java version alignment between Dockerfile and pom.xml feat(76471): check Java version alignment between Dockerfile and pom.xml feat(76471): check Java version alignment between Dockerfile and pom.xml feat(76471): fix the .gitignore and remove the scripts/__pycache__ fix(76471): fix shared workflow scripts checkout using hardcoded repo and workflow_sha github.workflow_ref inside a reusable workflow returns the caller's workflow ref instead of the shared workflow's ref, causing the scripts checkout to target the wrong repository. Replace dynamic resolution with a hardcoded repository name and github.workflow_sha which correctly references the reusable workflow's commit SHA. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> feat(76471): potential fix test(76471): add unit tests for validate_java_version_consistency.py and CI workflow feat(76455): inline the test layer of the Dockerfile in the CI/CD for simplifying the microservice's Dockerfiles feat(76471): fixes after PR review feat(76471): fixes++
1 parent f341192 commit 57072cf

6 files changed

Lines changed: 746 additions & 27 deletions

File tree

.github/workflows/ci-cd-java.yml

Lines changed: 65 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ on:
1212
required: false
1313
type: boolean
1414
default: false
15-
jarArtifactName:
16-
required: false
17-
type: string
18-
jarArtifactPath:
19-
required: false
20-
type: string
2115
performRelease:
2216
required: false
2317
type: boolean
@@ -32,11 +26,10 @@ on:
3226
runTestsInsideDocker:
3327
required: false
3428
type: boolean
35-
default: false
29+
default: true
3630

3731
env:
3832
IMAGE_NAME_MIXED_CASE: "${{ github.repository }}"
39-
TEST_STAGE: test
4033

4134
jobs:
4235
build-check-test-push:
@@ -49,19 +42,80 @@ jobs:
4942
clean: 'true'
5043
fetch-depth: 2
5144

45+
# Required since custom scripts from /scripts are being used
46+
- name: Resolve shared workflow ref
47+
id: resolve_shared_workflow_ref
48+
run: |
49+
set -euo pipefail
50+
SHARED_WORKFLOW_REF=$(grep -roh \
51+
'transitdata-shared-workflows/.github/workflows/[^@]*@[^ "'\'']*' \
52+
"${GITHUB_WORKSPACE}/.github/workflows/" 2>/dev/null \
53+
| sed 's/.*@//' | head -1 || true)
54+
55+
if [[ -z "${SHARED_WORKFLOW_REF}" ]]; then
56+
echo "::warning::Could not detect shared workflow ref from caller workflows; falling back to main"
57+
SHARED_WORKFLOW_REF="main"
58+
fi
59+
60+
echo "Resolved shared workflow ref: ${SHARED_WORKFLOW_REF}"
61+
echo "shared_workflow_ref=${SHARED_WORKFLOW_REF}" >> "$GITHUB_OUTPUT"
62+
63+
- name: Checkout shared workflow scripts
64+
uses: actions/checkout@v4
65+
with:
66+
repository: HSLdevcom/transitdata-shared-workflows
67+
ref: ${{ steps.resolve_shared_workflow_ref.outputs.shared_workflow_ref }}
68+
path: .shared-workflows
69+
5270
- name: Setup JDK
5371
uses: actions/setup-java@v4
5472
with:
5573
distribution: 'temurin'
5674
java-version: '25'
5775
cache: 'maven'
5876

77+
- name: Validate Java version consistency
78+
working-directory: ${{ inputs.workingDirectory }}
79+
env:
80+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
81+
JAVA_TOOL_OPTIONS: ""
82+
MAVEN_OPTS: ""
83+
run: python3 "${GITHUB_WORKSPACE}/.shared-workflows/scripts/validate_java_version_consistency.py"
84+
5985
- name: Check code format and lint
6086
working-directory: ${{ inputs.workingDirectory }}
6187
run: |
6288
mvn spotless:check
6389
64-
- name: Run tests outside Docker
90+
- name: Run unit tests inside Docker
91+
if: ${{ inputs.runTestsInsideDocker }}
92+
working-directory: ${{ inputs.workingDirectory }}
93+
env:
94+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
95+
GITHUB_ACTOR: ${{ github.actor }}
96+
DOCKER_BUILDKIT: "1"
97+
run: |
98+
cat > /tmp/Dockerfile.test << DOCKERFILE
99+
# syntax=docker/dockerfile:1
100+
# check=error=true
101+
FROM ${TEST_BASE_IMAGE}
102+
WORKDIR /usr/app
103+
COPY . .
104+
COPY .mvn/settings.xml /root/.m2/settings.xml
105+
RUN --mount=type=secret,id=github_token \
106+
--mount=type=secret,id=github_actor \
107+
export GITHUB_TOKEN="\$(cat /run/secrets/github_token)" && \
108+
export GITHUB_ACTOR="\$(cat /run/secrets/github_actor)" && \
109+
./mvnw -B test
110+
DOCKERFILE
111+
docker build \
112+
--secret id=github_token,env=GITHUB_TOKEN \
113+
--secret id=github_actor,env=GITHUB_ACTOR \
114+
-f /tmp/Dockerfile.test \
115+
.
116+
117+
- name: Run unit tests outside Docker
118+
if: ${{ !inputs.runTestsInsideDocker }}
65119
working-directory: ${{ inputs.workingDirectory }}
66120
env:
67121
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -104,8 +158,8 @@ jobs:
104158
if: ${{ inputs.uploadJarArtifact }}
105159
uses: actions/upload-artifact@v4
106160
with:
107-
name: ${{ inputs.jarArtifactName }}
108-
path: ${{ inputs.jarArtifactPath }}
161+
name: 'app.jar'
162+
path: '/app/app.jar'
109163

110164
- name: Set Docker Image Name
111165
run: |
@@ -119,19 +173,6 @@ jobs:
119173
120174
echo "IMAGE_NAME=${IMAGE_NAME}" >> "$GITHUB_ENV"
121175
122-
- name: Build & run tests inside Docker
123-
if: ${{ inputs.runTestsInsideDocker }}
124-
uses: docker/build-push-action@v6
125-
with:
126-
context: ${{ inputs.workingDirectory }}
127-
load: true
128-
target: "${{ env.TEST_STAGE }}"
129-
tags: "${{ env.IMAGE_NAME }}:${{ env.TEST_STAGE }}"
130-
secrets:
131-
github_token=${{ secrets.GITHUB_TOKEN }}
132-
build-args:
133-
GITHUB_ACTOR=${{ github.actor }}
134-
135176
- name: Build Docker Image
136177
uses: docker/build-push-action@v6
137178
with:

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

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ on:
2121
required: false
2222
type: boolean
2323
default: false
24+
runTestsInsideDocker:
25+
required: false
26+
type: boolean
27+
default: true
28+
hasIntegrationTests:
29+
required: false
30+
type: boolean
31+
default: false
2432

2533
env:
2634
IMAGE_NAME_MIXED_CASE: "${{ github.repository }}"
@@ -36,25 +44,86 @@ jobs:
3644
clean: 'true'
3745
fetch-depth: 2
3846

47+
# Required since custom scripts from /scripts are being used
48+
- name: Resolve shared workflow ref
49+
run: |
50+
set -euo pipefail
51+
SHARED_WORKFLOW_REF=$(grep -roh \
52+
'transitdata-shared-workflows/.github/workflows/[^@]*@[^ "'\'']*' \
53+
"${GITHUB_WORKSPACE}/.github/workflows/" 2>/dev/null \
54+
| sed 's/.*@//' | head -1 || true)
55+
56+
if [[ -z "${SHARED_WORKFLOW_REF}" ]]; then
57+
echo "::warning::Could not detect shared workflow ref from caller workflows; falling back to main"
58+
SHARED_WORKFLOW_REF="main"
59+
fi
60+
61+
echo "Resolved shared workflow ref: ${SHARED_WORKFLOW_REF}"
62+
echo "SHARED_WORKFLOW_REF=${SHARED_WORKFLOW_REF}" >> "$GITHUB_ENV"
63+
64+
- name: Checkout shared workflow scripts
65+
uses: actions/checkout@v4
66+
with:
67+
repository: HSLdevcom/transitdata-shared-workflows
68+
ref: ${{ env.SHARED_WORKFLOW_REF }}
69+
path: .shared-workflows
70+
3971
- name: Setup JDK
4072
uses: actions/setup-java@v4
4173
with:
4274
distribution: 'temurin'
4375
java-version: '11'
4476
cache: 'gradle'
4577

78+
- name: Validate Java version consistency
79+
env:
80+
JAVA_TOOL_OPTIONS: ""
81+
run: python3 "${GITHUB_WORKSPACE}/.shared-workflows/scripts/validate_java_version_consistency.py"
82+
4683
- name: Check code format and lint
4784
run: ./gradlew spotlessCheck
4885
env:
4986
GITHUB_ACTOR: ${{ github.actor }}
5087
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5188

52-
- name: Run tests
89+
- name: Run unit tests inside Docker
90+
if: ${{ inputs.runTestsInsideDocker }}
5391
env:
54-
GITHUB_ACTOR: ${{ github.actor }}
5592
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
93+
GITHUB_ACTOR_ARG: ${{ github.actor }}
94+
DOCKER_BUILDKIT: "1"
5695
run: |
57-
./gradlew test jacocoTestReport --stacktrace
96+
cat > /tmp/Dockerfile.test << DOCKERFILE
97+
# syntax=docker/dockerfile:1
98+
# check=error=true
99+
FROM ${TEST_BASE_IMAGE}
100+
WORKDIR /usr/app
101+
ARG GITHUB_ACTOR=github-actions
102+
COPY . .
103+
RUN --mount=type=secret,id=github_token \
104+
export GITHUB_TOKEN="\$(cat /run/secrets/github_token)" && \
105+
export GITHUB_ACTOR="\$GITHUB_ACTOR" && \
106+
./gradlew test --stacktrace --no-daemon
107+
DOCKERFILE
108+
docker build \
109+
--secret id=github_token,env=GITHUB_TOKEN \
110+
--build-arg "GITHUB_ACTOR=${GITHUB_ACTOR_ARG}" \
111+
-f /tmp/Dockerfile.test \
112+
.
113+
114+
- name: Run unit tests
115+
if: ${{ inputs.hasIntegrationTests == false }}
116+
env:
117+
GITHUB_ACTOR: ${{ github.actor }}
118+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
119+
run: ./gradlew test jacocoTestReport --stacktrace
120+
121+
- name: Run unit tests and integration tests
122+
if: ${{ inputs.hasIntegrationTests }}
123+
env:
124+
GITHUB_ACTOR: ${{ github.actor }}
125+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
126+
run: ./gradlew test integrationTest jacocoTestReport --stacktrace
58127

59128
- name: Upload coverage reports to Codecov
60129
uses: codecov/codecov-action@v5

.github/workflows/ci.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: ci.yml
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
pull_request:
8+
push:
9+
branches:
10+
- main
11+
12+
jobs:
13+
test-scripts:
14+
name: Test Python scripts
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Setup Python
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: '3.x'
24+
25+
- name: Install pytest
26+
run: pip install pytest
27+
28+
- name: Run script tests
29+
run: pytest scripts/ -v

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.idea
2+
scripts/__pycache__
23
/AGENTS.md
34
/CLAUDE.md
45
/.claude/settings.local.json

0 commit comments

Comments
 (0)