11name : AWS CodeBuild CI
22
33on :
4+ release :
5+ types : [ published ]
46 pull_request :
5- branches :
6- - main
7+ types : [ opened, synchronize, reopened, labeled, unlabeled ]
8+ branches : [ main ]
79 workflow_dispatch :
810 inputs :
911 aws-sdk-kotlin-pr :
2729permissions :
2830 id-token : write
2931 contents : read
32+ pull-requests : write
3033
3134# Allow one instance of this workflow per pull request, and cancel older runs when new changes are pushed
3235concurrency :
@@ -35,6 +38,7 @@ concurrency:
3538
3639jobs :
3740 e2e-tests :
41+ if : github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'
3842 runs-on : ubuntu-latest
3943 steps :
4044 - name : Verify PRs are not running malicious code
6367 aws codebuild stop-build --id $BUILD_ID
6468 fi
6569
66- service-check-batch :
70+ service-check-batch-and-artifact-size-metrics :
71+ if : github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'
6772 runs-on : ubuntu-latest
6873 steps :
6974 - name : Verify PRs are not running malicious code
@@ -78,14 +83,143 @@ jobs:
7883 with :
7984 role-to-assume : ${{ secrets.CI_AWS_ROLE_ARN }}
8085 aws-region : us-west-2
81- - name : Run Service Check Batch
86+ - name : Run Service Check Batch and Calculate Artifact Size Metrics
87+ id : svc-check-batch
88+ run : |
89+ REPOSITORY=$(echo ${{ github.repository }} | cut -d '/' -f 2)
90+ PULL_REQUEST=""
91+ INTERNAL=${{ github.event.number }}
92+ EXTERNAL=${{ inputs.aws-sdk-kotlin-pr }}
93+
94+ if [ ! -z "$INTERNAL" ]; then
95+ PULL_REQUEST=${{ github.event.number }}
96+ echo "Identified this an internal pull request build: $PULL_REQUEST"
97+ elif [ ! -z "$EXTERNAL" ]; then
98+ PULL_REQUEST=${{ inputs.aws-sdk-kotlin-pr }}
99+ echo "Identified this as an external pull request build: $PULL_REQUEST"
100+ else
101+ echo "Couldn't identify this as an internal or external pull request"
102+ exit 1
103+ fi
104+
105+ .github/scripts/run-codebuild-batch-job.sh \
106+ --project gh-aws-sdk-kotlin-svc-check-batch \
107+ --source ${{ github.event.pull_request.head.sha }} \
108+ --pr-number $PULL_REQUEST \
109+ --repository $REPOSITORY \
110+ --external-contributor-sdk-pr-number ${{ inputs.aws-sdk-kotlin-pr }} \
111+ --external-contributor-smithy-pr-number ${{ inputs.smithy-kotlin-pr }}
112+ - name : Cancel build
113+ if : ${{ cancelled() }}
114+ env :
115+ BUILD_ID : ${{ steps.svc-check-batch.outputs.aws-build-id }}
116+ run : |
117+ if [ ! -z "$BUILD_ID" ]; then
118+ echo "cancelling in-progress batch build: id=$BUILD_ID"
119+ aws codebuild stop-build --id $BUILD_ID
120+ fi
121+ - name : Collect Artifact Size Metrics
122+ run : |
123+ PULL_REQUEST=""
124+ INTERNAL=${{ github.event.number }}
125+ EXTERNAL=${{ inputs.aws-sdk-kotlin-pr }}
126+
127+ if [ ! -z "$INTERNAL" ]; then
128+ PULL_REQUEST=${{ github.event.number }}
129+ echo "Identified this an internal pull request build: $PULL_REQUEST"
130+ elif [ ! -z "$EXTERNAL" ]; then
131+ PULL_REQUEST=${{ inputs.aws-sdk-kotlin-pr }}
132+ echo "Identified this as an external pull request build: $PULL_REQUEST"
133+ else
134+ echo "Couldn't identify this as an internal or external pull request"
135+ exit 1
136+ fi
137+
138+ ./gradlew collectDelegatedArtifactSizeMetrics -PpullRequest=$PULL_REQUEST
139+ - name : Analyze Artifact Size Metrics
140+ run : ./gradlew analyzeArtifactSizeMetrics
141+ - name : Show Results
142+ uses : actions/github-script@v7
143+ with :
144+ script : |
145+ const getComments =
146+ `query {
147+ repository(owner:"${context.repo.owner}", name:"${context.repo.repo}"){
148+ pullRequest(number: ${context.issue.number}) {
149+ id
150+ comments(last:100) {
151+ nodes {
152+ id
153+ body
154+ author {
155+ login
156+ }
157+ isMinimized
158+ }
159+ }
160+ }
161+ }
162+ }`
163+
164+ const response = await github.graphql(getComments)
165+ const comments = response.repository.pullRequest.comments.nodes
166+
167+ const mutations = comments
168+ .filter(comment => comment.author.login == 'github-actions' && !comment.isMinimized && comment.body.startsWith('Affected Artifacts'))
169+ .map(comment =>
170+ github.graphql(
171+ `mutation {
172+ minimizeComment(input:{subjectId:"${comment.id}", classifier:OUTDATED}){
173+ clientMutationId
174+ }
175+ }`
176+ )
177+ )
178+ await Promise.all(mutations)
179+
180+ const fs = require('node:fs')
181+ const comment = fs.readFileSync('build/reports/metrics/artifact-analysis.md', 'utf8')
182+
183+ const writeComment =
184+ `mutation {
185+ addComment(input:{body:"""${comment}""", subjectId:"${response.repository.pullRequest.id}"}){
186+ clientMutationId
187+ }
188+ }`
189+
190+ await github.graphql(writeComment)
191+
192+ - name : Evaluate Result
193+ if : ${{ !contains(github.event.pull_request.labels.*.name, 'acknowledge-artifact-size-increase') }}
194+ run : |
195+ cd build/reports/metrics
196+ cat has-significant-change.txt | grep false || {
197+ echo An artifact increased in size by more than allowed or a new artifact was created.
198+ echo If this is expected please add the 'acknowledge-artifact-size-increase' label to this pull request.
199+ exit 1
200+ }
201+
202+ release-artifact-size-metrics :
203+ if : github.event_name == 'release'
204+ runs-on : ubuntu-latest
205+ steps :
206+ - name : Checkout sources
207+ uses : actions/checkout@v2
208+ - name : Configure AWS Credentials
209+ uses : aws-actions/configure-aws-credentials@v4
210+ with :
211+ role-to-assume : ${{ secrets.CI_AWS_ROLE_ARN }}
212+ aws-region : us-west-2
213+ - name : Calculate Artifact Size Metrics
82214 id : svc-check-batch
83215 run : |
216+ REPOSITORY=$(echo ${{ github.repository }} | cut -d '/' -f 2)
217+
84218 .github/scripts/run-codebuild-batch-job.sh \
85219 --project gh-aws-sdk-kotlin-svc-check-batch \
86220 --source ${{ github.event.pull_request.head.sha }} \
87- --sdk-pr ${{ inputs.aws-sdk-kotlin-pr }} \
88- --smithy-pr ${{ inputs.smithy-kotlin-pr }}
221+ --repository $REPOSITORY \
222+ --release ${{ github.event.release.tag_name }}
89223 - name : Cancel build
90224 if : ${{ cancelled() }}
91225 env :
95229 echo "cancelling in-progress batch build: id=$BUILD_ID"
96230 aws codebuild stop-build --id $BUILD_ID
97231 fi
232+ - name : Collect Artifact Size Metrics
233+ run : ./gradlew collectDelegatedArtifactSizeMetrics -Prelease=${{ github.event.release.tag_name }}
234+ - name : Save Artifact Size Metrics
235+ run : ./gradlew saveArtifactSizeMetrics
236+ - name : Put Artifact Size Metrics in CloudWatch
237+ run : ./gradlew putArtifactSizeMetricsInCloudWatch -Prelease=${{ github.event.release.tag_name }}
0 commit comments