1+ name : p23_slack_notification
2+
3+ on :
4+ workflow_dispatch :
5+
6+
7+ jobs :
8+ trigger-unit-tests-job :
9+ runs-on : ubuntu-latest
10+ steps :
11+ - name : Checkout Code
12+ uses : actions/checkout@v4
13+
14+ - name : Setup Java and Maven
15+ uses : actions/setup-java@v3
16+ with :
17+ distribution : ' temurin'
18+ java-version : ' 17' # or 11 based on your project
19+
20+ - name : Unit-Test execution started
21+ run : mvn clean surefire-report:report
22+
23+ - name : Test Run Completed
24+ if : always()
25+ run : |
26+ echo "✅ Job completed for ${{ inputs.userName }} on branch ${{ github.ref_name }}"
27+ cat target/surefire-reports/*Test.txt
28+
29+ - name : Upload Surefire HTML Report
30+ if : always()
31+ uses : actions/upload-artifact@v4
32+ with :
33+ name : surefire-report
34+ path : target/site/surefire-report.html
35+
36+ - name : Extract Test Summary
37+ id : test_summary
38+ if : always()
39+ run : |
40+ total=$(grep -o "Tests run:" target/surefire-reports/*.txt | wc -l || true)
41+ passed=$(grep -o "BUILD SUCCESS" target/surefire-reports/*.txt | wc -l || true)
42+ failed=$(grep -o "Failures:" target/surefire-reports/*.txt | wc -l || true)
43+ echo "summary=🧪 Total: $total | ✅ Passed: $passed | ❌ Failed: $failed" >> $GITHUB_OUTPUT
44+
45+ - name : Set Slack Color
46+ id : slack_color
47+ if : always()
48+ run : |
49+ if [ "${{ job.status }}" == "success" ]; then
50+ echo "color=#36a64f" >> $GITHUB_OUTPUT
51+ else
52+ echo "color=#ff0000" >> $GITHUB_OUTPUT
53+ fi
54+
55+ - name : Publish Test Results on Slack
56+ if : always()
57+ uses : docker://technosophos/slack-notify
58+ env :
59+ SLACK_WEBHOOK : ${{ secrets.SLACK_WEBHOOK_URL }}
60+ SLACK_TITLE : >
61+ Unit-Test Results - ${{ job.status == 'success' && '✅ Success' || '❌ Failed' }}
62+ SLACK_MESSAGE : |
63+ *👤 Triggered by:* `${{ github.actor }}`
64+ *🌿 Branch:* `${{ github.ref_name }}`
65+ *🧪 Test Summary:* `${{ steps.test_summary.outputs.summary }}`
66+ *📊 Full Report:* <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Open Report in Artifacts>
67+ SLACK_COLOR : ${{ steps.slack_color.outputs.color }}
0 commit comments