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: improve v1 integration test #86

Merged
merged 7 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
42 changes: 41 additions & 1 deletion projenrc/tag-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { SemVer } from 'semver';
import { versionMajorMinor } from 'typescript';
import * as yargs from 'yargs';

type PrereleaseIdentifier = 'dev' | 'pre' | 'alpha' | 'beta' | 'rc';

async function main(): Promise<void> {
const {
dryRun,
Expand Down Expand Up @@ -30,7 +32,7 @@ async function main(): Promise<void> {
alias: 'pre-release',
type: 'string',
desc: 'Use the specified pre-release identifier',
choices: ['dev', 'pre', 'alpha', 'beta', 'rc'],
choices: ['dev', 'pre', 'alpha', 'beta', 'rc'] as PrereleaseIdentifier[],
})
.option('push', {
boolean: true,
Expand Down Expand Up @@ -194,6 +196,8 @@ async function main(): Promise<void> {
'--contains',
'--match',
`v${versionMajorMinor}.*`,
// If no prerelease identifier, ignore any prerelease tags (we're "upgrading" to a regular release)
...excludeLowerTags(prerelease),
'--tags',
HEAD,
);
Expand Down Expand Up @@ -258,6 +262,42 @@ async function main(): Promise<void> {
await git('push', remote, `v${version}`);
}

/**
* Computes the `--exclude` options to be passed tino `git describe` to filter
* out any pre-release tags considered "inferior" to the current one, so that
* releases may be published that upgrade an artifact from one prerelease tier
* to the next tier (up to regular release).
*
* @param prerelease the prerelease identifier this is running for.
* @param versionMajorMinor the major/minor version considered.
*
* @returns arguments to pass tp `git describe`.
RomainMuller marked this conversation as resolved.
Show resolved Hide resolved
*/
function excludeLowerTags(prerelease: PrereleaseIdentifier | undefined): readonly string[] {
switch (prerelease) {
case 'dev':
case 'pre':
// -dev and -pre are the lowest rank. They can't be re-tagged as -dev or -pre.
return [];
case 'alpha':
// -dev and -pre can be upgraded to -alpha.
return excludeIdentifiers('dev', 'pre');
case 'beta':
// -dev, -pre and -alpha can be upgraded to -beta
return excludeIdentifiers('dev', 'pre', 'alpha');
case 'rc':
// -dev, -pre, -alpha and -beta can be upgraded to -rv
return excludeIdentifiers('dev', 'pre', 'alpha', 'beta');
case undefined:
// Regular release, ignore all prerelease tags.
return ['--exclude', `v${versionMajorMinor}.*-*`];
}

function excludeIdentifiers(...toExclude: readonly PrereleaseIdentifier[]) {
return toExclude.flatMap((id) => ['--exclude', `v${versionMajorMinor}.*-${id}.*`]);
}
}

main().then(
() => {},
(err) => {
Expand Down
61 changes: 61 additions & 0 deletions test/__snapshots__/integration.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ test('v1 compatibility check', () => {
// Export some class so the assembly isn't empty (not that it matters,
// really), but most use stuff from `calc` so it's not elided by the
// compiler.
'export class SomeClass {',
'export class SomeClass extends deep.BarrelImportClass {',
' private constructor() {',
' new deep.BarrelImportClass();',
' super();',
'',
' const calculator = new calc.Calculator();',
' calculator.add(42);',
Expand All @@ -80,6 +80,7 @@ test('v1 compatibility check', () => {
{
compilationDirectory,
packageJson: {
dependencies: { '@scope/jsii-calc-base': '*' },
jsii: {
tsc: {
types: ['node'],
Expand Down