Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read
packages: write

env:
REGISTRY: ghcr.io

jobs:
build-and-push:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: "17"
cache: gradle

- name: Copy application.yml into runner
run: |
mkdir -p src/main/resources
echo "${{ secrets.APPLICATION_YML }}" > src/main/resources/application.yml

- name: Build + Test(Gradle)
if: ${{ hashFiles('**/build.gradle*') != '' }}
run: |
chmod +x ./gradlew
./gradlew clean test
./gradlew bootJar
JAR=$(ls build/libs/*.jar | head -n 1)
cp "$JAR" app.jar

Comment on lines +42 to +44
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | πŸ”΄ Critical

Copying the wrong JAR breaks the container runtime.

ls build/libs/*.jar | head -n 1 grabs the first alphabetic match, which is the *-plain.jar Gradle produces alongside the runnable bootJar. That thin artifact lacks dependencies, so java -jar app.jar dies at runtime. Filter out the -plain variant (and fail fast if no runnable jar exists) before copying.

Apply this diff:

-          JAR=$(ls build/libs/*.jar | head -n 1)
-          cp "$JAR" app.jar
+          JAR=$(ls build/libs/*.jar | grep -v '\-plain\.jar$' | head -n 1)
+          if [ -z "$JAR" ]; then
+            echo "No runnable Spring Boot jar found in build/libs" >&2
+            exit 1
+          fi
+          cp "$JAR" app.jar
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
JAR=$(ls build/libs/*.jar | head -n 1)
cp "$JAR" app.jar
JAR=$(ls build/libs/*.jar | grep -v '\-plain\.jar$' | head -n 1)
if [ -z "$JAR" ]; then
echo "No runnable Spring Boot jar found in build/libs" >&2
exit 1
fi
cp "$JAR" app.jar
πŸ€– Prompt for AI Agents
In .github/workflows/gradle.yml around lines 42 to 44, the workflow currently
picks the first jar alphabetically which can be the non-runnable *-plain.jar;
change the selection to find the runnable fat jar by filtering out any filenames
containing "-plain.jar" (or prefer patterns like "*-all.jar" or the bootJar
output), and if no runnable jar is found fail the step immediately with a clear
error message so the container build doesn't proceed with an invalid artifact.
Ensure the copy step uses the filtered jar path.

- name: Compute image name (change to lowercase)
id: img
run: echo "name=${{ env.REGISTRY }}/${GITHUB_REPOSITORY,,}" >> $GITHUB_OUTPUT

- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}

Comment on lines +49 to +55
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Skip GHCR login when secrets are unavailable on forked PRs.

pull_request runs from forks (and bot PRs) execute without repository secrets, so ${{ secrets.GHCR_TOKEN }} resolves empty and the login step fails before any build/test feedback is produced.(github.blog) That breaks CI for outside contributors and automation like Dependabot.(docs.github.com) Gate the login (and any dependent steps) so it only runs when the workflow actually has access to repo secrets.

       - name: Log in to GHCR
-        uses: docker/login-action@v3
+        if: ${{ github.event_name != 'pull_request' && github.secret_source == 'Actions' }}
+        uses: docker/login-action@v3
         with:
           registry: ${{ env.REGISTRY }}
           username: ${{ github.actor }}
           password: ${{ secrets.GHCR_TOKEN }}
πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Log in to GHCR
if: ${{ github.event_name != 'pull_request' && github.secret_source == 'Actions' }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}
πŸ€– Prompt for AI Agents
.github/workflows/gradle.yml lines 49-55: the GHCR login step runs even when
secrets are not available (forked PRs), causing failures; update the workflow to
skip the login (and any steps that depend on it) when GHCR_TOKEN is not present
by adding an if conditional that checks the secret's presence (for example using
an expression like checking secrets.GHCR_TOKEN != ''), and propagate the same
conditional to downstream steps that require the login so CI for forked/bot PRs
proceeds without attempting GHCR authentication.

- name: Extract Docker metadata (tags, labels)
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ steps.img.outputs.name }}
tags: |
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
type=ref,event=tag
type=sha

- name: Set up Docker Build
uses: docker/setup-buildx-action@v3

- name: Debug paths
run: |
pwd
ls -la
find . -maxdepth 3 -iname 'Dockerfile' -print


- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM eclipse-temurin:17-jre-alpine
WORKDIR /app
COPY app.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]