-
Notifications
You must be signed in to change notification settings - Fork 0
364 lines (324 loc) · 11.9 KB
/
main.yml
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
#
#name: Selenium TestNG CI
#
#on:
# push:
# branches:
# - main
# pull_request:
# branches:
# - main
#
#jobs:
# build:
# runs-on: ubuntu-latest
#
# steps:
# # Step 1: Checkout the code
# - name: Checkout repository
# uses: actions/checkout@v2
#
# # Step 2: Set up Java environment
# - name: Set up JDK 11
# uses: actions/setup-java@v2
# with:
# distribution: 'adopt'
# java-version: '11'
#
# # Step 3: Cache Maven dependencies for faster builds
# - name: Cache Maven dependencies
# uses: actions/cache@v2
# with:
# path: ~/.m2
# key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
# restore-keys: |
# ${{ runner.os }}-maven-
#
# # Step 4: Install Maven dependencies
# - name: Install dependencies
# run: mvn install -DskipTests
#
# # Step 5: Run TestNG tests
# - name: Run TestNG tests
# run: mvn test
#
# # Step 6: Generate Extent Reports (optional)
# - name: Upload TestNG Extent Reports
# uses: actions/upload-artifact@v2
# with:
# name: extent-reports
# path: target/extent-reports/ # Adjust this path to your reports folder
#name: Selenium TestNG CI
#
#on:
# push:
# branches:
# - main
# pull_request:
# branches:
# - main
#
#jobs:
# build:
# runs-on: ubuntu-latest
#
# steps:
# # Step 1: Checkout the code
# - name: Checkout repository
# uses: actions/checkout@v2
#
# # Step 2: Set up JDK 16 (Ensure you are using Java 16)
# - name: Set up JDK 16
# uses: actions/setup-java@v2
# with:
# distribution: 'adopt'
# java-version: '16'
#
# # Step 3: Cache Maven dependencies for faster builds
# - name: Cache Maven dependencies
# uses: actions/cache@v2
# with:
# path: ~/.m2
# key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
# restore-keys: |
# ${{ runner.os }}-maven-
#
# # Step 4: Install Maven dependencies
# - name: Install dependencies
# run: mvn install -DskipTests
#
# # Step 5: Run TestNG tests
# - name: Run TestNG tests
# run: mvn test
#
# # Step 6: Upload Extent Reports
# - name: Upload TestNG Extent Reports
# uses: actions/upload-artifact@v3
# with:
# name: extent-reports
# path: Reports
name: Selenium TestNG CI
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the code
- name: Checkout repository
uses: actions/checkout@v2
# Step 2: Set up JDK 16 (Ensure you are using Java 16)
- name: Set up JDK 16
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '16'
# Step 3: Cache Maven dependencies for faster builds
- name: Cache Maven dependencies
uses: actions/cache@v2
with:
path: ~/.m2
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
# Step 4: Install Maven dependencies
- name: Install dependencies
run: mvn install -DskipTests
# Step 4: Clean Temporary Reports Directory
- name: Clean Temp Reports Directory
run: |
if [ -d "/tmp/reports" ]; then
rm -rf /tmp/reports/*
echo "Old temporary reports cleaned."
else
mkdir -p /tmp/reports
echo "Created temporary reports directory."
fi
# Step 4: Run UI-Automation tests with Chrome browser
- name: Run UI-Automation tests with Chrome browser
run: mvn test -Dthread=3 -Dlaunch=remote # Adjust as necessary for your project
# Step 5: Generate Extent Report
- name: Generate Extent Report
if: always() # Ensure report generation runs regardless of test success/failure
run: mvn site # Adjust this to your Extent report generation command
# Step 6: Deploy Extent Report
- name: Deploy Extent Report
if: always()
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GH_TOKEN }} # Use the secret created
publish_branch: gh-pages
publish_dir: target/extent-reports
env:
JAVA_HOME: /opt/hostedtoolcache/Java_Adopt_jdk/16.0.2-7/x64
# Step 7: Upload Extent Report as Artifact using the latest version (v3)
- name: Upload Extent Report as Artifact
if: always()
uses: actions/upload-artifact@v3 # Updated to v3 to avoid deprecation
with:
name: extent-report
path: Reports/* # Update to your report directory path
# Step 8: Send email with Extent Reports (Optional)
- name: Send email with Extent Reports
if: always() # Ensure this step runs whether the build succeeds or fails
uses: dawidd6/action-send-mail@v3
with:
server_address: smtp.gmail.com
server_port: 465
username: ${{ secrets.EMAIL_USERNAME }}
password: ${{ secrets.EMAIL_PASSWORD }}
subject: "Extent Report - Build ${{ github.run_number }}: ${{ job.status }}"
body: |
Hello,
The UI Automation build ${{ github.run_number }} has completed with status: **${{ job.status }}**.
Please find the attached Extent Reports or view them at the deployed location.
Regards,
CI System
from: CI System <[email protected]>
attachments: target/extent-reports/*.html # Attach Extent HTML reports
# # Step 6: Set the report path and ensure the directory exists
# - name: Set report path
# id: set_report_path
# run: |
# REPORT_DIR=$(pwd)/Reports
# if [ -d "$REPORT_DIR" ]; then
# echo "REPORT_PATH=$REPORT_DIR" >> $GITHUB_ENV
# else
# echo "No reports directory found!"
# exit 1
# fi # Closing the if block properly
#
# # Step 7: Upload reports as artifacts (Optional)
# - name: Upload TestNG Reports
# uses: actions/upload-artifact@v3
# with:
# name: TestNG-Extent-Reports
# path: ${{ env.REPORT_PATH }}/*.html # This will upload all HTML reports
#
# # Step 8: Send email with TestNG Extent Reports
# - name: Send email with TestNG Extent Reports
# if: always() # Ensure this step runs whether the build succeeds or fails
# uses: dawidd6/action-send-mail@v3
# with:
# server_address: smtp.gmail.com
# server_port: 465
# username: ${{ secrets.EMAIL_USERNAME }} # Set up as a secret in GitHub
# password: ${{ secrets.EMAIL_PASSWORD }} # Set up as a secret in GitHub
# subject: "TestNG Automation Report - Build ${{ github.run_number }}: ${{ job.status }}"
# body: |
# Hello,
#
# The TestNG Automation build ${{ github.run_number }} has completed with status: **${{ job.status }}**.
#
# You can download the TestNG Extent Reports from the attached files.
#
# Regards,
# CI System
# from: CI System <[email protected]>
# attachments: ${{ env.REPORT_PATH }}/*.html # Attach all HTML reports in the Reports directory
# # Step 6: Set the report path
# - name: Set report path
# id: set_report_path
# run: |
# echo "REPORT_PATH=$(pwd)/Reports" >> $GITHUB_ENV
#
# # Step 7: Send email with TestNG Extent Reports
# - name: Send email with TestNG Extent Reports
# if: always() # Ensure this step runs whether the build succeeds or fails
# uses: dawidd6/action-send-mail@v3
# with:
# server_address: smtp.gmail.com
# server_port: 465
# username: ${{ secrets.EMAIL_USERNAME }} # Set up as a secret in GitHub
# password: ${{ secrets.EMAIL_PASSWORD }} # Set up as a secret in GitHub
# subject: "TestNG Automation Report - Build ${{ github.run_number }}: ${{ job.status }}"
# body: |
# Hello,
#
# The TestNG Automation build ${{ github.run_number }} has completed with status: **${{ job.status }}**.
#
# Please find the attached Extent Reports.
#
# Regards,
# CI System
# from: CI System <[email protected]>
# attachments: ${{ env.REPORT_PATH }}/*.html # Attach all HTML reports in the Reports directory
#
# # Step 6: Upload TestNG Extent Reports
# - name: Upload TestNG Extent Reports
# uses: actions/upload-artifact@v3
# with:
# name: extent-reports
# path: Reports
#
# # Step 7: Set up report file paths
# - name: Prepare report file paths
# id: report-files
# run: |
# echo "REPORT_FILES<<EOF" >> $GITHUB_ENV
# for file in Reports/*; do
# echo "$file" >> $GITHUB_ENV
# done
# echo "EOF" >> $GITHUB_ENV
#
# # Step 8: Send email with TestNG Extent Reports (Runs on both success and failure)
# - name: Send email with TestNG Extent Reports
# if: always() # Ensure this step runs whether the build succeeds or fails
# uses: dawidd6/action-send-mail@v3
# with:
# server_address: smtp.gmail.com
# server_port: 465
# username: ${{ secrets.EMAIL_USERNAME }} # Set up as a secret in GitHub
# password: ${{ secrets.EMAIL_PASSWORD }} # Set up as a secret in GitHub
# subject: "TestNG Automation Report - Build ${{ github.run_number }}: ${{ job.status }}"
# body: |
# Hello,
#
# The TestNG Automation build ${{ github.run_number }} has completed with status: **${{ job.status }}**.
#
# Please find the attached Extent Reports.
#
# Regards,
# CI System
# to: "[email protected], [email protected], [email protected]" # Replace with actual recipient emails
# from: CI System <[email protected]>
# attachments: ${{ env.REPORT_FILES }} # Attach individual report files
#
#
# # Step 6: Upload TestNG Extent Reports
# - name: Upload TestNG Extent Reports
# uses: actions/upload-artifact@v3
# with:
# name: extent-reports
# path: Reports/** # Ensure this path matches the actual path of the Extent Report
#
# # Step 7: Send email with TestNG Extent Reports (Runs on both success and failure)
# - name: Send email with TestNG Extent Reports
# if: always() # Ensure this step runs whether the build succeeds or fails
# uses: dawidd6/action-send-mail@v3
# with:
# server_address: smtp.gmail.com
# server_port: 465
# username: ${{ secrets.EMAIL_USERNAME }} # Set up as a secret in GitHub
# password: ${{ secrets.EMAIL_PASSWORD }} # Set up as a secret in GitHub
# subject: "TestNG Automation Report - Build ${{ github.run_number }}: ${{ job.status }}"
# body: |
# Hello,
#
# The Automation build ${{ github.run_number }} has completed with status: **${{ job.status }}**.
#
# Please find the attached Extent Reports.
#
# Regards,
# Amol K
# to: [email protected], [email protected] # Replace with actual recipient email
# from: CI System <[email protected]>
# attachments: Reports/TestSuite.html # Ensure this is the correct path to the report file