From 3b132b32f04d9ae5776a10e1248e08dd7c376652 Mon Sep 17 00:00:00 2001 From: Ajay Negi Date: Sun, 1 Sep 2024 23:01:56 +0530 Subject: [PATCH] Spring Boot CI Pipeline --- .github/workflows/java-ci.yaml | 53 ---------------------------- .github/workflows/maven-publish.yml | 8 ++--- .github/workflows/spring-boot-ci.yml | 38 ++++++++++++++++++++ 3 files changed, 42 insertions(+), 57 deletions(-) delete mode 100644 .github/workflows/java-ci.yaml create mode 100644 .github/workflows/spring-boot-ci.yml diff --git a/.github/workflows/java-ci.yaml b/.github/workflows/java-ci.yaml deleted file mode 100644 index 52bbf25..0000000 --- a/.github/workflows/java-ci.yaml +++ /dev/null @@ -1,53 +0,0 @@ -name: Java CI - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Print environment variables - run: | - echo "DATABASE_URL=${{ secrets.DATABASE_URL }}" - echo "DATABASE_USERNAME=${{ secrets.DATABASE_USERNAME }}" - echo "DATABASE_PASSWORD=${{ secrets.DATABASE_PASSWORD }}" - echo "DATABASE_DRIVER_CLASS_NAME=${{ secrets.DATABASE_DRIVER_CLASS_NAME }}" - echo "ENV=${{ vars.ENV }}" - - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'temurin' - -# - name: Cache Maven packages -# uses: actions/cache@v3 -# with: -# path: ~/.m2 -# key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} -# restore-keys: | -# ${{ runner.os }}-maven- - -# - name: Build with Maven -# env: -# DATABASE_URL: ${{ secrets.DATABASE_URL }} -# DATABASE_USERNAME: ${{ secrets.DATABASE_USERNAME }} -# DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }} -# DATABASE_DRIVER_CLASS_NAME: ${{ secrets.DATABASE_DRIVER_CLASS_NAME }} -# run: mvn clean install -X - - - name: Run tests - run: mvn test - - - name: Verify application runs - run: mvn spring-boot:run -Dspring-boot.run.arguments=--server.port=8080 & - shell: bash - diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml index 855dfb8..6493613 100644 --- a/.github/workflows/maven-publish.yml +++ b/.github/workflows/maven-publish.yml @@ -1,8 +1,8 @@ -## This workflow will build a package using Maven and then publish it to GitHub packages when a release is created -## For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path -# +# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created +# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path + #name: Maven Package -# + #on: # release: # types: [created] diff --git a/.github/workflows/spring-boot-ci.yml b/.github/workflows/spring-boot-ci.yml new file mode 100644 index 0000000..2513af7 --- /dev/null +++ b/.github/workflows/spring-boot-ci.yml @@ -0,0 +1,38 @@ +name: Spring Boot CI Pipeline + +on: + push: + branches: + - 'main' + pull_request: + branches: + - '**' # Run on all PRs to any branch + +jobs: + build-and-test: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' + + - name: Install dependencies + run: mvn clean install + + - name: Run Spring Boot Application + run: mvn spring-boot:run + env: + ENV: production + DATABASE_URL: ${{ secrets.DATABASE_URL }} + DATABASE_USERNAME: ${{ secrets.DATABASE_USERNAME }} + DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }} + DATABASE_DRIVER_CLASS_NAME: ${{ secrets.DATABASE_DRIVER_CLASS_NAME }} + + - name: Run Tests + run: mvn test