Skip to content

Commit 4524719

Browse files
authored
feat: artifact size metrics (#102)
1 parent c693020 commit 4524719

File tree

4 files changed

+117
-2
lines changed

4 files changed

+117
-2
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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+
}

build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ plugins {
1818
id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.13.2"
1919
alias(libs.plugins.kotlin.multiplatform) apply false
2020
alias(libs.plugins.aws.kotlin.repo.tools.kmp)
21+
alias(libs.plugins.aws.kotlin.repo.tools.artifactsizemetrics)
22+
}
23+
24+
artifactSizeMetrics {
25+
artifactPrefixes = setOf(":aws-crt-kotlin")
26+
significantChangeThresholdPercentage = 5.0
27+
projectRepositoryName = "aws-crt-kotlin"
2128
}
2229

2330
allprojects {

gradle/libs.versions.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[versions]
22
kotlin-version = "1.9.21"
33

4-
aws-kotlin-repo-tools-version = "0.3.2"
4+
aws-kotlin-repo-tools-version = "0.4.4"
55

66
# libs
77
crt-java-version = "0.29.6"
@@ -40,4 +40,5 @@ mockserver-netty = { module = "org.mock-server:mockserver-netty", version.ref =
4040

4141
[plugins]
4242
kotlin-multiplatform = {id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin-version" }
43-
aws-kotlin-repo-tools-kmp = { id = "aws.sdk.kotlin.kmp", version.ref = "aws-kotlin-repo-tools-version" }
43+
aws-kotlin-repo-tools-kmp = { id = "aws.sdk.kotlin.gradle.kmp", version.ref = "aws-kotlin-repo-tools-version" }
44+
aws-kotlin-repo-tools-artifactsizemetrics = { id = "aws.sdk.kotlin.gradle.artifactsizemetrics", version.ref = "aws-kotlin-repo-tools-version" }

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
pluginManagement {
66
repositories {
7+
mavenLocal()
78
mavenCentral()
89
gradlePluginPortal()
910
maven {

0 commit comments

Comments
 (0)