Skip to content

Create CI/CD for OBS #4

Create CI/CD for OBS

Create CI/CD for OBS #4

Workflow file for this run

name: Java CI/CD Pipeline with Maven
on:
push:
branches: [ "main", "staging" ]
pull_request:
branches: [ "main", "staging" ]
jobs:
# 1. Build Stage
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn clean install
# 2. Test Stage
test:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Run Unit Tests
run: mvn test
- name: Run Integration Tests
run: mvn verify
# 3. Code Quality Check with SonarQube
# quality-check:
# runs-on: ubuntu-latest
# needs: build
# steps:
# - uses: actions/checkout@v4
#
# - name: Set up JDK 17
# uses: actions/setup-java@v4
# with:
# java-version: '17'
# distribution: 'temurin'
#
# - name: SonarQube Scan
# env:
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# run: mvn sonar:sonar -Dsonar.login=${{ secrets.SONAR_TOKEN }}
# 4. Deployment Stage
# deploy:
# runs-on: ubuntu-latest
# needs: test
# steps:
# - uses: actions/checkout@v4
#
# - name: Set up JDK 17
# uses: actions/setup-java@v4
# with:
# java-version: '17'
# distribution: 'temurin'
#
# - name: Login to Docker Hub
# uses: docker/login-action@v2
# with:
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_PASSWORD }}
#
# - name: Build Docker Image
# run: docker build -t ${{ secrets.DOCKER_USERNAME }}/online-banking-service:${{ github.sha }} .
#
# - name: Push Docker Image
# run: docker push ${{ secrets.DOCKER_USERNAME }}/online-banking-service:${{ github.sha }}
#
# - name: Deploy to Staging
# if: github.ref == 'refs/heads/staging'
# run: |
# echo "Deploying to staging environment"
# # Add deployment script or command here
#
# - name: Deploy to Production
# if: github.ref == 'refs/heads/main'
# run: |
# echo "Deploying to production environment"
# # Add deployment script or command here
# 5. Notifications
# notifications:
# runs-on: ubuntu-latest
# needs: [build, quality-check, test, deploy]
# steps:
# - name: Notify on Success or Failure
# if: always()
# run: |
# if [ "${{ job.status }}" == "success" ]; then
# echo "Build and deployment successful."
# else
# echo "Build or deployment failed."
# fi