Skip to content

Commit d628916

Browse files
committed
comment restructured
1 parent feb35e3 commit d628916

File tree

2 files changed

+17
-43
lines changed

2 files changed

+17
-43
lines changed

.github/workflows/wpt-test.yml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,6 @@ jobs:
3535
WPT_API_KEY: ${{ secrets.HA_API_KEY }}
3636
PR_BODY: ${{ github.event.pull_request.body }}
3737

38-
- name: Upload artifact if needed
39-
id: artifact-upload-step
40-
uses: actions/upload-artifact@v4
41-
with:
42-
path: artifact.md
43-
44-
- name: Update comment.md
45-
run: |
46-
if grep -q "{artifact-url}" comment.md; then
47-
artifact_url="${{ steps.artifact-upload-step.outputs.artifact-url }}"
48-
sed -i "s|{artifact-url}|$artifact_url|g" comment.md
49-
echo "Placeholder {artifact-url} replaced with a value: $artifact_url."
50-
else
51-
echo "No placeholder {artifact-url} found in comment.md."
52-
fi
53-
5438
- name: Add comment to PR
5539
uses: mshick/add-pr-comment@v2
5640
if: always()

tests/wpt.js

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ class WPTTestRunner {
1111
const wptApiKey = process.env.WPT_API_KEY;
1212
this.wpt = new WebPageTest(this.wptServer, wptApiKey);
1313
this.testResultsFile = 'comment.md';
14-
this.artifactFile = 'artifact.md';
15-
this.uploadArtifact = false;
14+
this.commentSizeLimitHit = false;
1615
}
1716

1817
/**
@@ -41,21 +40,15 @@ class WPTTestRunner {
4140
* Check if the test results are too big for a comment
4241
* @param {number} stringLength Length of the test results string
4342
*/
44-
commentSizeLimitHit(stringLength) {
45-
let commentSize = 0;
46-
try {
47-
commentSize = fs.statSync(this.testResultsFile).size;
48-
} catch (err) { }
49-
50-
if (commentSize + stringLength > 65536) {
51-
this.uploadArtifact = true;
52-
fs.appendFileSync(this.testResultsFile, `
53-
Next WebPageTest results are too big for a comment - [download them as an artifact]({artifact-url}).
54-
`);
55-
return true;
56-
} else {
57-
return false;
43+
checkCommentSizeLimit(stringLength) {
44+
let commentSize = fs.statSync(this.testResultsFile, throwIfNoEntry=false) ?
45+
fs.statSync(this.testResultsFile, throwIfNoEntry=false)?.size : 0;
46+
47+
if (commentSize + stringLength > 64500) {
48+
this.commentSizeLimitHit = true;
5849
}
50+
51+
return this.commentSizeLimitHit;
5952
}
6053

6154
/**
@@ -102,27 +95,24 @@ Next WebPageTest results are too big for a comment - [download them as an artifa
10295
const metricsToLogObject = this.extractLogMetrics(metricsObject, metricsToLog);
10396
const metricsToLogString = JSON.stringify(metricsToLogObject, null, 2);
10497

105-
let WPTResults = `<details>
106-
<summary><strong>Custom metrics for ${url}</strong></summary>
98+
let WPTResults = `<details><summary>${url}</summary>
10799
108-
WPT test run results: ${response.data.summary}
109-
`,
100+
[WPT test results](${response.data.summary})\n`,
110101
metricsObjectResult = `
111102
Changed custom metrics values:
112103
\`\`\`json
113104
${metricsToLogString}
114105
\`\`\`
106+
</details>\n\n`,
107+
metricsObjectJSON = `
108+
Cannot display changed custom metrics due to comment size limits, \
109+
use [test JSON](https://webpagetest.httparchive.org/jsonResult.php?test=${response.data.id}&pretty=1) instead.
115110
</details>\n\n`;
116111

117-
if (!this.uploadArtifact && !this.commentSizeLimitHit(metricsToLogString.length)) {
112+
if (!this.commentSizeLimitHit && !this.checkCommentSizeLimit(metricsToLogString.length)) {
118113
fs.appendFileSync(this.testResultsFile, WPTResults + metricsObjectResult);
119114
} else {
120-
fs.appendFileSync(this.testResultsFile, `
121-
<summary><strong>Custom metrics for ${url}</strong></summary>
122-
123-
WPT test run results: ${response.data.summary}
124-
`);
125-
fs.appendFileSync(this.artifactFile, WPTResults + metricsObjectResult);
115+
fs.appendFileSync(this.testResultsFile, WPTResults + metricsObjectJSON);
126116
}
127117

128118
console.log('::endgroup::');

0 commit comments

Comments
 (0)