-
Notifications
You must be signed in to change notification settings - Fork 0
101 lines (87 loc) · 3.16 KB
/
Copy pathtest-report.yml
File metadata and controls
101 lines (87 loc) · 3.16 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
name: Test Report
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
schedule:
# Run daily at 00:00 UTC to keep the report up to date
- cron: '0 0 * * *'
workflow_dispatch:
permissions:
contents: read
pull-requests: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
generate-test-report:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.11'
- name: Generate test report
run: |
python3 .github/scripts/generate_test_report.py
- name: Upload test report as artifact
uses: actions/upload-artifact@v7
with:
name: test-report
path: |
test-report.md
test-report.json
retention-days: 9
- name: Display report summary
run: |
echo "## Test Report Summary" >> $GITHUB_STEP_SUMMARY
cat test-report.md >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "---" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 🔗 Deployed Report" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "📊 [View Test Reports](https://carstenartur.github.io/sandbox/tests/)" >> $GITHUB_STEP_SUMMARY
- name: Comment PR with test report (on pull request)
if: github.event_name == 'pull_request'
uses: actions/github-script@v8
with:
script: |
try {
const fs = require('fs');
const report = fs.readFileSync('test-report.md', 'utf8');
// Find existing comment
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.data.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('# JUnit Test Overview Report')
);
const workflowUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
const commentBody = `${report}\n\n---\n*This report is automatically generated by the [Test Report workflow](${workflowUrl})*`;
if (botComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: commentBody
});
} else {
// Create new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody
});
}
} catch (e) {
core.warning('Could not post test report comment: ' + e.message);
}