Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: introduce pragma:context to cdk-integ #15779

Merged
merged 2 commits into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@aws-cdk/pipelines/test/integ.newpipeline.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// eslint-disable-next-line import/no-extraneous-dependencies
/// !cdk-integ PipelineStack
/// !cdk-integ PipelineStack pragma:set-context:@aws-cdk/core:newStyleStackSynthesis=true
import * as sqs from '@aws-cdk/aws-sqs';
import { App, Stack, StackProps, Stage, StageProps } from '@aws-cdk/core';
import { Construct } from 'constructs';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// !cdk-integ PipelineSecurityStack
/// !cdk-integ PipelineSecurityStack pragma:set-context:@aws-cdk/core:newStyleStackSynthesis=true
import * as codepipeline from '@aws-cdk/aws-codepipeline';
import * as codepipeline_actions from '@aws-cdk/aws-codepipeline-actions';
import * as iam from '@aws-cdk/aws-iam';
Expand Down
16 changes: 15 additions & 1 deletion tools/cdk-integ-tools/lib/integ-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const CDK_OUTDIR = 'cdk-integ.out';

const CDK_INTEG_STACK_PRAGMA = '/// !cdk-integ';
const PRAGMA_PREFIX = 'pragma:';
const SET_CONTEXT_PRAGMA_PREFIX = 'pragma:set-context:';

export class IntegrationTests {
constructor(private readonly directory: string) {
Expand Down Expand Up @@ -95,10 +96,23 @@ export class IntegrationTest {
* Return the "main" template or a concatenation of all listed templates in the pragma
*/
public async cdkSynthFast(options: SynthOptions = {}): Promise<any> {
const context = {
const context: Record<string, string> = {
...options.context,
};

// apply context from set-context pragma
// usage: pragma:set-context:key=value
const ctxPragmas = (await this.pragmas()).filter(p => p.startsWith(SET_CONTEXT_PRAGMA_PREFIX));
for (const p of ctxPragmas) {
const instruction = p.substring(SET_CONTEXT_PRAGMA_PREFIX.length);
const [key, value] = instruction.split('=');
if (key == null || value == null) {
throw new Error(`invalid "set-context" pragma syntax. example: "pragma:set-context:@aws-cdk/core:newStyleStackSynthesis=true" got: ${p}`);
}

context[key] = value;
}

try {
await exec(['node', `${this.name}`], {
cwd: this.directory,
Expand Down