Skip to content

Workflow file for this run

name: Build, Deploy, and Run
on:
push:
branches:
- '**' # Trigger on all branches
pull_request:
branches:
- master # Trigger on pull requests to the master branch
workflow_dispatch: # Allow manual trigger
jobs:
build-and-run:
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write # Required for CodeQL to upload the results
steps:
# Step 1: Checkout code
- name: Checkout Code
uses: actions/checkout@v4
# Step 2: Set up Java 11 (Temurin)
- name: Set up Java 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin' # Use Temurin JDK distribution
# Step 3: Set up Maven
- name: Set up Maven
uses: actions/setup-maven@v2
with:
maven-version: '3.8.4' # Specify the Maven version if needed
# Step 4: Initialize CodeQL for Java
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: 'java' # Specify Java language for analysis
# Step 5: Perform CodeQL Analysis
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
upload: true # Upload results to GitHub security events
# Step 6: Build the project with Maven
- name: Build with Maven
run: mvn clean package
# Step 7: Upload the built JAR as an artifact
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: built-jar
path: target/simple-parcel-service-app-1.0-SNAPSHOT.jar
# Step 8: Run the Spring Boot application
- name: Run Application
run: |
nohup mvn spring-boot:run & # Run in the background
sleep 15 # Allow time for the app to fully start
# Step 9: Validate App is Running
- name: Validate App is Running
run: |
echo "Waiting for the app to start..."
sleep 15 # Allow some time for the Spring Boot app to fully start
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
# Step 10: Wait for 5 minutes
- name: Wait for 5 minutes
run: |
echo "App has been running for 5 minutes. Waiting..."
sleep 300 # Wait for 5 minutes (300 seconds)
# Step 11: Gracefully Stop Spring Boot App
- name: Gracefully Stop Spring Boot App
run: |
echo "Stopping the app gracefully..."
mvn spring-boot:stop