From a1b845fe31900fa542b79d97d602366269e48e5d Mon Sep 17 00:00:00 2001 From: lukaDjordjevic01 <96748944+lukaDjordjevic01@users.noreply.github.com> Date: Thu, 22 Jan 2026 20:20:25 +0100 Subject: [PATCH 1/6] Add initial github workflow. --- .github/workflows/ci.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..c37e1f6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,29 @@ +name: CI Pipeline + +on: + push: + branches: + - develop + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up JDK 25 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '25' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Build with Gradle + run: ./gradlew clean build + + - name: Display build success + run: echo "Build completed successfully!" \ No newline at end of file From 087c43fbbb5dc1fb88c6258ee7d3b15b3e2a28f5 Mon Sep 17 00:00:00 2001 From: lukaDjordjevic01 <96748944+lukaDjordjevic01@users.noreply.github.com> Date: Thu, 22 Jan 2026 20:52:30 +0100 Subject: [PATCH 2/6] Add image publishing. --- .github/workflows/ci.yml | 33 ++++++++++++++++++++++++++++++++- Dockerfile | 12 ++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 Dockerfile diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c37e1f6..6b38648 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,6 +5,9 @@ on: branches: - develop +env: + DOCKERHUB_USERNAME: threeamigoscoding + jobs: build: runs-on: ubuntu-latest @@ -26,4 +29,32 @@ jobs: run: ./gradlew clean build - name: Display build success - run: echo "Build completed successfully!" \ No newline at end of file + run: echo "Build completed successfully!" + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ env.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Generate version tag + id: version + run: | + SHORT_SHA=$(git rev-parse --short HEAD) + VERSION_TAG="develop-${SHORT_SHA}" + echo "tag=$VERSION_TAG" >> $GITHUB_OUTPUT + echo "Generated version tag: $VERSION_TAG" + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: | + ${{ env.DOCKERHUB_USERNAME }}/devoops-backend-poc:${{ steps.version.outputs.tag }} + ${{ env.DOCKERHUB_USERNAME }}/devoops-backend-poc:latest + cache-from: type=gha + cache-to: type=gha,mode=max \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e7440a4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM eclipse-temurin:25-jre-alpine + +WORKDIR /app + +COPY build/libs/*SNAPSHOT.jar app.jar + +RUN addgroup -S spring && adduser -S spring -G spring +USER spring:spring + +EXPOSE 8080 + +ENTRYPOINT ["java", "-jar", "app.jar"] \ No newline at end of file From 433167ad57389b543711acc2022e120885993b40 Mon Sep 17 00:00:00 2001 From: lukaDjordjevic01 <96748944+lukaDjordjevic01@users.noreply.github.com> Date: Thu, 22 Jan 2026 21:19:48 +0100 Subject: [PATCH 3/6] Add PR check. --- .github/workflows/pr-check.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/pr-check.yml diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml new file mode 100644 index 0000000..890a5d8 --- /dev/null +++ b/.github/workflows/pr-check.yml @@ -0,0 +1,30 @@ +name: PR Check + +on: + pull_request: + branches: + - develop + - master + +jobs: + build-and-test: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up JDK 25 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '25' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Build with Gradle + run: ./gradlew clean build + + - name: Run unit tests + run: ./gradlew test From ea7e5729fd333b7fd49c822dd0e7e30336cbffaa Mon Sep 17 00:00:00 2001 From: lukaDjordjevic01 <96748944+lukaDjordjevic01@users.noreply.github.com> Date: Thu, 22 Jan 2026 21:22:22 +0100 Subject: [PATCH 4/6] Add failing test. --- .../com/devoops/backend_poc/BackendPocApplicationTests.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/test/java/com/devoops/backend_poc/BackendPocApplicationTests.java b/src/test/java/com/devoops/backend_poc/BackendPocApplicationTests.java index bae1e6a..975b87b 100644 --- a/src/test/java/com/devoops/backend_poc/BackendPocApplicationTests.java +++ b/src/test/java/com/devoops/backend_poc/BackendPocApplicationTests.java @@ -10,4 +10,9 @@ class BackendPocApplicationTests { void contextLoads() { } + @Test + void failingTest() { + throw new RuntimeException("This test is failing"); + } + } From f0a557b7e362b0a5e20870d451991ac30c4ee728 Mon Sep 17 00:00:00 2001 From: lukaDjordjevic01 <96748944+lukaDjordjevic01@users.noreply.github.com> Date: Thu, 22 Jan 2026 21:32:22 +0100 Subject: [PATCH 5/6] Fix failing test. --- .../com/devoops/backend_poc/BackendPocApplicationTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/devoops/backend_poc/BackendPocApplicationTests.java b/src/test/java/com/devoops/backend_poc/BackendPocApplicationTests.java index 975b87b..9e31ffd 100644 --- a/src/test/java/com/devoops/backend_poc/BackendPocApplicationTests.java +++ b/src/test/java/com/devoops/backend_poc/BackendPocApplicationTests.java @@ -11,8 +11,8 @@ void contextLoads() { } @Test - void failingTest() { - throw new RuntimeException("This test is failing"); + void notFailingTest() { + System.out.println( "Not failing test"); } } From 397648f5e281559c4f4722e3c93f1eec9a669cdc Mon Sep 17 00:00:00 2001 From: lukaDjordjevic01 <96748944+lukaDjordjevic01@users.noreply.github.com> Date: Mon, 26 Jan 2026 20:42:01 +0100 Subject: [PATCH 6/6] Add semantic versioning. --- .github/workflows/ci.yml | 40 ++++++++++++++++++++++++++++++---- .github/workflows/pr-check.yml | 7 ++---- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6b38648..147f19b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,6 +4,10 @@ on: push: branches: - develop + - main + tags: + - 'v*' + env: DOCKERHUB_USERNAME: threeamigoscoding @@ -28,8 +32,29 @@ jobs: - name: Build with Gradle run: ./gradlew clean build - - name: Display build success - run: echo "Build completed successfully!" + - name: Run tests + run: ./gradlew test + + - name: Upload build artifact + uses: actions/upload-artifact@v4 + with: + name: build-artifact + path: build/libs/*.jar + retention-days: 1 + + publish: + needs: build + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Download build artifact + uses: actions/download-artifact@v4 + with: + name: build-artifact + path: build/libs - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -43,8 +68,15 @@ jobs: - name: Generate version tag id: version run: | - SHORT_SHA=$(git rev-parse --short HEAD) - VERSION_TAG="develop-${SHORT_SHA}" + if [[ $GITHUB_REF == refs/tags/* ]]; then + VERSION_TAG=${GITHUB_REF#refs/tags/v} + elif [[ $GITHUB_REF == refs/heads/main ]]; then + SHORT_SHA=$(git rev-parse --short HEAD) + VERSION_TAG="main-${SHORT_SHA}" + else + SHORT_SHA=$(git rev-parse --short HEAD) + VERSION_TAG="develop-${SHORT_SHA}" + fi echo "tag=$VERSION_TAG" >> $GITHUB_OUTPUT echo "Generated version tag: $VERSION_TAG" diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 890a5d8..e6f3777 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -4,7 +4,7 @@ on: pull_request: branches: - develop - - master + - main jobs: build-and-test: @@ -24,7 +24,4 @@ jobs: uses: gradle/actions/setup-gradle@v4 - name: Build with Gradle - run: ./gradlew clean build - - - name: Run unit tests - run: ./gradlew test + run: ./gradlew clean build \ No newline at end of file