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

fix(scripts): bump playground in release process #690

Merged
merged 4 commits into from
Jun 14, 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
1 change: 1 addition & 0 deletions config/clients.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"javascript": {
"folder": "clients/algoliasearch-client-javascript",
"npmNamespace": "@experimental-api-clients-automation",
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe you can simplify packageName in openapitools.json to only be the package name without the @experimental-api-clients-automation

Copy link
Member Author

Choose a reason for hiding this comment

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

good idea! let's see if it does the thing 5942a5c

Copy link
Member Author

Choose a reason for hiding this comment

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

we could even do more magic by guessing it from the output path but will see

Copy link
Member Author

@shortcuts shortcuts Jun 14, 2022

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah didn't even see buildFile variable lol, it's better like that

Copy link
Member Author

@shortcuts shortcuts Jun 14, 2022

Choose a reason for hiding this comment

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

yup!! i'm trying to guess it from the path and we can remove additionalProperties :D

edit: ah no we still need the version

"gitRepoId": "algoliasearch-client-javascript",
"utilsPackageVersion": "0.5.0",
"modelFolder": "model",
Expand Down
20 changes: 0 additions & 20 deletions config/openapitools.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,82 +6,62 @@
"output": "#{cwd}/clients/algoliasearch-client-javascript/packages/client-search",
"reservedWordsMappings": "queryParameters=queryParameters,requestOptions=requestOptions",
"additionalProperties": {
"packageName": "@experimental-api-clients-automation/client-search",
"buildFile": "client-search",
"packageVersion": "0.5.0"
}
},
"javascript-algoliasearch-lite": {
"output": "#{cwd}/clients/algoliasearch-client-javascript/packages/algoliasearch-lite",
"reservedWordsMappings": "queryParameters=queryParameters,requestOptions=requestOptions",
"additionalProperties": {
"packageName": "@experimental-api-clients-automation/algoliasearch-lite",
"buildFile": "algoliasearch-lite",
"packageVersion": "0.5.0"
}
},
"javascript-recommend": {
"output": "#{cwd}/clients/algoliasearch-client-javascript/packages/recommend",
"reservedWordsMappings": "queryParameters=queryParameters",
"additionalProperties": {
"packageName": "@experimental-api-clients-automation/recommend",
"buildFile": "recommend",
"packageVersion": "0.5.0"
}
},
"javascript-personalization": {
"output": "#{cwd}/clients/algoliasearch-client-javascript/packages/client-personalization",
"additionalProperties": {
"packageName": "@experimental-api-clients-automation/client-personalization",
"buildFile": "client-personalization",
"packageVersion": "0.5.0"
}
},
"javascript-analytics": {
"output": "#{cwd}/clients/algoliasearch-client-javascript/packages/client-analytics",
"additionalProperties": {
"packageName": "@experimental-api-clients-automation/client-analytics",
"buildFile": "client-analytics",
"packageVersion": "0.5.0"
}
},
"javascript-insights": {
"output": "#{cwd}/clients/algoliasearch-client-javascript/packages/client-insights",
"additionalProperties": {
"packageName": "@experimental-api-clients-automation/client-insights",
"buildFile": "client-insights",
"packageVersion": "0.5.0"
}
},
"javascript-abtesting": {
"output": "#{cwd}/clients/algoliasearch-client-javascript/packages/client-abtesting",
"additionalProperties": {
"packageName": "@experimental-api-clients-automation/client-abtesting",
"buildFile": "client-abtesting",
"packageVersion": "0.5.0"
}
},
"javascript-query-suggestions": {
"output": "#{cwd}/clients/algoliasearch-client-javascript/packages/client-query-suggestions",
"additionalProperties": {
"packageName": "@experimental-api-clients-automation/client-query-suggestions",
"buildFile": "client-query-suggestions",
"packageVersion": "0.5.0"
}
},
"javascript-sources": {
"output": "#{cwd}/clients/algoliasearch-client-javascript/packages/client-sources",
"additionalProperties": {
"packageName": "@experimental-api-clients-automation/client-sources",
"buildFile": "client-sources",
"packageVersion": "0.5.0"
}
},
"javascript-predict": {
"output": "#{cwd}/clients/algoliasearch-client-javascript/packages/client-predict",
"additionalProperties": {
"packageName": "@experimental-api-clients-automation/client-predict",
"buildFile": "client-predict",
"packageVersion": "0.5.0"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
try {
Utils.generateServer((String) additionalProperties.get("client"), additionalProperties);
additionalProperties.put("utilsPackageVersion", Utils.getClientConfigField("javascript", "utilsPackageVersion"));
additionalProperties.put("npmNamespace", Utils.getClientConfigField("javascript", "npmNamespace"));
} catch (GeneratorException e) {
e.printStackTrace();
System.exit(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ public Map<String, Object> postProcessSupportingFileData(Map<String, Object> obj
bundle.put("hasRegionalHost", hasRegionalHost);
bundle.put("defaultRegion", client.equals("predict") ? "ew" : "us");
bundle.put("lambda", lambda);

if (language.equals("javascript")) {
bundle.put("npmNamespace", Utils.getClientConfigField(language, "npmNamespace"));
}

ctsManager.addDataToBundle(bundle);

for (TestsGenerator testGen : testsGenerators) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ public void addSupportingFiles(List<SupportingFile> supportingFiles) {
public void addDataToBundle(Map<String, Object> bundle) throws GeneratorException {
bundle.put("packageDependencies", this.getPackageDependencies());
bundle.put("utilsPackageVersion", Utils.getClientConfigField("javascript", "utilsPackageVersion"));
bundle.put("import", openApiToolsConfig.get("javascript-" + client).get("additionalProperties").get("packageName").asText());

String output = this.openApiToolsConfig.get("javascript-" + client).get("output").asText();
String packageName = Utils.getClientConfigField("javascript", "npmNamespace") + "/" + output.substring(output.lastIndexOf('/') + 1);
bundle.put("import", packageName);
}

private List<Map<String, String>> getPackageDependencies() {
Expand All @@ -38,8 +41,9 @@ private List<Map<String, String>> getPackageDependencies() {
}
JsonNode generator = field.getValue();
JsonNode additionalProperties = generator.get("additionalProperties");
String packageName = additionalProperties.get("packageName").asText();
String output = generator.get("output").asText();
String packageVersion = additionalProperties.get("packageVersion").asText();
String packageName = output.substring(output.lastIndexOf('/') + 1);

Map<String, String> newEntry = new HashMap<>();
newEntry.put("packageName", packageName);
Expand Down
15 changes: 10 additions & 5 deletions scripts/buildClients.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CI, run } from './common';
import { getLanguageFolder } from './config';
import { getClientsConfigField, getLanguageFolder } from './config';
import { createSpinner } from './oraLog';
import type { Generator } from './types';

Expand All @@ -13,13 +13,18 @@ async function buildPerClient(
verbose: boolean
): Promise<void> {
const spinner = createSpinner(`building ${key}`, verbose).start();
const npmNamespace = getClientsConfigField(language, 'npmNamespace');

switch (language) {
case 'javascript':
await run(`yarn workspace ${additionalProperties?.packageName} clean`, {
verbose,
});
await run(
`SKIP_UTILS=true yarn workspace algoliasearch-client-javascript build ${additionalProperties?.packageName}`,
`yarn workspace ${npmNamespace}/${additionalProperties.packageName} clean`,
{
verbose,
}
);
await run(
`SKIP_UTILS=true yarn workspace algoliasearch-client-javascript build ${npmNamespace}/${additionalProperties.packageName}`,
{ verbose }
);
break;
Expand Down
33 changes: 16 additions & 17 deletions scripts/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,37 @@ export const ROOT_DIR = path.resolve(process.cwd(), '..');
export const ROOT_ENV_PATH = path.resolve(ROOT_DIR, '.env');

export const GENERATORS: Record<string, Generator> = {
// Default `algoliasearch` package as it's built similarly to generated clients
// Default `algoliasearch` package as it's an aggregation of generated clients
'javascript-algoliasearch': {
language: 'javascript',
client: 'algoliasearch',
key: 'javascript-algoliasearch',
additionalProperties: {
buildFile: 'algoliasearch',
packageName: '@experimental-api-clients-automation/algoliasearch',
packageName: 'algoliasearch',
packageVersion: getPackageVersionDefault('javascript'),
},
},
};

// Build `GENERATORS` from the openapitools file
Object.entries(openapiConfig['generator-cli'].generators).forEach(
([key, gen]) => {
([key, { output, ...gen }]) => {
const language = key.slice(0, key.indexOf('-')) as Language;

GENERATORS[key] = {
additionalProperties: {},
...gen,
output: gen.output.replace('#{cwd}/', ''),
...splitGeneratorKey(key),
output: output.replace('#{cwd}/', ''),
client: key.slice(key.indexOf('-') + 1),
language,
key,
};

if (language === 'javascript') {
GENERATORS[key].additionalProperties.packageName = output.substring(
output.lastIndexOf('/') + 1
);
}
}
);

Expand All @@ -77,17 +87,6 @@ export const CLIENTS = CLIENTS_JS.filter(
(client) => client !== 'algoliasearch'
);

/**
* Takes a generator key in the form 'language-client' and returns the Generator object.
*/
export function splitGeneratorKey(
generatorKey: string
): Pick<Generator, 'client' | 'key' | 'language'> {
const language = generatorKey.slice(0, generatorKey.indexOf('-')) as Language;
const client = generatorKey.slice(generatorKey.indexOf('-') + 1);
return { language, client, key: generatorKey };
}

export function createGeneratorKey({
language,
client,
Expand Down
29 changes: 29 additions & 0 deletions scripts/release/common.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fsp from 'fs/promises';
import path from 'path';

import config from '../../config/release.config.json';
Expand Down Expand Up @@ -45,3 +46,31 @@ export async function cloneRepository({
tempGitDir,
};
}

/**
* Reads a JSON file and returns its parsed data.
*
* @param ppath - The absolute path to the file.
*/
export async function readJsonFile(
ppath: string
): Promise<Record<string, any>> {
return JSON.parse(
await fsp.readFile(ppath, {
encoding: 'utf-8',
})
);
}

/**
* Writes `data` in a file at the given `ppath`, appends a newline at the end of the file.
*
* @param ppath - The absolute path to the file.
* @param data - The data to store.
*/
export async function writeJsonFile(
ppath: string,
data: Record<string, any>
): Promise<void> {
await fsp.writeFile(ppath, JSON.stringify(data, null, 2).concat('\n'));
}
Loading