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(all): factor the version into clients.config.json #496

Merged
merged 6 commits into from
May 12, 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
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/** Exception thrown in case of API failure such as 4XX, 5XX error. */
public class AlgoliaApiException extends AlgoliaRuntimeException {

public static final long serialVersionUID = -1L;
public static final long serialVersionUID = 1L;

public int getHttpErrorCode() {
return httpErrorCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
public class AlgoliaRetryException extends AlgoliaRuntimeException {

public static final long serialVersionUID = -1L;
public static final long serialVersionUID = 1L;

public AlgoliaRetryException(String message, Throwable cause) {
super(message, cause);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/** Exception thrown when an error occurs during the Serialization/Deserialization process */
public class AlgoliaRuntimeException extends RuntimeException {

public static final long serialVersionUID = -1L;
public static final long serialVersionUID = 1L;

public AlgoliaRuntimeException(String message, Throwable cause) {
super(message, cause);
Expand Down
5 changes: 2 additions & 3 deletions config/clients.config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"java": {
"folder": "clients/algoliasearch-client-java-2",
"mainPackage": "java-search",
eunjae-lee marked this conversation as resolved.
Show resolved Hide resolved
"packageVersion": "0.0.1",
"modelFolder": "algoliasearch-core/src/main/java/com/algolia/model",
"apiFolder": "algoliasearch-core/src/main/java/com/algolia/api",
"customGenerator": "algolia-java",
Expand All @@ -12,7 +12,6 @@
},
"javascript": {
"folder": "clients/algoliasearch-client-javascript",
"mainPackage": "javascript-search",
"modelFolder": "model",
"apiFolder": "src",
"customGenerator": "algolia-javascript",
Expand All @@ -23,7 +22,7 @@
},
"php": {
"folder": "clients/algoliasearch-client-php",
"mainPackage": "php-search",
"packageVersion": "0.0.1",
"modelFolder": "lib/Model",
"customGenerator": "algolia-php",
"apiFolder": "lib/Api",
Expand Down
27 changes: 6 additions & 21 deletions config/openapitools.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@
"library": "okhttp-gson",
"gitRepoId": "algoliasearch-client-java-2",
"additionalProperties": {
"packageName": "algoliasearch-client-java-2",
"packageVersion": "0.0.1"
"packageName": "algoliasearch-client-java-2"
}
},
"java-recommend": {
Expand All @@ -157,8 +156,7 @@
"library": "okhttp-gson",
"gitRepoId": "algoliasearch-client-java-2",
"additionalProperties": {
"packageName": "algoliasearch-client-java-2",
"packageVersion": "0.0.1"
"packageName": "algoliasearch-client-java-2"
}
},
"java-personalization": {
Expand All @@ -172,7 +170,6 @@
"gitRepoId": "algoliasearch-client-java-2",
"additionalProperties": {
"packageName": "algoliasearch-client-java-2",
"packageVersion": "0.0.1",
"hasRegionalHost": true
}
},
Expand All @@ -187,7 +184,6 @@
"gitRepoId": "algoliasearch-client-java-2",
"additionalProperties": {
"packageName": "algoliasearch-client-java-2",
"packageVersion": "0.0.1",
"hasRegionalHost": true
}
},
Expand All @@ -202,7 +198,6 @@
"gitRepoId": "algoliasearch-client-java-2",
"additionalProperties": {
"packageName": "algoliasearch-client-java-2",
"packageVersion": "0.0.1",
"hasRegionalHost": true
}
},
Expand All @@ -217,7 +212,6 @@
"gitRepoId": "algoliasearch-client-java-2",
"additionalProperties": {
"packageName": "algoliasearch-client-java-2",
"packageVersion": "0.0.1",
"hasRegionalHost": true
}
},
Expand All @@ -232,7 +226,6 @@
"gitRepoId": "algoliasearch-client-java-2",
"additionalProperties": {
"packageName": "algoliasearch-client-java-2",
"packageVersion": "0.0.1",
"hasRegionalHost": true
}
},
Expand All @@ -246,8 +239,7 @@
"library": "okhttp-gson",
"gitRepoId": "algoliasearch-client-java-2",
"additionalProperties": {
"packageName": "algoliasearch-client-java-2",
"packageVersion": "0.0.1"
"packageName": "algoliasearch-client-java-2"
}
},
"php-search": {
Expand All @@ -256,8 +248,7 @@
"invokerPackage": "Algolia\\AlgoliaSearch",
"modelPackage": "Model\\Search",
"additionalProperties": {
"packageName": "algoliasearch-client-php",
"packageVersion": "0.0.1"
"packageName": "algoliasearch-client-php"
}
},
"php-recommend": {
Expand All @@ -266,8 +257,7 @@
"invokerPackage": "Algolia\\AlgoliaSearch",
"modelPackage": "Model\\Recommend",
"additionalProperties": {
"packageName": "algoliasearch-client-php",
"packageVersion": "0.0.1"
"packageName": "algoliasearch-client-php"
}
},
"php-personalization": {
Expand All @@ -277,7 +267,6 @@
"modelPackage": "Model\\Personalization",
"additionalProperties": {
"packageName": "algoliasearch-client-php",
"packageVersion": "0.0.1",
"hasRegionalHost": true
}
},
Expand All @@ -288,7 +277,6 @@
"modelPackage": "Model\\Analytics",
"additionalProperties": {
"packageName": "algoliasearch-client-php",
"packageVersion": "0.0.1",
"hasRegionalHost": true
}
},
Expand All @@ -299,7 +287,6 @@
"modelPackage": "Model\\Insights",
"additionalProperties": {
"packageName": "algoliasearch-client-php",
"packageVersion": "0.0.1",
"hasRegionalHost": true
}
},
Expand All @@ -310,7 +297,6 @@
"modelPackage": "Model\\Abtesting",
"additionalProperties": {
"packageName": "algoliasearch-client-php",
"packageVersion": "0.0.1",
"hasRegionalHost": true
}
},
Expand All @@ -326,8 +312,7 @@
"invokerPackage": "Algolia\\AlgoliaSearch",
"modelPackage": "Model\\QuerySuggestions",
"additionalProperties": {
"packageName": "algoliasearch-client-php",
"packageVersion": "0.0.1"
"packageName": "algoliasearch-client-php"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,19 @@ public Map<String, Object> postProcessOperationsWithModels(
allModels
);

Utils.generateServer(
Utils.getClientNameKebabCase(results),
additionalProperties
);
try {
Utils.generateServer(
Utils.getClientNameKebabCase(results),
additionalProperties
);
additionalProperties.put(
"packageVersion",
Utils.getPackageVersion("java")
);
} catch (GenerationException e) {
e.printStackTrace();
System.exit(1);
}

return results;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,15 @@ public Map<String, Object> postProcessOperationsWithModels(
CLIENT = Utils.getClientNameCamelCase(results);

setDefaultGeneratorOptions();
Utils.generateServer(
Utils.getClientNameKebabCase(results),
additionalProperties
);
try {
Utils.generateServer(
Utils.getClientNameKebabCase(results),
additionalProperties
);
} catch (GenerationException e) {
e.printStackTrace();
System.exit(1);
}

List<CodegenOperation> operations =
((Map<String, List<CodegenOperation>>) results.get("operations")).get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,16 @@ public Map<String, Object> postProcessOperationsWithModels(
String client = Utils.getClientNameKebabCase(results);

setDefaultGeneratorOptions(client);
Utils.generateServer(client, additionalProperties);
try {
Utils.generateServer(client, additionalProperties);
additionalProperties.put(
"packageVersion",
Utils.getPackageVersion("php")
);
} catch (GenerationException e) {
e.printStackTrace();
System.exit(1);
}

return results;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ public class GenerationException extends Exception {
public GenerationException(String message) {
super(message);
}

public GenerationException(String message, Throwable cause) {
super(message, cause);
}
}
31 changes: 28 additions & 3 deletions generators/src/main/java/com/algolia/codegen/Utils.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.algolia.codegen;

import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.collect.Sets;
import io.swagger.v3.core.util.Json;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.*;
import org.openapitools.codegen.CodegenOperation;
Expand Down Expand Up @@ -72,7 +76,7 @@ public static String getClientNameCamelCase(Map<String, Object> data) {
public static void generateServer(
String clientKebab,
Map<String, Object> additionalProperties
) {
) throws GenerationException {
Yaml yaml = new Yaml();
try {
Map<String, Object> spec = yaml.load(
Expand Down Expand Up @@ -145,8 +149,29 @@ public static void generateServer(
allowedRegions.toArray(new String[0])
);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
throw new GenerationException("Couldn't generate servers", e);
}
}

// Get the package version from clients.config.json (doesn't work for JavaScript)
public static String getPackageVersion(String language)
throws GenerationException {
if (language.equals("javascript")) {
throw new GenerationException(
"Cannot use getPackageVersion with language=\"javascript\", " +
"read openapitools.json instead"
);
}
try {
JsonNode config = Json
.mapper()
.readTree(new File("config/clients.config.json"));
return config.get(language).get("packageVersion").asText();
} catch (IOException e) {
throw new GenerationException(
"Couldn't read packageVersion from clients.config.json",
e
);
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@algolia/api-client-automation",
"version": "0.0.0",
"version": "0.0.1",
"private": true,
"workspaces": [
"clients/algoliasearch-client-javascript/",
Expand Down
11 changes: 2 additions & 9 deletions scripts/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import execa from 'execa'; // https://github.com/sindresorhus/execa/tree/v5.1.1
import { hashElement } from 'folder-hash';
import { remove } from 'fs-extra';

import clientsConfig from '../config/clients.config.json';
import openapiConfig from '../config/openapitools.json';
import releaseConfig from '../config/release.config.json';

import { getPackageVersionDefault } from './config';
import { createSpinner } from './oraLog';
import type {
CheckForCache,
Expand Down Expand Up @@ -41,10 +41,7 @@ export const GENERATORS: Record<string, Generator> = {
additionalProperties: {
buildFile: 'algoliasearch',
packageName: '@experimental-api-clients-automation/algoliasearch',
packageVersion:
openapiConfig['generator-cli'].generators[
clientsConfig.javascript.mainPackage
].additionalProperties.packageVersion,
packageVersion: getPackageVersionDefault('javascript'),
},
},
};
Expand All @@ -60,10 +57,6 @@ Object.entries(openapiConfig['generator-cli'].generators).forEach(
}
);

export function getPackageVersion(generator: string): string {
return GENERATORS[generator].additionalProperties.packageVersion;
}

export const LANGUAGES = [
...new Set(Object.values(GENERATORS).map((gen) => gen.language)),
];
Expand Down
10 changes: 10 additions & 0 deletions scripts/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import clientsConfig from '../config/clients.config.json';
import openapiConfig from '../config/openapitools.json';

import type { Language } from './types';

Expand All @@ -25,3 +26,12 @@ export function getTestOutputFolder(language: Language): string {
export function getCustomGenerator(language: Language): string {
return clientsConfig[language].customGenerator;
}

// Returns the version of the package from clients.config.json, except for JavaScript where it returns the version of javascript-search
export function getPackageVersionDefault(language: Language): string {
Copy link
Member

Choose a reason for hiding this comment

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

Can we add a description with the case for js pls?

if (language === 'javascript') {
return openapiConfig['generator-cli'].generators['javascript-search']
.additionalProperties.packageVersion;
}
return clientsConfig[language].packageVersion;
}
10 changes: 0 additions & 10 deletions scripts/release/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,11 @@ import path from 'path';

import { Octokit } from '@octokit/rest';

import clientsConfig from '../../config/clients.config.json';
import config from '../../config/release.config.json';
import { getGitHubUrl, run } from '../common';

export const RELEASED_TAG = config.releasedTag;
export const TEAM_SLUG = config.teamSlug;
export const MAIN_PACKAGE = Object.keys(clientsConfig).reduce(
(mainPackage: { [lang: string]: string }, lang: string) => {
return {
...mainPackage,
[lang]: clientsConfig[lang].mainPackage,
};
},
{}
);

export function getOctokit(githubToken: string): Octokit {
return new Octokit({
Expand Down
Loading