Skip to content

Commit 0db56c2

Browse files
committed
fix(scripts): bump playground in release process
1 parent 0875ec6 commit 0db56c2

File tree

13 files changed

+135
-39
lines changed

13 files changed

+135
-39
lines changed

config/clients.config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
},
1414
"javascript": {
1515
"folder": "clients/algoliasearch-client-javascript",
16+
"npmNamespace": "@experimental-api-clients-automation",
1617
"gitRepoId": "algoliasearch-client-javascript",
1718
"utilsPackageVersion": "0.4.0",
1819
"modelFolder": "model",

generators/src/main/java/com/algolia/codegen/AlgoliaJavaScriptGenerator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
7171
try {
7272
Utils.generateServer((String) additionalProperties.get("client"), additionalProperties);
7373
additionalProperties.put("utilsPackageVersion", Utils.getClientConfigField("javascript", "utilsPackageVersion"));
74+
additionalProperties.put("npmNamespace", Utils.getClientConfigField("javascript", "npmNamespace"));
7475
} catch (GeneratorException e) {
7576
e.printStackTrace();
7677
System.exit(1);

generators/src/main/java/com/algolia/codegen/cts/AlgoliaCTSGenerator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ public Map<String, Object> postProcessSupportingFileData(Map<String, Object> obj
9696
bundle.put("hasRegionalHost", hasRegionalHost);
9797
bundle.put("defaultRegion", client.equals("predict") ? "ew" : "us");
9898
bundle.put("lambda", lambda);
99+
100+
if (language.equals("javascript")) {
101+
bundle.put("npmNamespace", Utils.getClientConfigField(language, "npmNamespace"));
102+
}
103+
99104
ctsManager.addDataToBundle(bundle);
100105

101106
for (TestsGenerator testGen : testsGenerators) {

scripts/release/common.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import fsp from 'fs/promises';
12
import path from 'path';
23

34
import config from '../../config/release.config.json';
@@ -45,3 +46,31 @@ export async function cloneRepository({
4546
tempGitDir,
4647
};
4748
}
49+
50+
/**
51+
* Reads a JSON file and returns its parsed data.
52+
*
53+
* @param ppath - The absolute path to the file.
54+
*/
55+
export async function readJsonFile(
56+
ppath: string
57+
): Promise<Record<string, any>> {
58+
return JSON.parse(
59+
await fsp.readFile(ppath, {
60+
encoding: 'utf-8',
61+
})
62+
);
63+
}
64+
65+
/**
66+
* Writes `data` in a file at the given `ppath`, appends a newline at the end of the file.
67+
*
68+
* @param ppath - The absolute path to the file.
69+
* @param data - The data to store.
70+
*/
71+
export async function writeJsonFile(
72+
ppath: string,
73+
data: Record<string, any>
74+
): Promise<void> {
75+
await fsp.writeFile(ppath, JSON.stringify(data, null, 2).concat('\n'));
76+
}

scripts/release/updateAPIVersions.ts

Lines changed: 81 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
LANGUAGES,
1717
MAIN_BRANCH,
1818
gitBranchExists,
19+
CLIENTS_JS_UTILS,
1920
} from '../common';
2021
import {
2122
getClientsConfigField,
@@ -24,18 +25,49 @@ import {
2425
} from '../config';
2526
import type { Language } from '../types';
2627

28+
import { readJsonFile, writeJsonFile } from './common';
2729
import type { Changelog, Versions, VersionsToRelease } from './types';
2830

2931
dotenv.config({ path: ROOT_ENV_PATH });
3032

3133
/**
32-
* Bump each client version of the JavaScript client in openapitools.json.
34+
* Bump each client version of the JavaScript client in workspace places and config files.
3335
*
3436
* We don't use the pre-computed `next` version for JavaScript, because the packages have independent versioning.
3537
*/
3638
async function updateVersionForJavascript(
3739
jsVersion: NonNullable<VersionsToRelease['javascript']>
3840
): Promise<void> {
41+
// Sets the new version of the utils package
42+
const utilsPackageVersion = getClientsConfigField(
43+
'javascript',
44+
'utilsPackageVersion'
45+
);
46+
const nextUtilsPackageVersion = semver.inc(
47+
utilsPackageVersion,
48+
jsVersion.releaseType
49+
);
50+
51+
if (!nextUtilsPackageVersion) {
52+
throw new Error(
53+
`Failed to bump version ${utilsPackageVersion} by ${jsVersion.releaseType}.`
54+
);
55+
}
56+
57+
clientsConfig.javascript.utilsPackageVersion = nextUtilsPackageVersion;
58+
59+
// update local playground deps
60+
const nodePgPackageFile = await readJsonFile(
61+
toAbsolutePath('playground/javascript/node/package.json')
62+
);
63+
const browserPgPackageFile = await readJsonFile(
64+
toAbsolutePath('playground/javascript/browser/package.json')
65+
);
66+
67+
if (!nodePgPackageFile || !browserPgPackageFile) {
68+
throw new Error('Failed to bump playground package files');
69+
}
70+
3971
// Sets the new version of the JavaScript client
4072
Object.values(GENERATORS)
4173
.filter((gen) => gen.language === 'javascript')
@@ -45,39 +77,67 @@ async function updateVersionForJavascript(
4577
additionalProperties.packageVersion,
4678
jsVersion.releaseType
4779
);
80+
4881
if (!newVersion) {
4982
throw new Error(
5083
`Failed to bump version ${additionalProperties.packageVersion} by ${jsVersion.releaseType}.`
5184
);
5285
}
86+
5387
additionalProperties.packageVersion = newVersion;
88+
89+
if (!additionalProperties.packageName) {
90+
throw new Error(
91+
`Package name is missing for JavaScript - ${gen.client}.`
92+
);
93+
}
94+
95+
if (nodePgPackageFile.dependencies[additionalProperties.packageName]) {
96+
nodePgPackageFile.dependencies[additionalProperties.packageName] =
97+
newVersion;
98+
}
99+
100+
if (browserPgPackageFile.dependencies[additionalProperties.packageName]) {
101+
browserPgPackageFile.dependencies[additionalProperties.packageName] =
102+
newVersion;
103+
}
54104
});
55105

56-
await fsp.writeFile(
106+
CLIENTS_JS_UTILS.forEach((util) => {
107+
const utilPackageName = `${clientsConfig.javascript.npmNamespace}/${util}`;
108+
109+
if (nodePgPackageFile.dependencies[utilPackageName]) {
110+
nodePgPackageFile.dependencies[utilPackageName] = nextUtilsPackageVersion;
111+
}
112+
113+
if (browserPgPackageFile.dependencies[utilPackageName]) {
114+
browserPgPackageFile.dependencies[utilPackageName] =
115+
nextUtilsPackageVersion;
116+
}
117+
});
118+
119+
// update `openapitools.json` config file
120+
await writeJsonFile(
57121
toAbsolutePath('config/openapitools.json'),
58-
JSON.stringify(openapiConfig, null, 2).concat('\n')
122+
openapiConfig
59123
);
60124

61-
// Sets the new version of the utils package
62-
const utilsPackageVersion = getClientsConfigField(
63-
'javascript',
64-
'utilsPackageVersion'
65-
);
66-
const nextUtilsPackageVersion = semver.inc(
67-
utilsPackageVersion,
68-
jsVersion.releaseType
125+
// update `package.json` node playground file
126+
await writeJsonFile(
127+
toAbsolutePath('playground/javascript/node/package.json'),
128+
nodePgPackageFile
69129
);
70130

71-
if (!nextUtilsPackageVersion) {
72-
throw new Error(
73-
`Failed to bump version ${utilsPackageVersion} by ${jsVersion.releaseType}.`
74-
);
75-
}
131+
// update `package.json` browser playground file
132+
await writeJsonFile(
133+
toAbsolutePath('playground/javascript/browser/package.json'),
134+
browserPgPackageFile
135+
);
76136

77-
clientsConfig.javascript.utilsPackageVersion = nextUtilsPackageVersion;
78-
await fsp.writeFile(
137+
// update `clients.config.json` file for the utils version
138+
await writeJsonFile(
79139
toAbsolutePath('config/clients.config.json'),
80-
JSON.stringify(clientsConfig, null, 2).concat('\n')
140+
clientsConfig
81141
);
82142
}
83143

@@ -97,9 +157,9 @@ async function updateConfigFiles(
97157
clientsConfig[lang].packageVersion = versionsToRelease[lang]!.next;
98158
});
99159

100-
await fsp.writeFile(
160+
await writeJsonFile(
101161
toAbsolutePath('config/clients.config.json'),
102-
JSON.stringify(clientsConfig, null, 2).concat('\n')
162+
clientsConfig
103163
);
104164
}
105165

templates/javascript/api/builds/imports.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { InitClientOptions } from '@experimental-api-clients-automation/client-common';
2-
import { createMemoryCache, createFallbackableCache, createBrowserLocalStorageCache, createNullCache } from '@experimental-api-clients-automation/client-common';
1+
import type { InitClientOptions } from '{{{npmNamespace}}}/client-common';
2+
import { createMemoryCache, createFallbackableCache, createBrowserLocalStorageCache, createNullCache } from '{{{npmNamespace}}}/client-common';
33

44
import { create{{capitalizedApiName}}, apiClientVersion } from '../src/{{apiName}}';
55
import type { {{capitalizedApiName}} } from '../src/{{apiName}}';

templates/javascript/api/imports.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
{{#isSearchClient}}
77
createRetryablePromise,
88
{{/isSearchClient}}
9-
} from '@experimental-api-clients-automation/client-common';
9+
} from '{{{npmNamespace}}}/client-common';
1010
import type {
1111
CreateClientOptions,
1212
Headers,
@@ -17,7 +17,7 @@ import type {
1717
{{#isSearchClient}}
1818
CreateRetryablePromiseOptions,
1919
{{/isSearchClient}}
20-
} from '@experimental-api-clients-automation/client-common';
20+
} from '{{{npmNamespace}}}/client-common';
2121

2222
{{#imports}}
2323
import { {{classname}} } from '{{filename}}';

templates/javascript/browser.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { createXhrRequester } from '@experimental-api-clients-automation/requester-browser-xhr';
2-
import { DEFAULT_CONNECT_TIMEOUT_BROWSER, DEFAULT_READ_TIMEOUT_BROWSER, DEFAULT_WRITE_TIMEOUT_BROWSER } from '@experimental-api-clients-automation/client-common';
1+
import { createXhrRequester } from '{{{npmNamespace}}}/requester-browser-xhr';
2+
import { DEFAULT_CONNECT_TIMEOUT_BROWSER, DEFAULT_READ_TIMEOUT_BROWSER, DEFAULT_WRITE_TIMEOUT_BROWSER } from '{{{npmNamespace}}}/client-common';
33
{{> api/builds/imports}}
44

55
export function {{apiName}}(

templates/javascript/node.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { createHttpRequester } from '@experimental-api-clients-automation/requester-node-http';
2-
import { DEFAULT_CONNECT_TIMEOUT_NODE, DEFAULT_READ_TIMEOUT_NODE, DEFAULT_WRITE_TIMEOUT_NODE } from '@experimental-api-clients-automation/client-common';
1+
import { createHttpRequester } from '{{{npmNamespace}}}/requester-node-http';
2+
import { DEFAULT_CONNECT_TIMEOUT_NODE, DEFAULT_READ_TIMEOUT_NODE, DEFAULT_WRITE_TIMEOUT_NODE } from '{{{npmNamespace}}}/client-common';
33
{{> api/builds/imports}}
44

55
export function {{apiName}}(

templates/javascript/package.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
"clean": "rm -rf ./dist"
2222
},
2323
"dependencies": {
24-
"@experimental-api-clients-automation/client-common": "{{utilsPackageVersion}}",
25-
"@experimental-api-clients-automation/requester-browser-xhr": "{{utilsPackageVersion}}",
26-
"@experimental-api-clients-automation/requester-node-http": "{{utilsPackageVersion}}"
24+
"{{{npmNamespace}}}/client-common": "{{utilsPackageVersion}}",
25+
"{{{npmNamespace}}}/requester-browser-xhr": "{{utilsPackageVersion}}",
26+
"{{{npmNamespace}}}/requester-node-http": "{{utilsPackageVersion}}"
2727
},
2828
"devDependencies": {
2929
"@types/node": "16.11.39",

templates/javascript/tests/client/suite.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* eslint-disable @typescript-eslint/no-unused-vars, require-await */
22
// @ts-nocheck Failing tests will have type errors, but we cannot suppress them even with @ts-expect-error because it doesn't work for a block of lines.
33
import { {{client}}, {{#lambda.titlecase}}{{client}}{{/lambda.titlecase}} } from '{{{import}}}';
4-
import { echoRequester } from '@experimental-api-clients-automation/requester-node-http';
5-
import type { EchoResponse } from '@experimental-api-clients-automation/requester-node-http';
4+
import { echoRequester } from '{{{npmNamespace}}}/requester-node-http';
5+
import type { EchoResponse } from '{{{npmNamespace}}}/requester-node-http';
66

77
const appId = 'test-app-id';
88
const apiKey = 'test-api-key';

templates/javascript/tests/package.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
{{#packageDependencies}}
99
"{{{packageName}}}": "{{packageVersion}}",
1010
{{/packageDependencies}}
11-
"@experimental-api-clients-automation/client-common": "{{utilsPackageVersion}}",
12-
"@experimental-api-clients-automation/requester-node-http": "{{utilsPackageVersion}}"
11+
"{{{npmNamespace}}}/client-common": "{{utilsPackageVersion}}",
12+
"{{{npmNamespace}}}/requester-node-http": "{{utilsPackageVersion}}"
1313
},
1414
"devDependencies": {
1515
"@types/jest": "28.1.1",

templates/javascript/tests/requests/requests.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { {{client}} } from '{{{import}}}';
2-
import { echoRequester } from '@experimental-api-clients-automation/requester-node-http';
3-
import type { EchoResponse } from '@experimental-api-clients-automation/client-common';
4-
import type { RequestOptions } from '@experimental-api-clients-automation/client-common';
2+
import { echoRequester } from '{{{npmNamespace}}}/requester-node-http';
3+
import type { EchoResponse } from '{{{npmNamespace}}}/client-common';
4+
import type { RequestOptions } from '{{{npmNamespace}}}/client-common';
55

66
const appId = process.env.ALGOLIA_APPLICATION_ID || 'test_app_id';
77
const apiKey = process.env.ALGOLIA_SEARCH_KEY || 'test_api_key';

0 commit comments

Comments
 (0)