Skip to content

Commit 0907192

Browse files
committed
changes to actions
1 parent bbf999a commit 0907192

File tree

2 files changed

+53
-87
lines changed

2 files changed

+53
-87
lines changed

.github/actions/artifact-size-metrics/build-and-upload/action.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@ name: Calculate Artifact Size
22
description: Calculates size for JVM artifacts
33

44
inputs:
5-
artifact-dirs:
6-
description: List of directories for which artifact sizes will be calculated
7-
required: true
8-
# TODO: Additional inputs
5+
upload:
6+
description: Whether the metrics should be uploaded to S3/Cloudwatch
7+
release_metrics:
8+
description: Whether the metrics are coming from a release build
99

1010
runs:
1111
using: composite
1212
steps:
13-
- name: Checkout repository
14-
uses: actions/checkout@v4
15-
1613
- name: Calculate artifact sizes
1714
shell: bash
15+
env:
16+
GITHUB_REPOSITORY: ${{ github.repository }}
17+
IDENTIFIER: ${{ github.ref_name }}
18+
UPLOAD: ${{ inputs.upload }}
19+
RELEASE_METRICS: ${{ inputs.release_metrics }}
1820
run: |
19-
chmod +x ./src/main.sh
20-
./src/main.sh
21+
chmod +x ../utils/build-and-upload/main.sh
22+
../utils/build-and-upload/main.sh
Lines changed: 42 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,66 @@
1-
name: Download and process artifact size metrics
2-
description: TODO
1+
name: Process artifact size metrics
2+
description: Compares artifact size metrics, leaves a comment, and fails if a size increase of ≥5% is detected.
33

44
inputs:
55
download:
6-
description: TODO
7-
default: "false"
8-
# TODO: Additional inputs
6+
description: Whether the artifact size metrics should be downloaded from S3
97

108
runs:
119
using: composite
1210
steps:
1311
- name: Download and process artifact size metrics
12+
description: Compares artifact size metrics and sets LARGE_DIFF to true if a size increase of ≥5% is detected.
1413
shell: bash
14+
env:
15+
DOWNLOAD: ${{ inputs.download }}
16+
GITHUB_REPOSITORY: ${{ github.repository }}
17+
IDENTIFIER: ${{ github.ref_name }}
1518
run: |
16-
chmod +x ./src/main.sh
17-
chmod +x ./src/s3.sh
18-
chmod +x ./src/compare.sh
19-
chmod +x ./src/comment.sh
20-
21-
./src/main.sh
19+
chmod +x ../utils/download-and-process/main.sh
20+
../utils/download-and-process/main.sh
2221
23-
- name: Post artifact analysis comment # TODO: MOVE TO SCRIPT IF POSSIBLE
22+
- name: Comment artifact size metrics comparison
23+
if: github.event_name == 'pull_request'
2424
uses: actions/github-script@v7
2525
with:
2626
script: |
27-
const fs = require('node:fs')
28-
const prNumber = context.issue.number ?? process.env.SDK_PR # TOSO - CHANGE - THIS WON'T WORK FOR EXTERNAL CONTRIBUTORS BTW - IF EXTERNAL CONTRIBUTOR JUST FAIL
29-
const prInfo = await github.rest.pulls.get({
27+
const fs = require('node:fs')
28+
29+
// Read the artifact size metrics comparison
30+
const comparison = fs.readFileSync('build/reports/metrics/artifact-analysis.md', 'utf8')
31+
32+
// Get PR ID
33+
const { data: pullRequest } = await github.rest.pulls.get({
3034
owner: context.repo.owner,
3135
repo: context.repo.repo,
32-
pull_number: prNumber
36+
pull_number: context.issue.number
3337
})
34-
35-
const hasAcknowledgeLabel = prInfo.data.labels.some(label => label.name === 'acknowledge-artifact-size-increase')
36-
37-
const getComments = `
38-
query {
39-
repository(owner:"${context.repo.owner}", name:"${context.repo.repo}"){
40-
pullRequest(number: ${prNumber}) {
41-
id
42-
comments(last:100) {
43-
nodes {
44-
id
45-
body
46-
author {
47-
login
48-
}
49-
isMinimized
50-
}
51-
}
52-
}
53-
}
54-
}`
55-
56-
const response = await github.graphql(getComments)
57-
const comments = response.repository.pullRequest.comments.nodes
58-
59-
// Minimize outdated artifact-size comments
60-
const mutations = comments
61-
.filter(comment => comment.author.login == 'github-actions' && !comment.isMinimized && comment.body.startsWith('Affected Artifacts'))
62-
.map(comment =>
63-
github.graphql(`mutation {
64-
minimizeComment(input:{subjectId:"${comment.id}", classifier:OUTDATED}){
65-
clientMutationId
66-
}
67-
}`)
68-
)
69-
await Promise.all(mutations)
70-
71-
const comment = fs.readFileSync('build/reports/metrics/artifact-analysis.md', 'utf8')
72-
73-
// Create a new comment with the latest artifact analysis
74-
const writeComment = `mutation {
75-
addComment(input:{body:"""${comment}""", subjectId:"${response.repository.pullRequest.id}"}){
76-
commentEdge {
77-
node {
78-
id
79-
}
80-
}
81-
}}`
82-
const addCommentResponse = await github.graphql(writeComment)
83-
const newCommentId = addCommentResponse.addComment.commentEdge.node.id
84-
85-
// Minimize the newly-created comment if artifact size increase is acknowledged
86-
if (hasAcknowledgeLabel) {
87-
await github.graphql(`mutation {
88-
minimizeComment(input:{subjectId:"${newCommentId}", classifier:RESOLVED}){
89-
clientMutationId
38+
const pullRequestId = pullRequest.node_id
39+
40+
// Add the comment
41+
const addCommentResponse = await github.graphql(`
42+
mutation {
43+
addComment(input: {body: """${comparison}""", subjectId: "${pullRequestId}"}) {
44+
commentEdge { node { id } }
9045
}
91-
}`)
92-
}
46+
}
47+
`)
48+
49+
const commentId = addCommentResponse.addComment.commentEdge.node.id
50+
51+
// Minimize the comment
52+
await github.graphql(`
53+
mutation {
54+
minimizeComment(input: {subjectId: "${commentId}", classifier: RESOLVED}) { }
55+
}
56+
`)
9357
94-
- name: Fail if large size increase
95-
shell: bash
58+
- name: Large size increase?
9659
if: ${{ !contains(github.event.pull_request.labels.*.name, 'acknowledge-artifact-size-increase') }}
60+
shell: bash
9761
run: |
9862
if [ "$LARGE_DIFF" == "true" ]; then
99-
echo An artifact increased in size by more than allowed or a new artifact was created.
100-
echo If this is expected please add the 'acknowledge-artifact-size-increase' label to this pull request.
63+
echo "An artifact has increased in size by more than 5%.
64+
If this is expected, please add the acknowledge-artifact-size-increase label to this pull request."
10165
exit 1
10266
fi

0 commit comments

Comments
 (0)