Skip to content

Commit 51df059

Browse files
authored
chore: add ADC publishing workflow (#94)
The configuration lives in the 'releasing' environment, and the bucket names are masked away from the logs. --- By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
1 parent 7517ecc commit 51df059

File tree

6 files changed

+140
-15
lines changed

6 files changed

+140
-15
lines changed

.github/workflows/release.yml

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projen/tasks.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projenrc.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { BundleCli } from './projenrc/bundle';
55
import { ESLINT_RULES } from './projenrc/eslint';
66
import { JsiiBuild } from './projenrc/jsii';
77
import { CodeCovWorkflow } from './projenrc/codecov';
8+
import { AdcPublishing } from './projenrc/adc-publishing';
89

910
// 5.7 sometimes gives a weird error in `ts-jest` in `@aws-cdk/cli-lib-alpha`
1011
// https://github.com/microsoft/TypeScript/issues/60159
@@ -215,6 +216,8 @@ const repoProject = new yarn.Monorepo({
215216
},
216217
});
217218

219+
new AdcPublishing(repoProject);
220+
218221
// Eslint for projen config
219222
// @ts-ignore
220223
repoProject.eslint = new pj.javascript.Eslint(repoProject, {

projenrc/adc-publishing.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { Monorepo } from "cdklabs-projen-project-types/lib/yarn";
2+
import { Component, github } from "projen";
3+
import { JobPermission } from "projen/lib/github/workflows-model";
4+
5+
export class AdcPublishing extends Component {
6+
constructor(private readonly project_: Monorepo) {
7+
super(project_);
8+
9+
this.project.tasks.tryFind('build')?.exec('tsx projenrc/build-standalone-zip.task.ts');
10+
}
11+
12+
public preSynthesize() {
13+
const releaseWf = this.project_.github?.tryFindWorkflow('release');
14+
if (!releaseWf) {
15+
throw new Error('Could not find release workflow');
16+
}
17+
18+
(releaseWf.getJob('release') as github.workflows.Job).steps.push({
19+
name: 'standalone: Upload artifact',
20+
if: '${{ steps.git_remote.outputs.latest_commit == github.sha }}',
21+
uses: 'actions/[email protected]',
22+
with: {
23+
name: 'standalone_build-artifact',
24+
path: 'dist/standalone',
25+
overwrite: true
26+
},
27+
});
28+
29+
releaseWf.addJob('standalone_release_adc', {
30+
name: 'standalone: publish to ADC',
31+
environment: 'releasing', // <-- this has the configuration
32+
needs: ['release'],
33+
runsOn: ['ubuntu-latest'],
34+
permissions: {
35+
contents: JobPermission.WRITE,
36+
},
37+
if: `\${{ needs.release.outputs.latest_commit == github.sha }}`,
38+
steps: [
39+
{
40+
uses: 'actions/setup-node@v4',
41+
with: {
42+
'node-version': 'lts/*',
43+
},
44+
},
45+
{
46+
name: 'Download build artifacts',
47+
uses: 'actions/download-artifact@v4',
48+
with: {
49+
name: 'standalone_build-artifact',
50+
path: 'dist/standalone',
51+
},
52+
},
53+
{
54+
name: 'Authenticate Via OIDC Role',
55+
id: 'creds',
56+
uses: 'aws-actions/configure-aws-credentials@v4',
57+
with: {
58+
'aws-region': 'us-east-1',
59+
'role-duration-seconds': 14400,
60+
'role-to-assume': '${{ vars.AWS_ROLE_TO_ASSUME_FOR_ACCOUNT }}',
61+
'role-session-name': 'releasing@aws-cdk-cli',
62+
'output-credentials': true,
63+
},
64+
},
65+
{
66+
name: 'Publish artifacts',
67+
env: {
68+
PUBLISHING_ROLE_ARN: '${{ vars.PUBLISHING_ROLE_ARN }}',
69+
TARGET_BUCKETS: '${{ vars.TARGET_BUCKETS }}',
70+
},
71+
run: 'npx tsx projenrc/publish-to-adc.task.ts',
72+
},
73+
],
74+
});
75+
}
76+
}

projenrc/build-standalone-zip.task.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ import * as cp from 'child_process';
22
import { promises as fs } from 'fs';
33
import * as os from 'os';
44
import * as path from 'path';
5-
import * as util from 'util';
6-
import * as glob_ from 'glob';
7-
8-
const glob = util.promisify(glob_.glob);
5+
import { glob } from 'glob';
96

107
async function main() {
118
const outdir = await fs.mkdtemp(path.join(os.tmpdir(), 'bundling'));
129
try {
10+
1311
const pkgs = ['aws-cdk'];
1412
// this is a build task, so we are safe either way
1513
// eslint-disable-next-line @cdklabs/promiseall-no-unbounded-parallelism

projenrc/publish-to-adc.task.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createReadStream } from 'fs';
22
import { S3 } from '@aws-sdk/client-s3';
33
import { fromTemporaryCredentials, fromNodeProviderChain } from '@aws-sdk/credential-providers';
44
import { Upload } from '@aws-sdk/lib-storage';
5+
import { glob } from 'glob';
56

67
/**
78
* Takes files from `dist/standalone` and moves them to specific ADC buckets
@@ -16,6 +17,10 @@ async function main() {
1617
if (!TARGET_BUCKETS) {
1718
throw new Error('Require $TARGET_BUCKETS');
1819
}
20+
const buckets = TARGET_BUCKETS.split(/\s+|,+/).filter(x => x);
21+
22+
const root = 'dist/standalone';
23+
const filesToPublish = ['aws-cdk-cli.zip'];
1924

2025
const credentials = fromTemporaryCredentials({
2126
masterCredentials: fromNodeProviderChain(),
@@ -30,22 +35,24 @@ async function main() {
3035

3136
const s3 = new S3({ region: 'us-east-1', credentials });
3237

33-
for (const bucket of TARGET_BUCKETS.split(' ')) {
38+
for (const bucket of buckets) {
3439
// This value is secret-ish, mask it out
3540
// this is a cli
3641
// eslint-disable-next-line no-console
3742
console.log(`::add-mask::${bucket}`);
3843

39-
const upload = new Upload({
40-
client: s3,
41-
params: {
42-
Bucket: bucket,
43-
Key: 'aws-cdk-v2/aws-cdk-cli.zip',
44-
Body: createReadStream('dist/standalone/aws-cdk-cli.zip'),
45-
ChecksumAlgorithm: 'SHA256',
46-
},
47-
});
48-
await upload.done();
44+
for (const file of filesToPublish) {
45+
const upload = new Upload({
46+
client: s3,
47+
params: {
48+
Bucket: bucket,
49+
Key: `aws-cdk-v2/${file}`,
50+
Body: createReadStream(`${root}/${file}`),
51+
ChecksumAlgorithm: 'SHA256',
52+
},
53+
});
54+
await upload.done();
55+
}
4956
}
5057
}
5158

0 commit comments

Comments
 (0)