Skip to content

Update Build.yml

Update Build.yml #76

Workflow file for this run

name: Build, Deploy, and Upload Artifacts
on:
push:
branches:
- '**'
pull_request:
branches:
- master
workflow_dispatch:
jobs:
build:
runs-on: test-runner
steps:
# Checkout the repository
- name: Checkout Code
uses: actions/checkout@v3
# Set up Java
- name: Set up Java
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
# Cache Maven dependencies
- name: Cache Maven dependencies
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
# Build the project with Maven
- name: Build with Maven
run: mvn clean install
# Run the Spring Boot application in the background
- name: Run Spring Boot App
run: mvn spring-boot:run &
# Wait for the Spring Boot app to fully start
- name: Wait for Spring Boot App to Start
run: |
echo "Waiting for the app to start..."
sleep 15 # Allow time for the Spring Boot app to fully initialize
echo "App should now be running."
# Validate that the application is running by sending a request to the app
- name: Validate App is Running
run: |
echo "Checking if the app is running..."
RESPONSE=$(curl --write-out "%{http_code}" --silent --output /dev/null http://localhost:8080)
if [ "$RESPONSE" -eq 200 ]; then
echo "The app is running successfully!"
else
echo "The app failed to start. HTTP response code: $RESPONSE"
exit 1
fi
# Wait for 5 minutes (300 seconds)
- name: Wait for 5 minutes
run: |
echo "App has been running for 5 minutes. Waiting..."
sleep 300 # Wait for 5 minutes
# Stop the Spring Boot app gracefully using spring-boot:stop
- name: Gracefully Stop Spring Boot App
run: |
echo "Stopping the app gracefully..."
mvn spring-boot:stop
sonarcloud-analysis:
runs-on: ubuntu-latest
needs: build # Ensure the build job runs before sonarcloud-analysis job
steps:
# Checkout the repository
- name: Checkout Code
uses: actions/checkout@v3
# Set up Java
- name: Set up Java
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
# SonarCloud Analysis (separate job)
- name: SonarCloud Analysis
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_ORG: your-organization # Replace with your actual SonarCloud organization
SONAR_HOST_URL: https://sonarcloud.io
run: |
mvn clean verify sonar:sonar \
-Dsonar.organization=${{ secrets.SONAR_ORG }} \
-Dsonar.host.url=${{ secrets.SONAR_HOST_URL }} \
-Dsonar.login=${{ secrets.SONAR_TOKEN }}