Skip to content

Commit 9d80cfc

Browse files
rix0rrrgithub-actions
and
github-actions
authored
chore: record publishing timestamps in SSM (#104)
Write publishing timestamps to SSM so that we can more effectively alarm on problems caused by releases. --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license --------- Signed-off-by: github-actions <[email protected]> Co-authored-by: github-actions <[email protected]>
1 parent a18f005 commit 9d80cfc

File tree

5 files changed

+115
-0
lines changed

5 files changed

+115
-0
lines changed

.github/workflows/release.yml

+39
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projen/tasks.json

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projenrc.ts

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { BundleCli } from './projenrc/bundle';
77
import { CodeCovWorkflow } from './projenrc/codecov';
88
import { ESLINT_RULES } from './projenrc/eslint';
99
import { JsiiBuild } from './projenrc/jsii';
10+
import { RecordPublishingTimestamp } from './projenrc/record-publishing-timestamp';
1011

1112
// 5.7 sometimes gives a weird error in `ts-jest` in `@aws-cdk/cli-lib-alpha`
1213
// https://github.com/microsoft/TypeScript/issues/60159
@@ -224,6 +225,9 @@ const repoProject = new yarn.Monorepo({
224225
},
225226
});
226227

228+
new AdcPublishing(repoProject);
229+
new RecordPublishingTimestamp(repoProject);
230+
227231
// Eslint for projen config
228232
// @ts-ignore
229233
repoProject.eslint = new pj.javascript.Eslint(repoProject, {

projenrc/adc-publishing.ts

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export class AdcPublishing extends Component {
6060
'role-to-assume': '${{ vars.AWS_ROLE_TO_ASSUME_FOR_ACCOUNT }}',
6161
'role-session-name': 'releasing@aws-cdk-cli',
6262
'output-credentials': true,
63+
'mask-aws-account-id': true,
6364
},
6465
},
6566
{
+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { Monorepo } from 'cdklabs-projen-project-types/lib/yarn';
2+
import { Component } from 'projen';
3+
import { JobPermission } from 'projen/lib/github/workflows-model';
4+
5+
/**
6+
* Record publishing timestamp to SSM
7+
*/
8+
export class RecordPublishingTimestamp extends Component {
9+
constructor(private readonly project_: Monorepo) {
10+
super(project_);
11+
}
12+
13+
public preSynthesize() {
14+
const ssmPrefix = '/published/cdk/cli';
15+
16+
const releaseWf = this.project_.github?.tryFindWorkflow('release');
17+
if (!releaseWf) {
18+
throw new Error('Could not find release workflow');
19+
}
20+
21+
releaseWf.addJob('record_timestamp', {
22+
name: 'aws-cdk: Record publishing timestamp',
23+
environment: 'releasing', // <-- this has the configuration
24+
needs: ['release'],
25+
runsOn: ['ubuntu-latest'],
26+
permissions: {
27+
contents: JobPermission.WRITE,
28+
},
29+
if: '${{ needs.release.outputs.latest_commit == github.sha }}',
30+
steps: [
31+
{
32+
name: 'Download build artifacts',
33+
uses: 'actions/download-artifact@v4',
34+
with: {
35+
name: 'aws-cdk_build-artifact',
36+
path: 'dist',
37+
},
38+
},
39+
{
40+
name: 'Read version from build artifacts',
41+
id: 'aws-cdk-version',
42+
run: 'echo "version=$(cat dist/version.txt)" >> $GITHUB_OUTPUT',
43+
},
44+
{
45+
name: 'Authenticate Via OIDC Role',
46+
id: 'creds',
47+
uses: 'aws-actions/configure-aws-credentials@v4',
48+
with: {
49+
'aws-region': 'us-east-1',
50+
'role-duration-seconds': 14400,
51+
'role-to-assume': '${{ vars.AWS_ROLE_TO_ASSUME_FOR_ACCOUNT }}',
52+
'role-session-name': 'releasing@aws-cdk-cli',
53+
'output-credentials': true,
54+
'mask-aws-account-id': true,
55+
},
56+
},
57+
{
58+
name: 'Publish artifacts',
59+
run: [
60+
`aws ssm put-parameter --name "${ssmPrefix}/version" --type "String" --value "\${{ steps.aws-cdk-version.outputs.version }}" --overwrite`,
61+
`aws ssm put-parameter --name "${ssmPrefix}/timestamp" --type "String" --value "$(date +%s)" --overwrite`,
62+
].join('\n'),
63+
},
64+
],
65+
});
66+
}
67+
}
68+

0 commit comments

Comments
 (0)