diff --git a/packages/@aws-cdk/cfnspec/build-tools/build.ts b/packages/@aws-cdk/cfnspec/build-tools/build.ts index 5409134256ffb..094f2f5f13c1d 100644 --- a/packages/@aws-cdk/cfnspec/build-tools/build.ts +++ b/packages/@aws-cdk/cfnspec/build-tools/build.ts @@ -19,7 +19,7 @@ async function main() { // If this is a PR build check the spec for evolution (this is set in buildspec-pr.yaml) const outputFile = path.join(outDir, 'specification.json'); - if (process.env.PR_BUILD) { + if (process.env.CODEBUILD_WEBHOOK_TRIGGER?.startsWith('pr/')) { await validateSpecificationEvolution(async () => { await generateResourceSpecification(inputDir, outputFile); return fs.readJson(outputFile); diff --git a/packages/@aws-cdk/cfnspec/build-tools/massage-spec.ts b/packages/@aws-cdk/cfnspec/build-tools/massage-spec.ts index fc7aee9466e2e..9be37cef28b80 100644 --- a/packages/@aws-cdk/cfnspec/build-tools/massage-spec.ts +++ b/packages/@aws-cdk/cfnspec/build-tools/massage-spec.ts @@ -17,6 +17,13 @@ export function massageSpec(spec: schema.Specification) { */ function replaceIncompleteTypes(spec: schema.Specification) { for (const [name, definition] of Object.entries(spec.PropertyTypes)) { + if (!definition) { + // eslint-disable-next-line no-console + console.log(`[${name}] **ERROR** Nullish type definition: a patch probably copied a nonexistent value!`); + process.exitCode = 1; + continue; + } + if (!schema.isRecordType(definition) && !schema.isCollectionProperty(definition) && !schema.isScalarProperty(definition) diff --git a/packages/@aws-cdk/cfnspec/build-tools/validate-evolution.ts b/packages/@aws-cdk/cfnspec/build-tools/validate-evolution.ts index 40296e225bd55..dd0cb2f21c8db 100644 --- a/packages/@aws-cdk/cfnspec/build-tools/validate-evolution.ts +++ b/packages/@aws-cdk/cfnspec/build-tools/validate-evolution.ts @@ -1,5 +1,8 @@ /* eslint-disable no-console */ import * as child_process from 'child_process'; +import * as fs from 'fs-extra'; + +const SKIP_FILE = 'skip-evolution-check.txt'; /** * Run validations on the spec evolution, on the pull request. @@ -10,11 +13,24 @@ import * as child_process from 'child_process'; * Expects and uses git. */ export async function validateSpecificationEvolution(specProducer: () => Promise) { + const prNumber = (process.env.CODEBUILD_WEBHOOK_TRIGGER ?? '').replace(/^pr\//, ''); + const skips = (await fs.readFile(SKIP_FILE, { encoding: 'utf-8' })).split('\n'); + if (prNumber && skips.includes(prNumber)) { + console.log(`Skipping evo check of PR ${prNumber} (${SKIP_FILE})`); + await specProducer(); + return; + } + const targetBranch = process.env.CODEBUILD_WEBHOOK_BASE_REF ?? 'main'; console.log(`Comparing differences with ${targetBranch}`); const mergeBase = child_process.execSync(`git merge-base ${targetBranch} HEAD`).toString().trim(); console.log(`Base commit ${mergeBase}`); - const currentCommit = child_process.execSync('git rev-parse --abbrev-ref HEAD').toString().trim(); + // Find branch name if we have one + let currentCommit = child_process.execSync('git rev-parse --abbrev-ref HEAD').toString().trim(); + if (currentCommit === 'HEAD') { + // No branch, just spec use commit + currentCommit = child_process.execSync('git rev-parse HEAD').toString().trim(); + } console.log(`Current commit ${currentCommit}`); const specs = new Array(); diff --git a/packages/@aws-cdk/cfnspec/skip-evolution-check.txt b/packages/@aws-cdk/cfnspec/skip-evolution-check.txt new file mode 100644 index 0000000000000..725fe7f1f113e --- /dev/null +++ b/packages/@aws-cdk/cfnspec/skip-evolution-check.txt @@ -0,0 +1,2 @@ +# to fully skip spec evolution checks, put the PR number in this file. +25326 \ No newline at end of file diff --git a/packages/@aws-cdk/cfnspec/spec-source/specification/000_cfn/911_Batch_JobDefinition_patch.json b/packages/@aws-cdk/cfnspec/spec-source/specification/000_cfn/911_Batch_JobDefinition_patch.json deleted file mode 100644 index 90416d9a6c2e0..0000000000000 --- a/packages/@aws-cdk/cfnspec/spec-source/specification/000_cfn/911_Batch_JobDefinition_patch.json +++ /dev/null @@ -1,49 +0,0 @@ -{ - "PropertyTypes": { - "patch": { - "description": "Undoing upstream property type renames of Batch.", - "operations": [ - { - "op": "move", - "from": "/AWS::Batch::JobDefinition.EksEmptyDir", - "path": "/AWS::Batch::JobDefinition.EmptyDir" - }, - { - "op": "replace", - "path": "/AWS::Batch::JobDefinition.EksVolume/Properties/EmptyDir/Type", - "value": "EmptyDir" - }, - { - "op": "move", - "from": "/AWS::Batch::JobDefinition.EksHostPath", - "path": "/AWS::Batch::JobDefinition.HostPath" - }, - { - "op": "replace", - "path": "/AWS::Batch::JobDefinition.EksVolume/Properties/HostPath/Type", - "value": "HostPath" - }, - { - "op": "move", - "from": "/AWS::Batch::JobDefinition.EksContainerResourceRequirements", - "path": "/AWS::Batch::JobDefinition.Resources" - }, - { - "op": "replace", - "path": "/AWS::Batch::JobDefinition.EksContainer/Properties/Resources/Type", - "value": "Resources" - }, - { - "op": "move", - "from": "/AWS::Batch::JobDefinition.EksContainerSecurityContext", - "path": "/AWS::Batch::JobDefinition.SecurityContext" - }, - { - "op": "replace", - "path": "/AWS::Batch::JobDefinition.EksContainer/Properties/SecurityContext/Type", - "value": "SecurityContext" - } - ] - } - } -}