Skip to content

Commit

Permalink
fix: scope asset publishing scripts inside stage assembly directory (#…
Browse files Browse the repository at this point in the history
…397)

Inspired by #280. Added tests.

Fixes #279
  • Loading branch information
NathanTCz authored Feb 12, 2024
1 parent d0e1c52 commit 9c6934a
Show file tree
Hide file tree
Showing 5 changed files with 178 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ export class GitHubWorkflow extends PipelineBase {
const installSuffix = this.cdkCliVersion ? `@${this.cdkCliVersion}` : '';
const cdkoutDir = options.assemblyDir;
const jobId = node.uniqueId;
const assetId = assets[0].assetId;
const { assetId, assetManifestPath } = assets[0];
const preBuildSteps: github.JobStep[] = [];
let permissions: github.JobPermissions = {
contents: github.JobPermission.READ,
Expand Down Expand Up @@ -554,7 +554,7 @@ export class GitHubWorkflow extends PipelineBase {
this.assetHashMap[assetId] = jobId;
fileContents.push(`echo '${ASSET_HASH_NAME}=${assetId}' >> $GITHUB_OUTPUT`);

const publishStepFile = path.join(cdkoutDir, `publish-${jobId}-step.sh`);
const publishStepFile = path.join(path.dirname(relativeToAssembly(assetManifestPath)), `publish-${jobId}-step.sh`);
mkdirSync(path.dirname(publishStepFile), { recursive: true });
writeFileSync(publishStepFile, fileContents.join('\n'), { encoding: 'utf-8' });

Expand Down
149 changes: 134 additions & 15 deletions test/__snapshots__/github.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/__snapshots__/runner-provided.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions test/__snapshots__/stage-options.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions test/github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,38 @@ test('pipeline with publish asset region override', () => {
});
});

test('pipeline publish asset scripts are in stage assembly directory', () => {
withTemporaryDirectory((dir) => {
const pipeline = new GitHubWorkflow(app, 'Pipeline', {
workflowPath: `${dir}/.github/workflows/deploy.yml`,
synth: new ShellStep('Build', {
commands: [],
}),
publishAssetsAuthRegion: 'ap-southeast-2',
});

const stage = new Stage(app, 'MyStage', {
env: { account: '111111111111', region: 'us-east-1' },
});

const stack = new Stack(stage, 'MyStack');

new lambda.Function(stack, 'Function', {
code: lambda.Code.fromAsset(fixtures),
handler: 'index.handler',
runtime: lambda.Runtime.NODEJS_14_X,
});

pipeline.addStage(stage);

app.synth();

const file = readFileSync(pipeline.workflowPath, 'utf-8');
expect(file).toContain('./cdk.out/assembly-MyStage/publish-Assets');
expect(file).toMatchSnapshot();
});
});

test('pipeline with job settings', () => {
withTemporaryDirectory((dir) => {
const pipeline = new GitHubWorkflow(app, 'Pipeline', {
Expand Down

0 comments on commit 9c6934a

Please sign in to comment.