From c76c097cedc2e7c0f52f82fb44c0ed9b0343c756 Mon Sep 17 00:00:00 2001 From: Lassalle Cedric Date: Fri, 4 Oct 2024 20:37:48 +0200 Subject: [PATCH 1/5] ci: add workflows actions and ci profile --- .github/workflows/code.yaml | 43 +++++++++++++++++++++++++++ src/main/resources/application-ci.yml | 9 ++++++ 2 files changed, 52 insertions(+) create mode 100644 .github/workflows/code.yaml create mode 100644 src/main/resources/application-ci.yml diff --git a/.github/workflows/code.yaml b/.github/workflows/code.yaml new file mode 100644 index 0000000..912e04a --- /dev/null +++ b/.github/workflows/code.yaml @@ -0,0 +1,43 @@ +name: Java CI with Maven + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'adopt' + java-version: '17' + + - name: Set up Docker Compose + run: sudo apt-get install docker-compose + + - name: Start Docker Compose services + run: docker-compose up -d + + - name: Wait for services to be ready + run: | + echo "Waiting for services to be ready..." + while ! nc -z localhost 5432; do # Adapt this command depending on your DB or service port + sleep 2 + done + + - name: Build with Maven + run: mvn -B package --file pom.xml + + - name: Run Tests + run: mvn test -Dspring.profiles.active=local diff --git a/src/main/resources/application-ci.yml b/src/main/resources/application-ci.yml new file mode 100644 index 0000000..d463edd --- /dev/null +++ b/src/main/resources/application-ci.yml @@ -0,0 +1,9 @@ +# Jwt +JWT_SECRET: "SECRET JWT FOR CI DO NOT USE THIS IN PRODUCTION" +JWT_EXPIRATION_TIME: 1000 + +# Postgres +POSTRGES_DB: ideasmanager +POSTGRES_USER: ideasmanager +POSTGRES_PWD: ideasmanager +POSTGRES_HOST: ideasmanager From d309b2fe7a671f0b3271ab2b7501a24a133299c0 Mon Sep 17 00:00:00 2001 From: Lassalle Cedric Date: Fri, 4 Oct 2024 20:44:08 +0200 Subject: [PATCH 2/5] fix(ci): change postgres host config --- src/main/resources/application-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application-ci.yml b/src/main/resources/application-ci.yml index d463edd..921a8f8 100644 --- a/src/main/resources/application-ci.yml +++ b/src/main/resources/application-ci.yml @@ -6,4 +6,4 @@ JWT_EXPIRATION_TIME: 1000 POSTRGES_DB: ideasmanager POSTGRES_USER: ideasmanager POSTGRES_PWD: ideasmanager -POSTGRES_HOST: ideasmanager +POSTGRES_HOST: localhost From f3e83188ebd181a2ce07e3c4d1128f3584dc361e Mon Sep 17 00:00:00 2001 From: Lassalle Cedric Date: Fri, 4 Oct 2024 21:25:59 +0200 Subject: [PATCH 3/5] fix(ci): change command build --- .github/workflows/code.yaml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/code.yaml b/.github/workflows/code.yaml index 912e04a..af2e806 100644 --- a/.github/workflows/code.yaml +++ b/.github/workflows/code.yaml @@ -36,8 +36,5 @@ jobs: sleep 2 done - - name: Build with Maven - run: mvn -B package --file pom.xml - - - name: Run Tests - run: mvn test -Dspring.profiles.active=local + - name: Build with Maven and run test + run: mvn -B package --file pom.xml -Dspring.profiles.active=ci From 3e01051e5b10f27a4ab02c01648d3a2583b7ecec Mon Sep 17 00:00:00 2001 From: Lassalle Cedric Date: Fri, 4 Oct 2024 21:28:10 +0200 Subject: [PATCH 4/5] fix(config): POSTGRES_DB variable --- .github/workflows/code.yaml | 7 +++++-- src/main/resources/application-ci.yml | 2 +- src/main/resources/application-local-template.yml | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/code.yaml b/.github/workflows/code.yaml index af2e806..21045df 100644 --- a/.github/workflows/code.yaml +++ b/.github/workflows/code.yaml @@ -36,5 +36,8 @@ jobs: sleep 2 done - - name: Build with Maven and run test - run: mvn -B package --file pom.xml -Dspring.profiles.active=ci + - name: Build with Maven + run: mvn -B package --file pom.xml -DskipTests + + - name: Run Tests + run: mvn test -Dspring.profiles.active=local diff --git a/src/main/resources/application-ci.yml b/src/main/resources/application-ci.yml index 921a8f8..8f7d8dd 100644 --- a/src/main/resources/application-ci.yml +++ b/src/main/resources/application-ci.yml @@ -3,7 +3,7 @@ JWT_SECRET: "SECRET JWT FOR CI DO NOT USE THIS IN PRODUCTION" JWT_EXPIRATION_TIME: 1000 # Postgres -POSTRGES_DB: ideasmanager +POSTGRES_DB: ideasmanager POSTGRES_USER: ideasmanager POSTGRES_PWD: ideasmanager POSTGRES_HOST: localhost diff --git a/src/main/resources/application-local-template.yml b/src/main/resources/application-local-template.yml index df011d0..df84236 100644 --- a/src/main/resources/application-local-template.yml +++ b/src/main/resources/application-local-template.yml @@ -6,7 +6,7 @@ JWT_SECRET: SETME JWT_EXPIRATION_TIME: 300000 # Postgres -POSTRGES_DB: SETME +POSTGRES_DB: SETME POSTGRES_USER: SETME POSTGRES_PWD: SETME POSTGRES_HOST: SETME From caa917c858a5cfd49675accff21d2c5c0d12e913 Mon Sep 17 00:00:00 2001 From: Lassalle Cedric Date: Fri, 4 Oct 2024 21:31:00 +0200 Subject: [PATCH 5/5] fix(ci): change profile in test --- .github/workflows/code.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code.yaml b/.github/workflows/code.yaml index 21045df..9e4f7f7 100644 --- a/.github/workflows/code.yaml +++ b/.github/workflows/code.yaml @@ -40,4 +40,4 @@ jobs: run: mvn -B package --file pom.xml -DskipTests - name: Run Tests - run: mvn test -Dspring.profiles.active=local + run: mvn test -Dspring.profiles.active=ci