From 071951b6135ff8ce37274d65fc026c1327eab55a Mon Sep 17 00:00:00 2001 From: vsc1cob Date: Mon, 20 Jan 2025 14:22:32 +0530 Subject: [PATCH] adding templates --- .github/workflows/build-and-artifact.yml | 3 - .github/workflows/main.yml | 6 +- .github/workflows/springboot-run-stop.yml | 104 ++++++++++------------ 3 files changed, 51 insertions(+), 62 deletions(-) diff --git a/.github/workflows/build-and-artifact.yml b/.github/workflows/build-and-artifact.yml index adb810f..4fcfdb8 100644 --- a/.github/workflows/build-and-artifact.yml +++ b/.github/workflows/build-and-artifact.yml @@ -8,9 +8,6 @@ jobs: runs-on: self-hosted steps: - - name: Checkout Code - uses: actions/checkout@v3 - # Build the project with Maven - name: Build with Maven run: mvn clean install diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0c3bbad..dfb463c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,9 +18,9 @@ jobs: build-and-artifact: uses: ./.github/workflows/build-and-artifact.yml # Reference to the build workflow - # # Call the Spring Boot run and stop workflow - # springboot-run-stop: - # uses: ./.github/workflows/springboot-run-stop.yml # Reference to the Spring Boot workflow + # Call the Spring Boot run and stop workflow + springboot-run-stop: + uses: ./.github/workflows/springboot-run-stop.yml # Reference to the Spring Boot workflow # # Call the SonarCloud analysis workflow # sonarcloud-analysis: diff --git a/.github/workflows/springboot-run-stop.yml b/.github/workflows/springboot-run-stop.yml index 5a1aeba..170dad2 100644 --- a/.github/workflows/springboot-run-stop.yml +++ b/.github/workflows/springboot-run-stop.yml @@ -1,59 +1,51 @@ name: Spring Boot Run and Stop on: - push: - branches: - - '**' # Trigger for all branches - pull_request: - branches: - - master # Trigger for pull requests targeting the master branch - workflow_dispatch: # Manual trigger via GitHub UI - -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 + workflow_call: # This workflow can be called from other workflows + +jobs: + springboot-run-stop: + runs-on: self-hosted + + steps: + # 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) # Fetch public IP address + 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 (180 seconds) + - 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