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(ci): manage utils package version to bump versions correctly #346

Merged
merged 7 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
27 changes: 18 additions & 9 deletions openapitools.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"apiName": "search",
"capitalizedApiName": "Search",
"packageVersion": "0.0.5",
"packageName": "@experimental-api-clients-automation/client-search"
"packageName": "@experimental-api-clients-automation/client-search",
"utilsPackageVersion": "0.0.5"
}
},
"javascript-recommend": {
Expand All @@ -44,7 +45,8 @@
"apiName": "recommend",
"capitalizedApiName": "Recommend",
"packageVersion": "0.0.5",
"packageName": "@experimental-api-clients-automation/recommend"
"packageName": "@experimental-api-clients-automation/recommend",
"utilsPackageVersion": "0.0.5"
}
},
"javascript-personalization": {
Expand All @@ -69,7 +71,8 @@
"hasRegionalHost": true,
"isEuHost": true,
"host": "personalization",
"topLevelDomain": "com"
"topLevelDomain": "com",
"utilsPackageVersion": "0.0.5"
}
},
"javascript-analytics": {
Expand All @@ -95,7 +98,8 @@
"hasRegionalHost": true,
"isDeHost": true,
"host": "analytics",
"topLevelDomain": "com"
"topLevelDomain": "com",
"utilsPackageVersion": "0.0.5"
}
},
"javascript-insights": {
Expand All @@ -121,7 +125,8 @@
"hasRegionalHost": true,
"isDeHost": true,
"host": "insights",
"topLevelDomain": "io"
"topLevelDomain": "io",
"utilsPackageVersion": "0.0.5"
}
},
"javascript-abtesting": {
Expand All @@ -147,7 +152,8 @@
"fallbackToAliasHost": true,
"isDeHost": true,
"host": "analytics",
"topLevelDomain": "com"
"topLevelDomain": "com",
"utilsPackageVersion": "0.0.5"
}
},
"javascript-query-suggestions": {
Expand All @@ -172,7 +178,8 @@
"hasRegionalHost": true,
"isEuHost": true,
"host": "query-suggestions",
"topLevelDomain": "com"
"topLevelDomain": "com",
"utilsPackageVersion": "0.0.5"
}
},
"javascript-sources": {
Expand All @@ -197,7 +204,8 @@
"hasRegionalHost": true,
"isDeHost": true,
"host": "data",
"topLevelDomain": "com"
"topLevelDomain": "com",
"utilsPackageVersion": "0.0.5"
}
},
"javascript-predict": {
Expand All @@ -219,7 +227,8 @@
"capitalizedApiName": "Predict",
"packageVersion": "0.0.5",
"packageName": "@experimental-api-clients-automation/client-predict",
"experimentalHost": "predict-api-oslcbws3zq-ew.a.run.app"
"experimentalHost": "predict-api-oslcbws3zq-ew.a.run.app",
"utilsPackageVersion": "0.0.5"
}
},
"java-search": {
Expand Down
19 changes: 17 additions & 2 deletions scripts/release/process-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
configureGitHubAuthor,
cloneRepository,
getOctokit,
MAIN_PACKAGE,
} from './common';
import TEXT from './text';
import type {
Expand Down Expand Up @@ -103,22 +104,36 @@ export function getVersionsToRelease(issueBody: string): VersionsToRelease {
async function updateOpenApiTools(
versionsToRelease: VersionsToRelease
): Promise<void> {
const nextUtilsPackageVersion = semver.inc(
openapitools['generator-cli'].generators[MAIN_PACKAGE.javascript]
.additionalProperties.utilsPackageVersion,
versionsToRelease.javascript?.releaseType
);

Object.keys(openapitools['generator-cli'].generators).forEach((client) => {
const lang = client.split('-')[0];
if (versionsToRelease[lang]) {
const additionalProperties =
openapitools['generator-cli'].generators[client].additionalProperties;
const releaseType = versionsToRelease[lang].releaseType;

const newVersion = semver.inc(
additionalProperties.packageVersion,
versionsToRelease[lang].releaseType
releaseType
);
if (!newVersion) {
throw new Error(
`Failed to bump version ${additionalProperties.packageVersion} by ${versionsToRelease[lang].releaseType}.`
`Failed to bump version ${additionalProperties.packageVersion} by ${releaseType}.`
);
}
additionalProperties.packageVersion = newVersion;

// In case we're not releasing javascript package,
// we shouldn't bump the utils version.
// At that time `nextUtilsPackageVersion` is undefined, and the following branch is skipped.
if (lang === 'javascript' && nextUtilsPackageVersion) {
additionalProperties.utilsPackageVersion = nextUtilsPackageVersion;
}
Comment on lines +134 to +136
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (lang === 'javascript' && nextUtilsPackageVersion) {
additionalProperties.utilsPackageVersion = nextUtilsPackageVersion;
}
if (lang === 'javascript') {
additionalProperties.utilsPackageVersion = nextUtilsPackageVersion || mainPackageUtilsVersion;
}

mainPackageUtilsVersion is openapitools['generator-cli'].generators[MAIN_PACKAGE.javascript] .additionalProperties.utilsPackageVersion

So it's initialized in case it's missing anyway? wdyt?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it's worth handling it actually as the gen would throw if there's no utilsPackageVersion 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case we're not releasing javascript package, we shouldn't bump the utils version in the openapitools.json. I'll add the comment.

}
});
await fsp.writeFile(
Expand Down
6 changes: 3 additions & 3 deletions templates/javascript/package.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
"node": ">= 14.0.0"
},
"dependencies": {
"@experimental-api-clients-automation/client-common": "^0.0.5",
"@experimental-api-clients-automation/requester-browser-xhr": "^0.0.5",
"@experimental-api-clients-automation/requester-node-http": "^0.0.5"
"@experimental-api-clients-automation/client-common": "{{utilsPackageVersion}}",
"@experimental-api-clients-automation/requester-browser-xhr": "{{utilsPackageVersion}}",
"@experimental-api-clients-automation/requester-node-http": "{{utilsPackageVersion}}"
},
"devDependencies": {
"@types/node": "16.11.26",
Expand Down