|
| 1 | +name: Artifact Size Metrics |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + types: [ opened, synchronize, reopened, labeled, unlabeled ] |
| 5 | + branches: [ main ] |
| 6 | + release: |
| 7 | + types: [published] |
| 8 | + |
| 9 | +permissions: |
| 10 | + id-token: write |
| 11 | + contents: read |
| 12 | + pull-requests: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + release-metrics: |
| 16 | + if: github.event_name == 'release' |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - name: Checkout Sources |
| 20 | + uses: actions/checkout@v4 |
| 21 | + - name: Configure AWS Credentials |
| 22 | + uses: aws-actions/configure-aws-credentials@v4 |
| 23 | + with: |
| 24 | + role-to-assume: ${{ secrets.CI_AWS_ROLE_ARN }} |
| 25 | + aws-region: us-west-2 |
| 26 | + - name: Generate Artifact Size Metrics |
| 27 | + run: ./gradlew artifactSizeMetrics |
| 28 | + - name: Save Artifact Size Metrics |
| 29 | + run: ./gradlew saveArtifactSizeMetrics |
| 30 | + - name: Put Artifact Size Metrics in CloudWatch |
| 31 | + run: ./gradlew putArtifactSizeMetricsInCloudWatch -Prelease=${{ github.event.release.tag_name }} |
| 32 | + size-check: |
| 33 | + if: github.event_name == 'pull_request' |
| 34 | + runs-on: ubuntu-latest |
| 35 | + steps: |
| 36 | + - name: Checkout Sources |
| 37 | + uses: actions/checkout@v4 |
| 38 | + - name: Configure AWS Credentials |
| 39 | + uses: aws-actions/configure-aws-credentials@v4 |
| 40 | + with: |
| 41 | + role-to-assume: ${{ secrets.CI_AWS_ROLE_ARN }} |
| 42 | + aws-region: us-west-2 |
| 43 | + - name: Generate Artifact Size Metrics |
| 44 | + run: ./gradlew artifactSizeMetrics |
| 45 | + - name: Analyze Artifact Size Metrics |
| 46 | + run: ./gradlew analyzeArtifactSizeMetrics |
| 47 | + - name: Show Results |
| 48 | + uses: actions/github-script@v7 |
| 49 | + with: |
| 50 | + script: | |
| 51 | + const getComments = |
| 52 | + `query { |
| 53 | + repository(owner:"${context.repo.owner}", name:"${context.repo.repo}"){ |
| 54 | + pullRequest(number: ${context.issue.number}) { |
| 55 | + id |
| 56 | + comments(last:100) { |
| 57 | + nodes { |
| 58 | + id |
| 59 | + body |
| 60 | + author { |
| 61 | + login |
| 62 | + } |
| 63 | + isMinimized |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | + } |
| 68 | + }` |
| 69 | + |
| 70 | + const response = await github.graphql(getComments) |
| 71 | + const comments = response.repository.pullRequest.comments.nodes |
| 72 | +
|
| 73 | + const mutations = comments |
| 74 | + .filter(comment => comment.author.login == 'github-actions' && !comment.isMinimized && comment.body.startsWith('Affected Artifacts')) |
| 75 | + .map(comment => |
| 76 | + github.graphql( |
| 77 | + `mutation { |
| 78 | + minimizeComment(input:{subjectId:"${comment.id}", classifier:OUTDATED}){ |
| 79 | + clientMutationId |
| 80 | + } |
| 81 | + }` |
| 82 | + ) |
| 83 | + ) |
| 84 | + await Promise.all(mutations) |
| 85 | +
|
| 86 | + const fs = require('node:fs') |
| 87 | + const comment = fs.readFileSync('build/reports/metrics/artifact-analysis.md', 'utf8') |
| 88 | +
|
| 89 | + const writeComment = |
| 90 | + `mutation { |
| 91 | + addComment(input:{body:"""${comment}""", subjectId:"${response.repository.pullRequest.id}"}){ |
| 92 | + clientMutationId |
| 93 | + } |
| 94 | + }` |
| 95 | + |
| 96 | + await github.graphql(writeComment) |
| 97 | +
|
| 98 | + - name: Evaluate |
| 99 | + if: ${{ !contains(github.event.pull_request.labels.*.name, 'acknowledge-artifact-size-increase') }} |
| 100 | + run: | |
| 101 | + cd build/reports/metrics |
| 102 | + cat has-significant-change.txt | grep false || { |
| 103 | + echo An artifact increased in size by more than allowed or a new artifact was created. |
| 104 | + echo If this is expected please add the 'acknowledge-artifact-size-increase' label to this pull request. |
| 105 | + exit 1 |
| 106 | + } |
0 commit comments