Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: artifact size metrics #1075

Closed
wants to merge 16 commits into from
121 changes: 121 additions & 0 deletions .github/workflows/artifact-size-metrics.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
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 JDK
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: 17
cache: 'gradle'
- 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 JDK
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: 17
cache: 'gradle'
- 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
cat has-significant-change.txt | grep false || {
echo An artifact increased in size by more than allowed or a new artifact was created.
exit 1
}
7 changes: 7 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ plugins {
// since build-plugins also has <some> version in its dependency closure
alias(libs.plugins.kotlin.multiplatform) apply false
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.aws.kotlin.repo.tools.artifactsizemetrics)
}

artifactSizeMetrics {
artifactPrefixes = setOf(":codegen", ":runtime")
significantChangeThresholdPercentage = 5.0
projectRepositoryName = "smithy-kotlin"
}

val testJavaVersion = typedProp<String>("test.java.version")?.let {
Expand Down
3 changes: 2 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
kotlin-version = "1.9.22"
dokka-version = "1.9.10"

aws-kotlin-repo-tools-version = "0.4.0"
aws-kotlin-repo-tools-version = "0.4.2"

# libs
coroutines-version = "1.7.3"
Expand Down Expand Up @@ -104,3 +104,4 @@ kotlinx-binary-compatibility-validator = { id = "org.jetbrains.kotlinx.binary-co
kotlinx-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin-version"}
aws-kotlin-repo-tools-kmp = { id = "aws.sdk.kotlin.gradle.kmp", version.ref = "aws-kotlin-repo-tools-version" }
aws-kotlin-repo-tools-smithybuild = { id = "aws.sdk.kotlin.gradle.smithybuild", version.ref = "aws-kotlin-repo-tools-version" }
aws-kotlin-repo-tools-artifactsizemetrics = { id = "artifact-size-metrics", version.ref = "aws-kotlin-repo-tools-version" }
3 changes: 0 additions & 3 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ pluginManagement {
maven {
name = "kotlinRepoTools"
url = java.net.URI("https://d2gys1nrxnjnyg.cloudfront.net/releases")
content {
includeGroupByRegex("""aws\.sdk\.kotlin.*""")
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions tests/codegen/nullability-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ tasks.generateSmithyProjections {
smithyBuildConfigs.set(files("smithy-build.json"))
}

tasks.kotlinSourcesJar {
dependsOn(tasks.generateSmithyProjections)
}

val optinAnnotations = listOf("kotlin.RequiresOptIn", "aws.smithy.kotlin.runtime.InternalApi")
kotlin.sourceSets.all {
optinAnnotations.forEach { languageSettings.optIn(it) }
Expand Down
4 changes: 4 additions & 0 deletions tests/codegen/paginator-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ tasks.generateSmithyProjections {
smithyBuildConfigs.set(files("smithy-build.json"))
}

tasks.kotlinSourcesJar {
dependsOn(tasks.generateSmithyProjections)
}

val optinAnnotations = listOf("kotlin.RequiresOptIn", "aws.smithy.kotlin.runtime.InternalApi")
kotlin.sourceSets.all {
optinAnnotations.forEach { languageSettings.optIn(it) }
Expand Down
7 changes: 7 additions & 0 deletions tests/codegen/serde-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ val stageGeneratedSources = tasks.register("stageGeneratedSources") {
}
}

tasks.kotlinSourcesJar {
dependsOn(
tasks.generateSmithyProjections,
stageGeneratedSources,
)
}

kotlin.sourceSets.getByName("main") {
kotlin.srcDir(generatedSrcDir)
}
Expand Down
4 changes: 4 additions & 0 deletions tests/codegen/waiter-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ tasks.generateSmithyProjections {
smithyBuildConfigs.set(files("smithy-build.json"))
}

tasks.kotlinSourcesJar {
dependsOn(tasks.generateSmithyProjections)
}

val optinAnnotations = listOf("kotlin.RequiresOptIn", "aws.smithy.kotlin.runtime.InternalApi")
kotlin.sourceSets.all {
optinAnnotations.forEach { languageSettings.optIn(it) }
Expand Down
Loading