Skip to content

Feature/dts 42248 report generation gp #4468

Feature/dts 42248 report generation gp

Feature/dts 42248 report generation gp #4468

name: CI # Define the name of the workflow
# Define when the workflow should trigger
on:
pull_request:
types:
- labeled # Trigger when a label is added
- unlabeled # Trigger when a label is removed
- synchronize # Trigger when commits are pushed to the PR
- opened # Trigger when a PR is opened
- edited # Trigger when a PR title or description is edited
- ready_for_review # Trigger when a draft PR is marked as ready
- reopened # Trigger when a closed PR is reopened
- unlocked # Trigger when a locked PR is unlocked
branches: [master, develop, qa-master] # Apply to these branches
pull_request_review:
types: [edited, dismissed] # Trigger when a review is edited or dismissed
branches: [master, develop, qa-master]
workflow_dispatch: # Allow manual triggering of the workflow
# Define environment variables
env:
GITHUB_HEAD_NAME: $GITHUB_HEAD_REF # Store the head branch name
sonartoken: ${{ secrets.SONARQUBE_TOKEN }} # Secret for SonarQube authentication
sonarurl: ${{ secrets.SONARURL }} # SonarQube URL stored in secrets
jobs:
# ✅ Detect Changed Files
detect_changes:
runs-on: ubuntu-latest # Use Ubuntu as the runner
outputs:
UI: ${{ steps.filter.outputs.UI }} # Output if UI files changed
customapi: ${{ steps.filter.outputs.customapi }} # Output if customapi files changed
processors: ${{ steps.filter.outputs.processors }} # Output if processor files changed
steps:
- name: Checkout Repository # Clone the repo
uses: actions/checkout@v2
- name: Detect Changes # Identify modified files
id: filter
uses: dorny/paths-filter@v2
with:
filters: |
UI:
- 'UI/src/**'
customapi:
- 'customapi/src/**'
processors:
- 'processors/**'
# ✅ UI Build & Testing
ui_ci:
runs-on: ubuntu-latest
needs: detect_changes # Run only if detect_changes job is successful
if: needs.detect_changes.outputs.UI == 'true' # Only run if UI files changed
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Set Up Node.js # Set up Node.js environment
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install Dependencies & Build UI
run: |
cd UI
sudo chown -R $(whoami) /usr/local/lib/node_modules
sudo npm cache clean --force
sudo npm install
sudo npm install -g @angular/[email protected]
sudo npm run build:dev
- name: Run UI Unit Tests
run: |
cd UI
sudo npm install --save-dev @angular-devkit/[email protected]
sudo ng test --code-coverage
- name: SonarQube Analysis - UI # Run static analysis
run: |
cd UI
sudo chown -R $(whoami) /home/runner/work/PSknowHOW/PSknowHOW/UI/
echo "sonar.branch.name=${{ env.GITHUB_HEAD_NAME }}" >> sonar-project.properties
echo "sonar.host.url=${{ secrets.SONARQUBE_HOST }}" >> sonar-project.properties
echo "sonar.login=${{ secrets.SONARQUBE_TOKEN }}" >> sonar-project.properties
npm install -D sonarqube-scanner
npm run sonar
- name: Check SonarQube Quality Gate - UI
run: |
chmod +x SonarDelay.sh
./SonarDelay.sh ./UI/.scannerwork/report-task.txt
# ✅ CustomAPI Build & SonarQube Analysis
customapi_ci:
runs-on: ubuntu-latest
needs: detect_changes
if: needs.detect_changes.outputs.customapi == 'true'
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Set Up Java
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '17'
- name: Cache Maven packages
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Build & Test CustomAPI
run: mvn clean install -Pcustomapi -Ddockerfile.skip=true
- name: SonarQube Analysis - CustomAPI
run: |
mvn sonar:sonar -Dsonar.projectKey=ENGINEERING.KPIDASHBOARD.CUSTOMAPI \
-Dsonar.projectName=ENGINEERING.KPIDASHBOARD.CUSTOMAPI \
-Dsonar.branch.name=${{ env.GITHUB_HEAD_NAME }} \
-Dsonar.host.url=${{ secrets.SONARQUBE_HOST }} \
-Dsonar.login=${{ secrets.SONARQUBE_TOKEN }} -f customapi/pom.xml
- name: Check SonarQube Quality Gate - CustomAPI
run: |
chmod +x SonarDelay.sh
./SonarDelay.sh ./customapi/target/sonar/report-task.txt
# ✅ Building & Testing Processors
processors_ci:
runs-on: ubuntu-latest
needs: detect_changes
if: needs.detect_changes.outputs.processors == 'true'
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Set Up Java
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '17'
- name: Cache Maven packages
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Build & Test Jira Processor
run: mvn clean install -Pjira-processor -Ddockerfile.skip=true
- name: Build & Test Azure Board Processor
run: mvn clean install -Pazure-board-processor -Ddockerfile.skip=true
- name: Build & Test DevOps Processor
run: mvn clean install -Pdevops-processor -Ddockerfile.skip=true
- name: Build & Test Azure Pipeline Repo Processor
run: mvn clean install -Pazure-pipeline-repo -Ddockerfile.skip=true
- name: SonarQube Analysis - Processors
run: |
mvn sonar:sonar -Dsonar.projectKey=ENGINEERING.KPIDASHBOARD.PROCESSORS \
-Dsonar.projectName=ENGINEERING.KPIDASHBOARD.PROCESSORS \
-Dsonar.branch.name=${{ env.GITHUB_HEAD_NAME }} \
-Dsonar.host.url=${{ secrets.SONARQUBE_HOST }} \
-Dsonar.login=${{ secrets.SONARQUBE_TOKEN }} -f processors/pom.xml
- name: Check SonarQube Quality Gate - Processors
run: |
chmod +x SonarDelay.sh
./SonarDelay.sh ./processors/target/sonar/report-task.txt
# ✅ Final Job to Ensure Completion
GitHub_CI_Complete:
needs: [processors_ci, ui_ci, customapi_ci]
if: always()
runs-on: ubuntu-latest
steps:
- name: Check Job Status
run: |
if [[ "${{ needs.processors_ci.result }}" == "failure" || \
"${{ needs.ui_ci.result }}" == "failure" || \
"${{ needs.customapi_ci.result }}" == "failure" || \
"${{ needs.processors_ci.result }}" == "cancelled" || \
"${{ needs.ui_ci.result }}" == "cancelled" || \
"${{ needs.customapi_ci.result }}" == "cancelled" ]]; then
echo "❌ One or more jobs failed or were cancelled. Failing CI."
exit 1
else
echo "✅ All relevant jobs have passed."
fi