Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .github/actions/artifact-size-metrics/show-results/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Artifact Size Metrics - Show Results
description: Posts a new artifact analysis comment on the PR

runs:
using: "composite"
steps:
- name: Post Artifact Analysis Comment
uses: actions/github-script@v7
with:
script: |
const fs = require('node:fs')
const prNumber = context.issue.number ?? process.env.SDK_PR

const prInfo = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber
})

const hasAcknowledgeLabel = prInfo.data.labels.some(label => label.name === 'acknowledge-artifact-size-increase')

const getComments = `
query {
repository(owner:"${context.repo.owner}", name:"${context.repo.repo}"){
pullRequest(number: ${prNumber}) {
id
comments(last:100) {
nodes {
id
body
author {
login
}
isMinimized
}
}
}
}`

const response = await github.graphql(getComments)
const comments = response.repository.pullRequest.comments.nodes

// Minimize outdated artifact-size comments
const mutations = comments
.filter(comment => comment.author.login == 'github-actions' && !comment.isMinimized && comment.body.startsWith('Affected Artifacts'))
.map(comment =>
github.graphql(`mutation {
minimizeComment(input:{subjectId:"${comment.id}", classifier:OUTDATED}){
clientMutationId
}
}`)
)
await Promise.all(mutations)

const comment = fs.readFileSync('build/reports/metrics/artifact-analysis.md', 'utf8')

// Create a new comment with the latest artifact analysis
const writeComment = `mutation {
addComment(input:{body:"""${comment}""", subjectId:"${response.repository.pullRequest.id}"}){
commentEdge {
node {
id
}
}
}}`
const addCommentResponse = await github.graphql(writeComment)
const newCommentId = addCommentResponse.addComment.commentEdge.node.id

// Minimize the newly-created comment if artifact size increase is acknowledged
if (hasAcknowledgeLabel) {
await github.graphql(`mutation {
minimizeComment(input:{subjectId:"${newCommentId}", classifier:RESOLVED}){
clientMutationId
}
}`)
}