|
| 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