Update artifact-size-metrics.yml #13
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Artifact Size Metrics | |
on: | |
pull_request: | |
types: [ opened, synchronize, reopened, labeled, unlabeled ] | |
branches: [ main ] | |
release: | |
types: [published] | |
permissions: | |
id-token: write | |
contents: read | |
pull-requests: write | |
jobs: | |
release-metrics: | |
if: ${{ github.event_name }} == 'release' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Sources | |
uses: actions/checkout@v4 | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: ${{ secrets.CI_AWS_ROLE_ARN }} | |
aws-region: us-west-2 | |
- name: Generate Artifact Size Metrics | |
run: ./gradlew artifactSizeMetrics | |
- name: Save Artifact Size Metrics | |
run: | | |
cd build/reports/metrics/ | |
REPOSITORY=$(echo ${{ github.repository }} | cut -d '/' -f 2) | |
aws s3 cp artifact-size-metrics.csv s3://${{ secrets.ARTIFACT_METRICS_BUCKET }}/$REPOSITORY-${{ github.event.release.tag_name }}-release.csv | |
aws s3 cp artifact-size-metrics.csv s3://${{ secrets.ARTIFACT_METRICS_BUCKET }}/$REPOSITORY-latest-release.csv | |
- name: Put Artifact Size Metrics in CloudWatch | |
run: ./gradlew putArtifactSizeMetricsInCloudWatch -Prelease=${{ github.event.release.tag_name }} | |
size-check: | |
if: ${{ github.event_name }} == 'pull_request' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Sources | |
uses: actions/checkout@v4 | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: ${{ secrets.CI_AWS_ROLE_ARN }} | |
aws-region: us-west-2 | |
- name: Generate Artifact Size Metrics | |
run: ./gradlew artifactSizeMetrics | |
- name: Analyze Artifact Size Metrics | |
run: ./gradlew analyzeArtifactSizeMetrics | |
- name: Show Results | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const getComments = | |
`query { | |
repository(owner:"${context.repo.owner}", name:"${context.repo.repo}"){ | |
pullRequest(number: ${context.issue.number}) { | |
id | |
comments(last:100) { | |
nodes { | |
id | |
body | |
author { | |
login | |
} | |
isMinimized | |
} | |
} | |
} | |
} | |
}` | |
const response = await github.graphql(getComments) | |
const comments = response.repository.pullRequest.comments.nodes | |
for (const i in comments) { | |
if (comments[i].author.login == 'github-actions' && !comments[i].isMinimized && comments[i].body.startsWith('Affected Artifacts')) { | |
const hideComment = | |
`mutation { | |
minimizeComment(input:{subjectId:"${comments[i].id}", classifier:OUTDATED}){ | |
clientMutationId | |
} | |
}` | |
await github.graphql(hideComment) | |
} | |
} | |
const fs = require('node:fs') | |
const comment = fs.readFileSync('build/reports/metrics/artifact-analysis.md', 'utf8') | |
const writeComment = | |
`mutation { | |
addComment(input:{body:"""${comment}""", subjectId:"${response.repository.pullRequest.id}"}){ | |
clientMutationId | |
} | |
}` | |
await github.graphql(writeComment) | |
- name: Evaluate | |
if: ${{ !contains(github.event.pull_request.labels.*.name, 'acknowledge-artifact-size-increase') }} | |
run: | | |
cd build/reports/metrics | |
ls | |
cat has-significant-change.txt | grep true | |
if [ $? = 0 ]; then | |
echo An artifact increased in size by more than allowed or a new artifact was created. | |
exit 1 | |
fi |