Skip to content

Commit

Permalink
chore: avoid empty next version release (#657)
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts authored Jun 8, 2022
1 parent 21860da commit ee77bc2
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 33 deletions.
1 change: 1 addition & 0 deletions scripts/release/__tests__/createReleasePR.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ describe('createReleasePR', () => {
current: '0.0.1',
releaseType: null,
noCommit: true,
next: null,
},

java: {
Expand Down
7 changes: 7 additions & 0 deletions scripts/release/__tests__/updateAPIVersions.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getNextVersion } from '../createReleasePR';
import { getVersionsToRelease } from '../updateAPIVersions';

describe('updateAPIversions', () => {
Expand All @@ -6,16 +7,19 @@ describe('updateAPIversions', () => {
javascript: {
current: '1.0.0',
releaseType: 'minor',
next: getNextVersion('1.0.0', 'minor'),
},
php: {
current: '2.0.0',
releaseType: 'patch',
next: getNextVersion('2.0.0', 'patch'),
},
java: {
current: '3.0.0',
releaseType: null,
noCommit: true,
skipRelease: true,
next: null,
},
});

Expand All @@ -32,15 +36,18 @@ describe('updateAPIversions', () => {
javascript: {
current: '0.0.1',
releaseType: 'patch',
next: getNextVersion('0.0.1', 'patch'),
},
php: {
current: '0.0.1',
releaseType: 'minor',
next: getNextVersion('0.0.1', 'minor'),
},
java: {
current: '0.0.1',
releaseType: 'patch',
skipRelease: true,
next: null,
},
});
expect(versions).toEqual({
Expand Down
10 changes: 7 additions & 3 deletions scripts/release/createReleasePR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { RELEASED_TAG } from './common';
import TEXT from './text';
import type {
Versions,
VersionsWithoutReleaseType,
VersionsBeforeBump,
PassedCommit,
Commit,
Scope,
Expand All @@ -34,7 +34,7 @@ dotenv.config({ path: ROOT_ENV_PATH });

const COMMON_SCOPES = ['specs'];

export function readVersions(): VersionsWithoutReleaseType {
export function readVersions(): VersionsBeforeBump {
return Object.fromEntries(
LANGUAGES.map((lang) => [lang, { current: getPackageVersionDefault(lang) }])
);
Expand Down Expand Up @@ -177,6 +177,10 @@ export function getNextVersion(
);
}

console.log(
`Next version is '${nextVersion}', release type: '${releaseType}'`
);

return nextVersion;
}

Expand All @@ -185,7 +189,7 @@ export function decideReleaseStrategy({
versions,
commits,
}: {
versions: VersionsWithoutReleaseType;
versions: VersionsBeforeBump;
commits: PassedCommit[];
}): Versions {
return Object.entries(versions).reduce(
Expand Down
10 changes: 6 additions & 4 deletions scripts/release/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Language } from '../types';
export type Version = {
current: string;
releaseType: ReleaseType | null;
next?: string;
next: string | null;
skipRelease?: boolean;
noCommit?: boolean;
};
Expand All @@ -14,8 +14,8 @@ export type Versions = {
[lang: string]: Version;
};

export type VersionsWithoutReleaseType = {
[lang: string]: Omit<Version, 'releaseType'>;
export type VersionsBeforeBump = {
[lang: string]: Omit<Version, 'next' | 'releaseType'>;
};

export type Scope = Language | 'specs';
Expand All @@ -38,7 +38,9 @@ export type Commit =
| { error: 'unknown-language-scope' };

export type VersionsToRelease = {
[lang in Language]?: Pick<Version, 'current' | 'next'> & {
[lang in Language]?: {
current: string;
next: string;
releaseType: ReleaseType;
};
};
Expand Down
40 changes: 14 additions & 26 deletions scripts/release/updateAPIVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
getClientsConfigField,
getGitHubUrl,
getLanguageFolder,
getPackageVersionDefault,
} from '../config';
import type { Language } from '../types';

Expand All @@ -31,16 +30,13 @@ dotenv.config({ path: ROOT_ENV_PATH });

/**
* Bump each client version of the JavaScript client in openapitools.json.
*
* We don't use the pre-computed `next` version for JavaScript, because the packages have independent versioning.
*/
async function updateVersionForJavascript(
versionsToRelease: VersionsToRelease
jsVersion: NonNullable<VersionsToRelease['javascript']>
): Promise<void> {
if (!versionsToRelease.javascript) {
return;
}

// Sets the new version of the JavaScript client
const jsVersion = versionsToRelease.javascript;
Object.values(GENERATORS)
.filter((gen) => gen.language === 'javascript')
.forEach((gen) => {
Expand All @@ -58,7 +54,7 @@ async function updateVersionForJavascript(
});

await fsp.writeFile(
toAbsolutePath('config/openapitools.json'),
toAbsolutePath('config/openapitools.json').concat('\n'),
JSON.stringify(openapiConfig, null, 2)
);

Expand All @@ -81,38 +77,29 @@ async function updateVersionForJavascript(
clientsConfig.javascript.utilsPackageVersion = nextUtilsPackageVersion;
await fsp.writeFile(
toAbsolutePath('config/clients.config.json'),
JSON.stringify(clientsConfig, null, 2)
JSON.stringify(clientsConfig, null, 2).concat('\n')
);
}

async function updateConfigFiles(
versionsToRelease: VersionsToRelease
): Promise<void> {
await updateVersionForJavascript(versionsToRelease);
if (versionsToRelease.javascript) {
await updateVersionForJavascript(versionsToRelease.javascript);
}

// update the other versions in clients.config.json
LANGUAGES.forEach((lang) => {
if (lang === 'javascript' || !versionsToRelease[lang]) {
return;
}

const releaseType = versionsToRelease[lang]!.releaseType;
const nextVersion = versionsToRelease[lang]!.next;

if (!nextVersion) {
throw new Error(
`Failed to bump version ${getPackageVersionDefault(
lang
)} by ${releaseType}.`
);
}

clientsConfig[lang].packageVersion = nextVersion;
clientsConfig[lang].packageVersion = versionsToRelease[lang]!.next;
});

await fsp.writeFile(
toAbsolutePath('config/clients.config.json'),
JSON.stringify(clientsConfig, null, 2)
JSON.stringify(clientsConfig, null, 2).concat('\n')
);
}

Expand Down Expand Up @@ -146,8 +133,8 @@ export function getVersionsToRelease(versions: Versions): VersionsToRelease {
const versionsToRelease: VersionsToRelease = {};

Object.entries(versions).forEach(
([lang, { noCommit, current, skipRelease, releaseType }]) => {
if (noCommit || skipRelease || !current) {
([lang, { noCommit, current, skipRelease, releaseType, next }]) => {
if (noCommit || skipRelease || !current || !next) {
return;
}

Expand All @@ -163,6 +150,7 @@ export function getVersionsToRelease(versions: Versions): VersionsToRelease {
versionsToRelease[lang] = {
current,
releaseType,
next,
};
}
);
Expand Down Expand Up @@ -221,7 +209,7 @@ export async function updateAPIVersions(
lang: lang as Language,
changelog,
current,
next: next!,
next,
});
}

Expand Down

0 comments on commit ee77bc2

Please sign in to comment.