forked from jboulon/influent
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from drzo/drzo-patch-11
Create agro-maven.yml
- Loading branch information
Showing
1 changed file
with
373 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,373 @@ | ||
name: Aggressive Maven CI/CD Pipeline | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
schedule: | ||
- cron: '0 3 * * *' # Runs daily at 3 AM UTC | ||
workflow_dispatch: # Allows manual trigger | ||
|
||
jobs: | ||
# Job 1: Build the Project | ||
build: | ||
runs-on: ubuntu-latest | ||
name: Build Project | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set Up JDK 11 | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'temurin' | ||
java-version: '11' | ||
cache: maven | ||
|
||
- name: Display Java Version | ||
run: java -version | ||
|
||
- name: Maven Clean and Compile | ||
run: mvn clean compile -fn | ||
|
||
- name: Upload Build Logs | ||
if: always() | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: build-logs | ||
path: target/build.log | ||
|
||
- name: Notify Build Issues | ||
if: failure() | ||
uses: dawidd6/action-send-mail@v3 | ||
with: | ||
server_address: smtp.example.com | ||
server_port: 587 | ||
username: ${{ secrets.SMTP_USERNAME }} | ||
password: ${{ secrets.SMTP_PASSWORD }} | ||
subject: 'Build Job Encountered Issues' | ||
body: | | ||
The build job has completed with issues. Please check the workflow logs for details. | ||
to: [email protected] | ||
from: [email protected] | ||
|
||
# Job 2: Manage Maven Dependencies | ||
manage-dependencies: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
name: Manage Maven Dependencies | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set Up JDK 11 | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'temurin' | ||
java-version: '11' | ||
cache: maven | ||
|
||
- name: Generate Dependency Tree | ||
run: mvn dependency:tree -fn -DoutputType=dot -DoutputFile=dependency-tree.dot | ||
|
||
- name: Upload Dependency Tree | ||
if: always() | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: dependency-tree | ||
path: dependency-tree.dot | ||
|
||
- name: Analyze Dependencies | ||
run: | | ||
mvn dependency:analyze -fn > dependency-analysis.txt || echo "Dependency analysis failed, but continuing" | ||
- name: Upload Dependency Analysis Report | ||
if: always() | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: dependency-analysis | ||
path: dependency-analysis.txt | ||
|
||
- name: Attempt to Auto-Fix Missing Dependencies | ||
if: failure() | ||
run: | | ||
# Example: Automatically add missing dependencies (Requires custom scripting) | ||
# This is a placeholder for actual implementation | ||
echo "Attempting to auto-fix missing dependencies..." | ||
# Implement logic to parse dependency-analysis.txt and update pom.xml | ||
# For example, using sed, awk, or a custom script to insert dependencies | ||
# WARNING: Automated POM modifications can introduce instability | ||
- name: Commit and Push Auto-Fixes | ||
if: failure() | ||
uses: stefanzweifel/git-auto-commit-action@v4 | ||
with: | ||
commit_message: "Auto-fix missing dependencies via GitHub Actions" | ||
branch: main | ||
file_pattern: pom.xml | ||
|
||
- name: Notify Dependency Issues | ||
if: failure() | ||
uses: dawidd6/action-send-mail@v3 | ||
with: | ||
server_address: smtp.example.com | ||
server_port: 587 | ||
username: ${{ secrets.SMTP_USERNAME }} | ||
password: ${{ secrets.SMTP_PASSWORD }} | ||
subject: 'Maven Dependency Issues Detected' | ||
body: | | ||
The Maven dependency management has encountered issues. Auto-fix attempts have been made. | ||
Please review the dependency-analysis.txt and the updated pom.xml for details. | ||
to: [email protected] | ||
from: [email protected] | ||
|
||
- name: Create GitHub Issue for Dependency Issues | ||
if: failure() | ||
uses: peter-evans/create-issue-from-file@v3 | ||
with: | ||
title: 'Maven Dependency Issues Detected' | ||
content-file: dependency-analysis.txt | ||
labels: dependency, issue | ||
|
||
# Job 3: Run Unit Tests | ||
unit-tests: | ||
needs: manage-dependencies | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
java-version: [8, 11, 17] | ||
name: Run Unit Tests on Java ${{ matrix.java-version }} | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set Up JDK ${{ matrix.java-version }} | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'temurin' | ||
java-version: ${{ matrix.java-version }} | ||
cache: maven | ||
|
||
- name: Maven Test with Retries | ||
run: | | ||
for i in {1..3}; do | ||
mvn test -fn && break || sleep 15 | ||
done | ||
- name: Upload Unit Test Results | ||
if: always() | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: unit-test-results-java-${{ matrix.java-version }} | ||
path: target/surefire-reports/ | ||
|
||
- name: Notify Unit Test Issues | ||
if: failure() | ||
uses: dawidd6/action-send-mail@v3 | ||
with: | ||
server_address: smtp.example.com | ||
server_port: 587 | ||
username: ${{ secrets.SMTP_USERNAME }} | ||
password: ${{ secrets.SMTP_PASSWORD }} | ||
subject: 'Unit Tests Encountered Issues' | ||
body: | | ||
The unit tests on Java ${{ matrix.java-version }} have completed with issues. Please check the workflow logs for details. | ||
to: [email protected] | ||
from: [email protected] | ||
|
||
# Job 4: Run Integration Tests | ||
integration-tests: | ||
needs: manage-dependencies | ||
runs-on: ubuntu-latest | ||
name: Run Integration Tests | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set Up JDK 11 | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'temurin' | ||
java-version: '11' | ||
cache: maven | ||
|
||
- name: Maven Integration Test with Retries | ||
run: | | ||
for i in {1..3}; do | ||
mvn verify -P integration-tests -fn && break || sleep 15 | ||
done | ||
- name: Upload Integration Test Results | ||
if: always() | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: integration-test-results | ||
path: target/failsafe-reports/ | ||
|
||
- name: Notify Integration Test Issues | ||
if: failure() | ||
uses: dawidd6/action-send-mail@v3 | ||
with: | ||
server_address: smtp.example.com | ||
server_port: 587 | ||
username: ${{ secrets.SMTP_USERNAME }} | ||
password: ${{ secrets.SMTP_PASSWORD }} | ||
subject: 'Integration Tests Encountered Issues' | ||
body: | | ||
The integration tests have completed with issues. Please check the workflow logs for details. | ||
to: [email protected] | ||
from: [email protected] | ||
|
||
# Job 5: Code Analysis | ||
code-analysis: | ||
needs: manage-dependencies | ||
runs-on: ubuntu-latest | ||
name: Static Code Analysis | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set Up JDK 11 | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'temurin' | ||
java-version: '11' | ||
|
||
- name: Maven Code Analysis with SpotBugs | ||
run: mvn spotbugs:check -fn | ||
continue-on-error: true # Allows this step to fail without failing the job | ||
|
||
- name: Upload SpotBugs Report | ||
if: always() | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: spotbugs-report | ||
path: target/spotbugs/ | ||
|
||
- name: Notify Code Analysis Issues | ||
if: failure() | ||
uses: dawidd6/action-send-mail@v3 | ||
with: | ||
server_address: smtp.example.com | ||
server_port: 587 | ||
username: ${{ secrets.SMTP_USERNAME }} | ||
password: ${{ secrets.SMTP_PASSWORD }} | ||
subject: 'Code Analysis Encountered Issues' | ||
body: | | ||
The static code analysis has completed with issues. Please check the workflow logs for details. | ||
to: [email protected] | ||
from: [email protected] | ||
|
||
# Job 6: Package the Application | ||
package: | ||
needs: [unit-tests, integration-tests, code-analysis] | ||
runs-on: ubuntu-latest | ||
name: Package Application | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set Up JDK 11 | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'temurin' | ||
java-version: '11' | ||
cache: maven | ||
|
||
- name: Maven Package | ||
run: mvn package -fn | ||
|
||
- name: Upload Package Artifact | ||
if: always() | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: packaged-artifact | ||
path: target/*.jar | ||
|
||
- name: Notify Packaging Issues | ||
if: failure() | ||
uses: dawidd6/action-send-mail@v3 | ||
with: | ||
server_address: smtp.example.com | ||
server_port: 587 | ||
username: ${{ secrets.SMTP_USERNAME }} | ||
password: ${{ secrets.SMTP_PASSWORD }} | ||
subject: 'Packaging Encountered Issues' | ||
body: | | ||
The packaging step has completed with issues. Please check the workflow logs for details. | ||
to: [email protected] | ||
from: [email protected] | ||
|
||
# Job 7: Deploy the Application | ||
deploy: | ||
needs: package | ||
runs-on: ubuntu-latest | ||
name: Deploy Application | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set Up JDK 11 | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'temurin' | ||
java-version: '11' | ||
|
||
- name: Download Packaged Artifact | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: packaged-artifact | ||
path: deploy/ | ||
|
||
- name: Deploy to Server | ||
env: | ||
DEPLOYMENT_SERVER: ${{ secrets.DEPLOYMENT_SERVER }} | ||
DEPLOYMENT_USER: ${{ secrets.DEPLOYMENT_USER }} | ||
DEPLOYMENT_KEY: ${{ secrets.DEPLOYMENT_KEY }} | ||
run: | | ||
# Ensure SSH key has proper permissions | ||
mkdir -p ~/.ssh | ||
echo "$DEPLOYMENT_KEY" > ~/.ssh/id_rsa | ||
chmod 600 ~/.ssh/id_rsa | ||
# Add server to known hosts to prevent prompt | ||
ssh-keyscan $DEPLOYMENT_SERVER >> ~/.ssh/known_hosts | ||
# Securely copy the JAR to the deployment server | ||
scp deploy/*.jar $DEPLOYMENT_USER@$DEPLOYMENT_SERVER:/path/to/deploy/ | ||
# Execute deployment commands on the server | ||
ssh -i ~/.ssh/id_rsa $DEPLOYMENT_USER@$DEPLOYMENT_SERVER 'bash -s' <<'ENDSSH' | ||
cd /path/to/deploy/ | ||
pkill -f your-application.jar || true | ||
nohup java -jar your-application.jar > application.log 2>&1 & | ||
ENDSSH || echo "Deployment commands failed, but continuing" | ||
- name: Notify Deployment Success | ||
if: success() | ||
uses: dawidd6/action-send-mail@v3 | ||
with: | ||
server_address: smtp.example.com | ||
server_port: 587 | ||
username: ${{ secrets.SMTP_USERNAME }} | ||
password: ${{ secrets.SMTP_PASSWORD }} | ||
subject: 'Deployment Successful' | ||
body: | | ||
The application has been successfully deployed to ${{ secrets.DEPLOYMENT_SERVER }}. | ||
to: [email protected] | ||
from: [email protected] | ||
|
||
- name: Notify Deployment Failure | ||
if: failure() | ||
uses: dawidd6/action-send-mail@v3 | ||
with: | ||
server_address: smtp.example.com | ||
server_port: 587 | ||
username: ${{ secrets.SMTP_USERNAME }} | ||
password: ${{ secrets.SMTP_PASSWORD }} | ||
subject: 'Deployment Failed' | ||
body: | | ||
The deployment to ${{ secrets.DEPLOYMENT_SERVER }} has failed. Please check the workflow logs for details. | ||
to: [email protected] | ||
from: [email protected] |