From bd1191a5c2b85dce9d0f71381e9aaf539c15c750 Mon Sep 17 00:00:00 2001 From: Momo Kornher Date: Tue, 31 Jan 2023 11:58:30 +0000 Subject: [PATCH] chore(cfnspec): support us-west-2 only services --- .../@aws-cdk/cfnspec/build-tools/spec-diff.ts | 9 +++++++++ .../build-tools/split-spec-by-service.ts | 19 +++++++++++++++---- .../@aws-cdk/cfnspec/build-tools/update.sh | 11 ++++++++++- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/packages/@aws-cdk/cfnspec/build-tools/spec-diff.ts b/packages/@aws-cdk/cfnspec/build-tools/spec-diff.ts index 465637b789522..b39f50aa17fdb 100644 --- a/packages/@aws-cdk/cfnspec/build-tools/spec-diff.ts +++ b/packages/@aws-cdk/cfnspec/build-tools/spec-diff.ts @@ -18,6 +18,15 @@ async function main() { const newSpec = await fs.readJSON(newSpecFile); const oldSpec = await fs.readJSON(oldSpecFile); + // Diff operates on PropertyTypes & ResourceTypes + // Ensure they always exist in the old spec + if (!oldSpec.PropertyTypes) { + oldSpec.PropertyTypes = {}; + } + if (!oldSpec.ResourceTypes) { + oldSpec.ResourceTypes = {}; + } + const out = jsonDiff(oldSpec, newSpec); // Here's the magic output format of this thing diff --git a/packages/@aws-cdk/cfnspec/build-tools/split-spec-by-service.ts b/packages/@aws-cdk/cfnspec/build-tools/split-spec-by-service.ts index d563350e21d8b..08a86c8e9f58c 100644 --- a/packages/@aws-cdk/cfnspec/build-tools/split-spec-by-service.ts +++ b/packages/@aws-cdk/cfnspec/build-tools/split-spec-by-service.ts @@ -18,11 +18,13 @@ import { writeSorted } from './patch-set'; import { CfnSpec, CfnSpecValidator, formatErrorInContext } from './validate-cfn'; async function main(args: string[]) { - if (args.length < 2) { - throw new Error('Usage: split-spec-by-service '); + if (args.length < 3) { + throw new Error('Usage: split-spec-by-service []'); } - const [specFile, outDir] = args; + const [specFile, outDir, services] = args; + const allowedServices = services.trim().split(' ').filter(Boolean); + log(`Loading specification: ${specFile}`); const spec: CfnSpec = await fs.readJson(specFile); @@ -39,8 +41,17 @@ async function main(args: string[]) { } // Write out - log('Writing'); + if (allowedServices.length > 0) { + log(`Writing: ${allowedServices.join(' ')}`); + } else { + log('Writing all services'); + } for (const [svcName, svcSpec] of Object.entries(byService)) { + // Skip services that are not explicitly allowed + if (allowedServices.length > 0 && !allowedServices.includes(svcName)) { + continue; + } + const successTarget = path.join(outDir, `000_${svcName}.json`); const rejectedTarget = path.join(outDir, `.000_${svcName}.rejected.json`); diff --git a/packages/@aws-cdk/cfnspec/build-tools/update.sh b/packages/@aws-cdk/cfnspec/build-tools/update.sh index 5a1aefd55bbb3..7b3c73eac2d3d 100755 --- a/packages/@aws-cdk/cfnspec/build-tools/update.sh +++ b/packages/@aws-cdk/cfnspec/build-tools/update.sh @@ -16,6 +16,7 @@ function update-spec() { local targetdir=$3 local gunzip=$4 local split=$5 + local services=${@:6} local tmpdir="$(mktemp -d)" local newspec="${tmpdir}/new_proposed.json" @@ -42,10 +43,11 @@ function update-spec() { # Calculate the old and new combined specs, so we can do a diff on the changes echo >&2 "Updating source spec..." + mkdir -p ${targetdir} node build-tools/patch-set.js --quiet "${targetdir}" "${oldcombined}" if ${split}; then - node build-tools/split-spec-by-service.js "${newspec}" "${targetdir}" + node build-tools/split-spec-by-service.js "${newspec}" "${targetdir}" "${services}" else cp "${newspec}" "${targetdir}/spec.json" sort-json "${targetdir}/spec.json" @@ -66,6 +68,12 @@ update-spec \ spec-source/specification/000_cfn/000_official \ true true +update-spec \ + "CloudFormation Resource Specification (us-west-2)" \ + "${2:-https://d201a2mn26r7lk.cloudfront.net/latest/gzip/CloudFormationResourceSpecification.json}" \ + spec-source/specification/001_cfn_us-west-2/000_official \ + true true AWS_DeviceFarm + old_version=$(cat cfn.version) new_version=$(node -p "require('${scriptdir}/../spec-source/specification/000_cfn/000_official/001_Version.json').ResourceSpecificationVersion") echo >&2 "Recording new version..." @@ -76,6 +84,7 @@ echo "$new_version" > cfn.version if [[ "$new_version" != "$old_version" ]]; then echo >&2 "Reporting outdated specs..." node build-tools/report-issues spec-source/specification/000_cfn/000_official/ outdated >> CHANGELOG.md.new + node build-tools/report-issues spec-source/specification/001_cfn_us-west-2/000_official/ outdated >> CHANGELOG.md.new fi update-spec \