-
Notifications
You must be signed in to change notification settings - Fork 0
109 lines (98 loc) · 3.03 KB
/
test.yml
File metadata and controls
109 lines (98 loc) · 3.03 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
107
108
109
name: Test
on:
workflow_call:
inputs:
pr_number:
required: true
type: number
pr_actor:
required: true
type: string
pr_head_ref:
required: true
type: string
pr_head_sha:
required: true
type: string
concurrency:
group: test-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
issues: write
pull-requests: write
jobs:
test:
name: Swift Test
runs-on: macos-15
steps:
- name: Checkout
uses: actions/checkout@v5
with:
ref: ${{ inputs.pr_head_sha }}
- name: Swift Version
run: swift --version
- name: Test
shell: bash
run: |
set -euo pipefail
set -o pipefail
set +e
swift test 2>&1 | tee test.log
testStatus=${PIPESTATUS[0]}
set -e
exit $testStatus
- name: Upload test log artifact
if: always()
uses: actions/upload-artifact@v7
with:
name: test-log
path: test.log
if-no-files-found: ignore
notify_pr_failure:
name: Notify PR Failure (Test)
needs: test
if: ${{ always() && needs.test.result == 'failure' }}
runs-on: ubuntu-latest
steps:
- name: Download test log artifact
uses: actions/download-artifact@v7
with:
name: test-log
path: artifacts
continue-on-error: true
- name: Comment on Failed PR
uses: actions/github-script@v8
with:
script: |
const fs = require('fs');
let body = [
`@${{ inputs.pr_actor }} test CI가 실패했습니다.`,
'',
`- Workflow: ${context.workflow}`,
`- Branch: ${{ inputs.pr_head_ref }}`,
`- Commit: ${{ inputs.pr_head_sha }}`,
`- Run: ${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${process.env.GITHUB_RUN_ID}`,
].join('\n');
const logPath = 'artifacts/test.log';
if (fs.existsSync(logPath)) {
const log = fs.readFileSync(logPath, 'utf8');
const lines = log.split(/\r?\n/);
const errorLines = lines.filter((line) =>
/error:/i.test(line) || /fatal error:/i.test(line) || /failed/i.test(line)
);
const trimmedLines = errorLines.slice(0, 30);
if (0 < trimmedLines.length) {
body += '\n\n### 오류 요약\n```\n' + trimmedLines.join('\n') + '\n```';
} else {
body += '\n\n### 오류 요약\n로그에서 에러 라인을 찾지 못했습니다.';
}
} else {
body += '\n\n### 오류 요약\ntest.log를 찾지 못했습니다.';
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ inputs.pr_number }},
body,
});