|
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. |
3 | 3 |
|
4 | 4 | inputs: |
5 | 5 | download: |
6 | | - description: TODO |
7 | | - default: "false" |
8 | | - # TODO: Additional inputs |
| 6 | + description: Whether the artifact size metrics should be downloaded from S3 |
9 | 7 |
|
10 | 8 | runs: |
11 | 9 | using: composite |
12 | 10 | steps: |
13 | 11 | - 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. |
14 | 13 | shell: bash |
| 14 | + env: |
| 15 | + DOWNLOAD: ${{ inputs.download }} |
| 16 | + GITHUB_REPOSITORY: ${{ github.repository }} |
| 17 | + IDENTIFIER: ${{ github.ref_name }} |
15 | 18 | 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 |
22 | 21 |
|
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' |
24 | 24 | uses: actions/github-script@v7 |
25 | 25 | with: |
26 | 26 | 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({ |
30 | 34 | owner: context.repo.owner, |
31 | 35 | repo: context.repo.repo, |
32 | | - pull_number: prNumber |
| 36 | + pull_number: context.issue.number |
33 | 37 | }) |
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 } } |
90 | 45 | } |
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 | + `) |
93 | 57 |
|
94 | | - - name: Fail if large size increase |
95 | | - shell: bash |
| 58 | + - name: Large size increase? |
96 | 59 | if: ${{ !contains(github.event.pull_request.labels.*.name, 'acknowledge-artifact-size-increase') }} |
| 60 | + shell: bash |
97 | 61 | run: | |
98 | 62 | 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." |
101 | 65 | exit 1 |
102 | 66 | fi |
0 commit comments