forked from complytime/complytime-collector-components
-
Notifications
You must be signed in to change notification settings - Fork 0
102 lines (92 loc) · 3.23 KB
/
Copy pathci_crapload.yml
File metadata and controls
102 lines (92 loc) · 3.23 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
# CRAP Load Check
# ===============
# Runs CRAP load analysis on pull requests targeting main.
# Consumes the reusable workflow from org-infra.
#
# SPDX-License-Identifier: Apache-2.0
name: CRAP Load Check
on:
pull_request:
branches:
- main
permissions:
contents: read
pull-requests: write
jobs:
crapload:
name: CRAP Load Analysis
uses: complytime/org-infra/.github/workflows/reusable_crapload_analysis.yml@cfd981e757253218aefb37c91969c32827e5c4b1 # v0.2.1
permissions:
contents: read
post-comment:
name: Post PR Comment
needs: crapload
if: ${{ !cancelled() }}
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Download comment body
id: download
continue-on-error: true
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: crapload-analysis
path: artifact
- name: Post or update PR comment
continue-on-error: true
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const fs = require('fs');
const marker = '<!-- crapload-analysis-marker -->';
const bodyPath = 'artifact/crapload-comment-body.md';
const runUrl = [
context.serverUrl,
context.repo.owner,
context.repo.repo,
'actions/runs',
context.runId,
].join('/');
const MAX_COMMENT_LENGTH = 60000;
let body;
if (fs.existsSync(bodyPath)) {
body = fs.readFileSync(bodyPath, 'utf8');
if (body.length > MAX_COMMENT_LENGTH) {
const lastNewline = body.lastIndexOf('\n', MAX_COMMENT_LENGTH);
body = body.substring(0, lastNewline > 0 ? lastNewline : MAX_COMMENT_LENGTH);
body += '\n\n---\n';
body += '> **Note:** This report was truncated due to size.';
body += ` [View the full analysis in the Job Summary](${runUrl}).`;
}
} else {
body = [
marker,
'## ❌ CRAP Load Analysis',
'',
'The CRAP Load analysis could not generate a detailed report.',
'',
`[View the full analysis in the Job Summary](${runUrl}).`,
].join('\n');
}
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c => c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}