Skip to content

Commit

Permalink
Merge branch 'main' into update-contributing-guide
Browse files Browse the repository at this point in the history
  • Loading branch information
pahud authored Apr 27, 2023
2 parents 8d2455b + 5a02d81 commit 0c7c630
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 51 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/cfnspec/build-tools/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions packages/@aws-cdk/cfnspec/build-tools/massage-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 17 additions & 1 deletion packages/@aws-cdk/cfnspec/build-tools/validate-evolution.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -10,11 +13,24 @@ import * as child_process from 'child_process';
* Expects and uses git.
*/
export async function validateSpecificationEvolution(specProducer: () => Promise<any>) {
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<any>();
Expand Down
2 changes: 2 additions & 0 deletions packages/@aws-cdk/cfnspec/skip-evolution-check.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# to fully skip spec evolution checks, put the PR number in this file.
25326

This file was deleted.

0 comments on commit 0c7c630

Please sign in to comment.