-
Notifications
You must be signed in to change notification settings - Fork 1
106 lines (90 loc) · 3.61 KB
/
unitTestPipeline.yaml
File metadata and controls
106 lines (90 loc) · 3.61 KB
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
name: Unit-Test pipeline and publish results
on:
workflow_dispatch: # manual run
pull_request: # auto run only on PRs into master
branches:
- master
jobs:
trigger-unit-tests-job:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup Java and Maven
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17' # or 11 based on your project
- name: Unit-Test execution started
run: mvn clean surefire-report:report
- name: Test Run Completed
if: always()
run: |
echo "✅ Job completed for ${{ inputs.userName }} on branch ${{ github.ref_name }}"
cat target/surefire-reports/*Test.txt
- name: Upload Surefire HTML Report
if: always()
uses: actions/upload-artifact@v4
with:
name: surefire-report
path: target/site/surefire-report.html
- name: Extract Test Summary
id: test_summary
if: always()
run: |
total=0
failures=0
errors=0
skipped=0
duration=0
for file in target/surefire-reports/TEST-*.xml; do
if [ -f "$file" ]; then
t=$(grep -oP 'tests="\K[0-9]+' "$file" | head -1)
f=$(grep -oP 'failures="\K[0-9]+' "$file" | head -1)
e=$(grep -oP 'errors="\K[0-9]+' "$file" | head -1)
s=$(grep -oP 'skipped="\K[0-9]+' "$file" | head -1)
d=$(grep -oP 'time="\K[0-9]+(\.[0-9]+)?' "$file" | head -1)
total=$((total + t))
failures=$((failures + f))
errors=$((errors + e))
skipped=$((skipped + s))
# use bc for float-safe addition
duration=$(echo "$duration + $d" | bc)
fi
done
passed=$((total - failures - errors - skipped))
failed=$((failures + errors))
echo "summary=🧪 Total: $total | ✅ Passed: $passed | ❌ Failed: $failed" >> $GITHUB_OUTPUT
echo "duration=⏱️ Duration: ${duration}s" >> $GITHUB_OUTPUT
- name: Set Slack Color
id: slack_color
if: always()
run: |
if [ "${{ job.status }}" == "success" ]; then
echo "color=#36a64f" >> $GITHUB_OUTPUT
else
echo "color=#ff0000" >> $GITHUB_OUTPUT
fi
- name: Build PR link
id: pr_link
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
echo "link=*🔗 PR:* <${{ github.event.pull_request.html_url }}|#${{ github.event.pull_request.number }} - ${{ github.event.pull_request.title }}>" >> $GITHUB_OUTPUT
else
echo "link=" >> $GITHUB_OUTPUT
fi
- name: Publish Test Results on Slack
if: always()
uses: docker://technosophos/slack-notify
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_TITLE: >
Unit-Test Results - ${{ job.status == 'success' && '✅ Success' || '❌ Failed' }}
SLACK_MESSAGE: |
*👤 Triggered by:* `${{ github.actor }}`
*🌿 Branch:* `${{ github.ref_name }}`
*🧪 Test Summary:* `${{ steps.test_summary.outputs.summary }}`
*⏱️ Duration:* `${{ steps.test_summary.outputs.duration }}`
*🔗 PR:* `${{ steps.pr_link.outputs.link }}`
*📊 Full Report:* <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Open Report in Artifacts>
SLACK_COLOR: ${{ steps.slack_color.outputs.color }}