Skip to content

Commit

Permalink
adding templates
Browse files Browse the repository at this point in the history
  • Loading branch information
vsc1cob committed Jan 20, 2025
1 parent b3e0309 commit e2ed1a3
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 120 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/build-and-artifact.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Build and Artifact

runs-on: self-hosted

steps:
# Checkout the repository
- name: Checkout Code
uses: actions/checkout@v3

# Build the project with Maven
- name: Build with Maven
run: mvn clean install

# Store artifacts with versioning
- name: Upload Artifacts with Versioning
uses: actions/upload-artifact@v3
with:
name: my-app-artifact-${{ github.sha }}
path: target/*.jar
120 changes: 0 additions & 120 deletions .github/workflows/build.yml

This file was deleted.

26 changes: 26 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Build, Deploy, and Analyze

on:
push:
branches:
- '**'
pull_request:
branches:
- master
workflow_dispatch:

jobs:
setup-java-maven:
uses: ./.github/workflows/setup-java-maven.yml

build-and-artifact:
uses: ./.github/workflows/build-and-artifact.yml
needs: setup-java-maven

springboot-run-stop:
uses: ./.github/workflows/springboot-run-stop.yml
needs: build-and-artifact

sonarcloud-analysis:
uses: ./.github/workflows/sonarcloud-analysis.yml
needs: build-and-artifact
32 changes: 32 additions & 0 deletions .github/workflows/setup-java-maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Setup Java and Maven

runs-on: ubuntu-latest

steps:
# Checkout the repository
- name: Checkout Code
uses: actions/checkout@v3

# Install Maven
- name: Install Maven
run: |
sudo apt update
sudo apt install maven -y
mvn -v
# Set up Java
- name: Set up Java
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: maven

# 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-
28 changes: 28 additions & 0 deletions .github/workflows/sonarcloud-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: SonarCloud Analysis

runs-on: self-hosted
needs: build-and-artifact # Ensure the build and artifact job runs before the 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
- 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 }}
50 changes: 50 additions & 0 deletions .github/workflows/springboot-run-stop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Spring Boot Run and Stop

runs-on: self-hosted

steps:
# Checkout the repository
- name: Checkout Code
uses: actions/checkout@v3

# Run Spring Boot App
- 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
echo "App should now be running."
# Validate that the application is running
- name: Validate App is Running
run: |
echo "Checking if the app is running..."
IP_ADDRESS=$(curl -s ifconfig.me)
PORT=8080
RESPONSE=$(curl --write-out "%{http_code}" --silent --output /dev/null http://$IP_ADDRESS:$PORT)
if [ "$RESPONSE" -eq 200 ]; then
echo "The app is running successfully at http://$IP_ADDRESS:$PORT!"
else
echo "The app failed to start. HTTP response code: $RESPONSE"
exit 1
fi
# Display the IP address and port number
- name: Display IP Address and Port
run: |
echo "The app is accessible at: http://$IP_ADDRESS:$PORT"
# Wait for 3 minutes
- name: Wait for 3 minutes
run: |
echo "App has been running for 3 minutes. Waiting..."
sleep 180
# Gracefully Stop Spring Boot App
- name: Gracefully Stop Spring Boot App
run: |
echo "Stopping the app gracefully..."
mvn spring-boot:stop

0 comments on commit e2ed1a3

Please sign in to comment.