Skip to content

Commit 9cfb9be

Browse files
committed
Testing workflow
1 parent 59c63da commit 9cfb9be

File tree

3 files changed

+120
-3
lines changed

3 files changed

+120
-3
lines changed
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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: |
30+
cd build/reports/metrics/
31+
REPOSITORY=$(echo ${{ github.repository }} | cut -d '/' -f 2)
32+
aws s3 cp artifact-size-metrics.csv s3://${{ secrets.ARTIFACT_METRICS_BUCKET }}/$REPOSITORY-${{ github.event.release.tag_name }}-release.csv
33+
aws s3 cp artifact-size-metrics.csv s3://${{ secrets.ARTIFACT_METRICS_BUCKET }}/$REPOSITORY-latest-release.csv
34+
- name: Put Artifact Size Metrics in CloudWatch
35+
run: ./gradlew putArtifactSizeMetricsInCloudWatch -Prelease=${{ github.event.release.tag_name }}
36+
size-check:
37+
if: ${{ github.event_name }} == 'pull_request'
38+
runs-on: ubuntu-latest
39+
steps:
40+
- name: Checkout Sources
41+
uses: actions/checkout@v4
42+
- name: Configure AWS Credentials
43+
uses: aws-actions/configure-aws-credentials@v4
44+
with:
45+
role-to-assume: ${{ secrets.CI_AWS_ROLE_ARN }}
46+
aws-region: us-west-2
47+
- name: Generate Artifact Size Metrics
48+
run: ./gradlew artifactSizeMetrics
49+
- name: Analyze Artifact Size Metrics
50+
run: ./gradlew analyzeArtifactSizeMetrics
51+
- name: Show Results
52+
uses: actions/github-script@v7
53+
with:
54+
script: |
55+
const getComments =
56+
`query {
57+
repository(owner:"${context.repo.owner}", name:"${context.repo.repo}"){
58+
pullRequest(number: ${context.issue.number}) {
59+
id
60+
comments(last:100) {
61+
nodes {
62+
id
63+
body
64+
author {
65+
login
66+
}
67+
isMinimized
68+
}
69+
}
70+
}
71+
}
72+
}`
73+
74+
const response = await github.graphql(getComments)
75+
const comments = response.repository.pullRequest.comments.nodes
76+
77+
for (const i in comments) {
78+
if (comments[i].author.login == 'github-actions' && !comments[i].isMinimized && comments[i].body.startsWith('Affected Artifacts')) {
79+
const hideComment =
80+
`mutation {
81+
minimizeComment(input:{subjectId:"${comments[i].id}", classifier:OUTDATED}){
82+
clientMutationId
83+
}
84+
}`
85+
86+
await github.graphql(hideComment)
87+
}
88+
}
89+
90+
const fs = require('node:fs')
91+
const comment = fs.readFileSync('build/reports/metrics/artifact-analysis.md', 'utf8')
92+
93+
const writeComment =
94+
`mutation {
95+
addComment(input:{body:"""${comment}""", subjectId:"${response.repository.pullRequest.id}"}){
96+
clientMutationId
97+
}
98+
}`
99+
100+
await github.graphql(writeComment)
101+
102+
- name: Evaluate
103+
if: ${{ !contains(github.event.pull_request.labels.*.name, 'acknowledge-artifact-size-increase') }}
104+
run: |
105+
cd build/reports/metrics/artifact-analysis.md
106+
cat has-significant-change.txt | grep true
107+
if [ $? = 0 ]; then
108+
echo An artifact increased in size by more than allowed or a new artifact was created.
109+
exit 1
110+
fi

build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ plugins {
2424
// since build-plugins also has <some> version in its dependency closure
2525
alias(libs.plugins.kotlin.multiplatform) apply false
2626
alias(libs.plugins.kotlin.jvm) apply false
27+
id("artifact-size-metrics") version "0.4.2" // TODO: Use lib.versions.toml
28+
}
29+
30+
artifactSizeMetrics {
31+
artifactPrefixes = setOf(":codegen", ":runtime")
32+
significantChangeThresholdPercentage = 5.0
33+
projectRepositoryName = "smithy-kotlin"
2734
}
2835

2936
val testJavaVersion = typedProp<String>("test.java.version")?.let {

settings.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ pluginManagement {
1111
maven {
1212
name = "kotlinRepoTools"
1313
url = java.net.URI("https://d2gys1nrxnjnyg.cloudfront.net/releases")
14-
content {
15-
includeGroupByRegex("""aws\.sdk\.kotlin.*""")
16-
}
14+
// content {
15+
// includeGroupByRegex("""aws\.sdk\.kotlin.*""")
16+
// }
1717
}
1818
}
1919
}

0 commit comments

Comments
 (0)