-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update workflows for release and version bump (#8)
What's Changed: 1. Running `yarn build` will now automatically update the schema if any changes have been made that will impact it. Not all changes will. This is accomplished by adding the existing command `yarn update-schema` into the `pre-compile` step that is run within `yarn build`. It is also run in the `release` step to check for any unintentional changes and will fail the release if uncommitted changes are found (one intentional exception is listed below). 3. A new function `bump()` will check for any updates to the schema (generated by `pre-compile`). If there are any, it will update the minimum major version to release by a full major version based off the latest tag in the repository. If there are no changes to the schema, no updates will be made. This is accomplished by setting `bump()` as the value for `minMajorVersion`. If there are no changes to the schema, this field will remain undefined but if there are, it will increment the version. This change will not be committed and will be removed once the release has completed, similarly to how `unbump` works in `projen` 4. A new command `yarn pre-release` runs `update-schema` and `default`. Running `default` after `update-schema` accomplishes all of the above and re-synthesizes the `tasks.json` file with the new major version so that the `release` command will run on the updated task definition. Any uncommitted changes other than the `minMajorVersion` update will cause the `release` command to fail.
- Loading branch information
1 parent
1461a06
commit 39892ad
Showing
16 changed files
with
221 additions
and
134 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as semver from 'semver'; | ||
import { schemasChanged } from './update-schema'; | ||
import { exec, log } from './util'; | ||
|
||
export function bump() { | ||
try { | ||
const tags = exec([ | ||
'git', | ||
'ls-remote', | ||
'--tags', | ||
'[email protected]:cdklabs/cloud-assembly-schema.git', | ||
]); | ||
|
||
const oldVersion = tags.split('/v').pop()!.slice(0, -3); | ||
const newVersion = schemasChanged() ? semver.inc(oldVersion, 'major')! : oldVersion; | ||
|
||
if (newVersion !== oldVersion) { | ||
log(`Updating schema version: ${oldVersion} -> ${newVersion}`); | ||
return parseInt(newVersion); | ||
} | ||
return undefined; | ||
} catch (e) { | ||
/** | ||
* If git cannot be reached, returning undefined is fine. This will never happen | ||
* in the release workflow and may very well happen in any given build. | ||
*/ | ||
return undefined; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './update'; | ||
export * from './bump'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import * as path from 'path'; | ||
import { generatedPath, sourcePath } from './util'; | ||
|
||
export type SchemaDefinition = { | ||
/** | ||
* The name of the root type. | ||
*/ | ||
rootTypeName: string; | ||
/** | ||
* Files loaded to generate the schema. | ||
* Should be relative to `cloud-assembly-schema/lib`. | ||
* Usually this is just the file containing the root type. | ||
*/ | ||
sourceFile: string; | ||
/** | ||
* The location of the generated schema. | ||
*/ | ||
generatedFile: string; | ||
}; | ||
|
||
/** | ||
* Where schemas are committed. | ||
*/ | ||
export const SCHEMA_DIR = path.resolve(__dirname, '../schema'); | ||
|
||
const SCHEMA_DEFINITIONS: { [schemaName: string]: SchemaDefinition } = { | ||
assets: { | ||
rootTypeName: 'AssetManifest', | ||
sourceFile: sourcePath('assets'), | ||
generatedFile: generatedPath('assets'), | ||
}, | ||
'cloud-assembly': { | ||
rootTypeName: 'AssemblyManifest', | ||
sourceFile: sourcePath('cloud-assembly'), | ||
generatedFile: generatedPath('cloud-assembly'), | ||
}, | ||
integ: { | ||
rootTypeName: 'IntegManifest', | ||
sourceFile: sourcePath('integ-tests'), | ||
generatedFile: generatedPath('integ'), | ||
}, | ||
}; | ||
|
||
export const SCHEMAS: string[] = Object.keys(SCHEMA_DEFINITIONS); | ||
|
||
export function getSchemaDefinition(key: string): SchemaDefinition { | ||
return SCHEMA_DEFINITIONS[key]; | ||
} | ||
|
||
export function getGeneratedSchemaPaths(): string[] { | ||
return Object.values(SCHEMA_DEFINITIONS).map((s) => s.generatedFile); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,31 @@ | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import * as semver from 'semver'; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import * as tjs from 'typescript-json-schema'; | ||
|
||
function log(message: string) { | ||
// eslint-disable-next-line no-console | ||
console.log(message); | ||
} | ||
|
||
/** | ||
* Where schemas are committed. | ||
*/ | ||
const SCHEMA_DIR = path.resolve(__dirname, '../schema'); | ||
|
||
const SCHEMA_DEFINITIONS: { | ||
[schemaName: string]: { | ||
/** | ||
* The name of the root type. | ||
*/ | ||
rootTypeName: string; | ||
/** | ||
* Files loaded to generate the schema. | ||
* Should be relative to `cloud-assembly-schema/lib`. | ||
* Usually this is just the file containing the root type. | ||
*/ | ||
files: string[]; | ||
}; | ||
} = { | ||
assets: { | ||
rootTypeName: 'AssetManifest', | ||
files: [path.join('assets', 'schema.ts')], | ||
}, | ||
'cloud-assembly': { | ||
rootTypeName: 'AssemblyManifest', | ||
files: [path.join('cloud-assembly', 'schema.ts')], | ||
}, | ||
integ: { | ||
rootTypeName: 'IntegManifest', | ||
files: [path.join('integ-tests', 'schema.ts')], | ||
}, | ||
}; | ||
|
||
export const SCHEMAS = Object.keys(SCHEMA_DEFINITIONS); | ||
|
||
export function update() { | ||
for (const s of SCHEMAS) { | ||
generateSchema(s); | ||
} | ||
|
||
bump(); | ||
} | ||
import { SCHEMA_DIR, getGeneratedSchemaPaths, getSchemaDefinition } from './schema-definition'; | ||
import { exec, log } from './util'; | ||
|
||
export function bump() { | ||
const versionFile = path.join(SCHEMA_DIR, 'cloud-assembly.version.json'); | ||
const tags = exec([ | ||
'git', | ||
'ls-remote', | ||
'--tags', | ||
'[email protected]:cdklabs/cloud-assembly-schema.git', | ||
]); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-require-imports | ||
const metadata = require(versionFile); | ||
const oldVersion = tags.split('/v').pop()!.slice(0, -3); | ||
|
||
const oldVersion = metadata.version; | ||
const newVersion = semver.inc(oldVersion, 'major'); | ||
const newVersion = schemasChanged() ? semver.inc(oldVersion, 'major')! : oldVersion; | ||
const versionFile = path.join(SCHEMA_DIR, 'cloud-assembly.version.json'); | ||
|
||
log(`Updating schema version: ${oldVersion} -> ${newVersion}`); | ||
fs.writeFileSync(versionFile, JSON.stringify({ version: newVersion })); | ||
return parseInt(newVersion); | ||
} | ||
|
||
export function schemasChanged(): boolean { | ||
const changes = exec(['git', 'diff', '--name-only', 'origin/main']).split('\n'); | ||
return changes.filter((change) => getGeneratedSchemaPaths().includes(change)).length > 0; | ||
} | ||
|
||
/** | ||
|
@@ -72,7 +35,7 @@ export function bump() { | |
* @param shouldBump writes a new version of the schema and bumps the major version | ||
*/ | ||
export function generateSchema(schemaName: string, saveToFile: boolean = true) { | ||
const spec = SCHEMA_DEFINITIONS[schemaName]; | ||
const spec = getSchemaDefinition(schemaName); | ||
const out = saveToFile ? path.join(SCHEMA_DIR, `${schemaName}.schema.json`) : ''; | ||
|
||
const settings: Partial<tjs.Args> = { | ||
|
@@ -87,10 +50,7 @@ export function generateSchema(schemaName: string, saveToFile: boolean = true) { | |
strictNullChecks: true, | ||
}; | ||
|
||
const program = tjs.getProgramFromFiles( | ||
spec.files.map((file) => path.join(__dirname, '..', 'lib', file)), | ||
compilerOptions | ||
); | ||
const program = tjs.getProgramFromFiles([spec.sourceFile], compilerOptions); | ||
const schema = tjs.generateSchema(program, spec.rootTypeName, settings); | ||
|
||
augmentDescription(schema); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { SCHEMAS } from './schema-definition'; | ||
import { generateSchema } from './update-schema'; | ||
|
||
export function update() { | ||
for (const s of SCHEMAS) { | ||
generateSchema(s); | ||
} | ||
} |
Oops, something went wrong.