Skip to content

Commit b3caac8

Browse files
committed
Commonize "Show Results" artifact-size-metrics step
1 parent 5388018 commit b3caac8

File tree

1 file changed

+76
-0
lines changed
  • .github/actions/artifact-size-metrics/show-results

1 file changed

+76
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Artifact Size Metrics - Show Results
2+
description: Posts a new artifact analysis comment on the PR
3+
4+
runs:
5+
using: "composite"
6+
steps:
7+
- name: Post Artifact Analysis Comment
8+
uses: actions/github-script@v7
9+
with:
10+
script: |
11+
const fs = require('node:fs')
12+
const prNumber = context.issue.number ?? process.env.SDK_PR
13+
14+
const prInfo = await github.rest.pulls.get({
15+
owner: context.repo.owner,
16+
repo: context.repo.repo,
17+
pull_number: prNumber
18+
})
19+
20+
const hasAcknowledgeLabel = prInfo.data.labels.some(label => label.name === 'acknowledge-artifact-size-increase')
21+
22+
const getComments = `
23+
query {
24+
repository(owner:"${context.repo.owner}", name:"${context.repo.repo}"){
25+
pullRequest(number: ${prNumber}) {
26+
id
27+
comments(last:100) {
28+
nodes {
29+
id
30+
body
31+
author {
32+
login
33+
}
34+
isMinimized
35+
}
36+
}
37+
}
38+
}`
39+
40+
const response = await github.graphql(getComments)
41+
const comments = response.repository.pullRequest.comments.nodes
42+
43+
// Minimize outdated artifact-size comments
44+
const mutations = comments
45+
.filter(comment => comment.author.login == 'github-actions' && !comment.isMinimized && comment.body.startsWith('Affected Artifacts'))
46+
.map(comment =>
47+
github.graphql(`mutation {
48+
minimizeComment(input:{subjectId:"${comment.id}", classifier:OUTDATED}){
49+
clientMutationId
50+
}
51+
}`)
52+
)
53+
await Promise.all(mutations)
54+
55+
const comment = fs.readFileSync('build/reports/metrics/artifact-analysis.md', 'utf8')
56+
57+
// Create a new comment with the latest artifact analysis
58+
const writeComment = `mutation {
59+
addComment(input:{body:"""${comment}""", subjectId:"${response.repository.pullRequest.id}"}){
60+
commentEdge {
61+
node {
62+
id
63+
}
64+
}
65+
}}`
66+
const addCommentResponse = await github.graphql(writeComment)
67+
const newCommentId = addCommentResponse.addComment.commentEdge.node.id
68+
69+
// Minimize the newly-created comment if artifact size increase is acknowledged
70+
if (hasAcknowledgeLabel) {
71+
await github.graphql(`mutation {
72+
minimizeComment(input:{subjectId:"${newCommentId}", classifier:RESOLVED}){
73+
clientMutationId
74+
}
75+
}`)
76+
}

0 commit comments

Comments
 (0)