-
Notifications
You must be signed in to change notification settings - Fork 4
200 lines (174 loc) · 7.15 KB
/
Github_CI_Master.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
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