From 8b25eecd096d4e97e5707add110b666877e7a815 Mon Sep 17 00:00:00 2001 From: Tatjana Date: Thu, 2 Apr 2026 20:02:16 +0200 Subject: [PATCH 1/6] Add ci.yml with demo content as a first test --- .github/workflows/ci.yml | 18 ++++++++++++++++++ 1 file changed, 18 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 00000000..b00f8e94 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,18 @@ +name: GitHub Actions Demo +run-name: ${{ github.actor }} is testing out GitHub Actions πŸš€ +on: [push] +jobs: + Explore-GitHub-Actions: + runs-on: ubuntu-latest + steps: + - run: echo "πŸŽ‰ The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "πŸ”Ž The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + - name: Check out repository code + uses: actions/checkout@v5 + - run: echo "πŸ’‘ The ${{ github.repository }} repository has been cloned to the runner." + - run: echo "πŸ–₯️ The workflow is now ready to test your code on the runner." + - name: List files in the repository + run: | + ls ${{ github.workspace }} + - run: echo "🍏 This job's status is ${{ job.status }}." From 7aa86d57792d237a46e3d4560e69c1ae200e1be3 Mon Sep 17 00:00:00 2001 From: Tatjana Date: Thu, 2 Apr 2026 20:55:26 +0200 Subject: [PATCH 2/6] Changes ci.yml with real flow --- .github/workflows/ci.yml | 46 ++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b00f8e94..0c929e6c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,18 +1,36 @@ -name: GitHub Actions Demo -run-name: ${{ github.actor }} is testing out GitHub Actions πŸš€ -on: [push] +name: CI Pipeline + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + jobs: - Explore-GitHub-Actions: + build-and-test: runs-on: ubuntu-latest + steps: - - run: echo "πŸŽ‰ The job was automatically triggered by a ${{ github.event_name }} event." - - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" - - run: echo "πŸ”Ž The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." - - name: Check out repository code + # 1. HΓ€mta koden + - name: Checkout code uses: actions/checkout@v5 - - run: echo "πŸ’‘ The ${{ github.repository }} repository has been cloned to the runner." - - run: echo "πŸ–₯️ The workflow is now ready to test your code on the runner." - - name: List files in the repository - run: | - ls ${{ github.workspace }} - - run: echo "🍏 This job's status is ${{ job.status }}." + + # 2. Installera Java + - name: Set up JDK + uses: actions/setup-java@v5 + with: + distribution: 'temurin' + java-version: '25' + + # 3. Cache (snabbar upp builds) + - name: Cache Maven dependencies + uses: actions/cache@v5 + with: + path: ~/.m2 + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven + + # 4. Build + Test + - name: Build and run tests + run: mvn clean verify \ No newline at end of file From 7ecba236542c5a928469e18a4e12ed9d24ed4075 Mon Sep 17 00:00:00 2001 From: Tatjana Date: Fri, 3 Apr 2026 18:00:13 +0200 Subject: [PATCH 3/6] Add secrets as env variables in ci.yml file --- .github/workflows/ci.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0c929e6c..073885da 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,4 +33,11 @@ jobs: # 4. Build + Test - name: Build and run tests - run: mvn clean verify \ No newline at end of file + run: mvn clean verify + env: + SPRING_DATASOURCE_URL: ${{ secrets.DB_URL }} + SPRING_DATASOURCE_USERNAME: ${{ secrets.DB_USER }} + SPRING_DATASOURCE_PASSWORD: ${{ secrets.DB_PASSWORD }} + + MINIO_ACCESS_KEY: ${{ secrets.MINIO_ACCESS_KEY }} + MINIO_SECRET_KEY: ${{ secrets.MINIO_SECRET_KEY }} \ No newline at end of file From 13d775d599e2bc5da9bcde277919027319240787 Mon Sep 17 00:00:00 2001 From: Tatjana Date: Sat, 4 Apr 2026 18:09:57 +0200 Subject: [PATCH 4/6] Finished initial CI-workflow and add a simple test to check the CI workflow works --- .github/workflows/ci.yml | 10 +++++++++- .../example/vet1177/ci_dummy_test/CiDummyTest.java | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/test/java/org/example/vet1177/ci_dummy_test/CiDummyTest.java diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 073885da..4b6236da 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,4 +40,12 @@ jobs: SPRING_DATASOURCE_PASSWORD: ${{ secrets.DB_PASSWORD }} MINIO_ACCESS_KEY: ${{ secrets.MINIO_ACCESS_KEY }} - MINIO_SECRET_KEY: ${{ secrets.MINIO_SECRET_KEY }} \ No newline at end of file + MINIO_SECRET_KEY: ${{ secrets.MINIO_SECRET_KEY }} + + # 5. Upload artifact (ONLY on main) + - name: Upload JAR artifact + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + uses: actions/upload-artifact@v7 + with: + name: app-${{ github.ref_name }}-${{ github.run_number }}-${{ github.sha }} + path: target/*.jar diff --git a/src/test/java/org/example/vet1177/ci_dummy_test/CiDummyTest.java b/src/test/java/org/example/vet1177/ci_dummy_test/CiDummyTest.java new file mode 100644 index 00000000..760d67c2 --- /dev/null +++ b/src/test/java/org/example/vet1177/ci_dummy_test/CiDummyTest.java @@ -0,0 +1,14 @@ +package org.example.vet1177.ci_dummy_test; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class CiDummyTest { + + @Test + void shouldPass() { + assertTrue(true); + } + +} From 4050f291c3a40116a21923178724eab2ee5e50f4 Mon Sep 17 00:00:00 2001 From: Tatjana Date: Sat, 4 Apr 2026 18:13:55 +0200 Subject: [PATCH 5/6] Change simple test to fail to make sure workflow fails with a failing test --- .../java/org/example/vet1177/ci_dummy_test/CiDummyTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/example/vet1177/ci_dummy_test/CiDummyTest.java b/src/test/java/org/example/vet1177/ci_dummy_test/CiDummyTest.java index 760d67c2..57eda8f9 100644 --- a/src/test/java/org/example/vet1177/ci_dummy_test/CiDummyTest.java +++ b/src/test/java/org/example/vet1177/ci_dummy_test/CiDummyTest.java @@ -8,7 +8,7 @@ public class CiDummyTest { @Test void shouldPass() { - assertTrue(true); + assertTrue(false); } } From f7278ebd6680767f30a6813264f0ae468dd6be66 Mon Sep 17 00:00:00 2001 From: Tatjana Date: Sat, 4 Apr 2026 18:16:30 +0200 Subject: [PATCH 6/6] Revert simple test so its succeeds --- .../java/org/example/vet1177/ci_dummy_test/CiDummyTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/example/vet1177/ci_dummy_test/CiDummyTest.java b/src/test/java/org/example/vet1177/ci_dummy_test/CiDummyTest.java index 57eda8f9..760d67c2 100644 --- a/src/test/java/org/example/vet1177/ci_dummy_test/CiDummyTest.java +++ b/src/test/java/org/example/vet1177/ci_dummy_test/CiDummyTest.java @@ -8,7 +8,7 @@ public class CiDummyTest { @Test void shouldPass() { - assertTrue(false); + assertTrue(true); } }