From f903ebd12f4cd100508a5c3537dec662f77f8ec3 Mon Sep 17 00:00:00 2001 From: Pierre Millot Date: Fri, 13 May 2022 11:03:01 +0200 Subject: [PATCH] chore(scripts): factor git repo id (#499) --- config/clients.config.json | 3 + config/openapitools.json | 80 ------------------- .../algolia/codegen/AlgoliaJavaGenerator.java | 5 +- .../codegen/AlgoliaJavascriptGenerator.java | 3 +- .../algolia/codegen/AlgoliaPhpGenerator.java | 5 ++ scripts/common.ts | 30 ------- scripts/config.ts | 16 ++++ scripts/release/common.ts | 6 +- scripts/release/process-release.ts | 9 ++- 9 files changed, 40 insertions(+), 117 deletions(-) diff --git a/config/clients.config.json b/config/clients.config.json index 9a299d5690..776fddbf60 100644 --- a/config/clients.config.json +++ b/config/clients.config.json @@ -1,6 +1,7 @@ { "java": { "folder": "clients/algoliasearch-client-java-2", + "gitRepoId": "algoliasearch-client-java-2", "packageVersion": "0.0.1", "modelFolder": "algoliasearch-core/src/main/java/com/algolia/model", "apiFolder": "algoliasearch-core/src/main/java/com/algolia/api", @@ -12,6 +13,7 @@ }, "javascript": { "folder": "clients/algoliasearch-client-javascript", + "gitRepoId": "algoliasearch-client-javascript", "modelFolder": "model", "apiFolder": "src", "customGenerator": "algolia-javascript", @@ -22,6 +24,7 @@ }, "php": { "folder": "clients/algoliasearch-client-php", + "gitRepoId": "algoliasearch-client-php", "packageVersion": "0.0.1", "modelFolder": "lib/Model", "customGenerator": "algolia-php", diff --git a/config/openapitools.json b/config/openapitools.json index f69d91489b..cd8651ee2d 100644 --- a/config/openapitools.json +++ b/config/openapitools.json @@ -3,9 +3,7 @@ "version": "5.4.0", "generators": { "javascript-search": { - "apiPackage": "src", "output": "#{cwd}/clients/algoliasearch-client-javascript/packages/client-search", - "gitRepoId": "algoliasearch-client-javascript", "reservedWordsMappings": "queryParameters=queryParameters,requestOptions=requestOptions", "additionalProperties": { "npmName": "@experimental-api-clients-automation/client-search", @@ -16,9 +14,7 @@ } }, "javascript-algoliasearch-lite": { - "apiPackage": "src", "output": "#{cwd}/clients/algoliasearch-client-javascript/packages/algoliasearch-lite", - "gitRepoId": "algoliasearch-client-javascript", "reservedWordsMappings": "queryParameters=queryParameters,requestOptions=requestOptions", "additionalProperties": { "npmName": "@experimental-api-clients-automation/algoliasearch-lite", @@ -29,9 +25,7 @@ } }, "javascript-recommend": { - "apiPackage": "src", "output": "#{cwd}/clients/algoliasearch-client-javascript/packages/recommend", - "gitRepoId": "algoliasearch-client-javascript", "reservedWordsMappings": "queryParameters=queryParameters", "additionalProperties": { "npmName": "@experimental-api-clients-automation/recommend", @@ -42,9 +36,7 @@ } }, "javascript-personalization": { - "apiPackage": "src", "output": "#{cwd}/clients/algoliasearch-client-javascript/packages/client-personalization", - "gitRepoId": "algoliasearch-client-javascript", "additionalProperties": { "npmName": "@experimental-api-clients-automation/client-personalization", "buildFile": "client-personalization", @@ -55,9 +47,7 @@ } }, "javascript-analytics": { - "apiPackage": "src", "output": "#{cwd}/clients/algoliasearch-client-javascript/packages/client-analytics", - "gitRepoId": "algoliasearch-client-javascript", "additionalProperties": { "npmName": "@experimental-api-clients-automation/client-analytics", "buildFile": "client-analytics", @@ -68,9 +58,7 @@ } }, "javascript-insights": { - "apiPackage": "src", "output": "#{cwd}/clients/algoliasearch-client-javascript/packages/client-insights", - "gitRepoId": "algoliasearch-client-javascript", "additionalProperties": { "npmName": "@experimental-api-clients-automation/client-insights", "buildFile": "client-insights", @@ -81,9 +69,7 @@ } }, "javascript-abtesting": { - "apiPackage": "src", "output": "#{cwd}/clients/algoliasearch-client-javascript/packages/client-abtesting", - "gitRepoId": "algoliasearch-client-javascript", "additionalProperties": { "npmName": "@experimental-api-clients-automation/client-abtesting", "buildFile": "client-abtesting", @@ -94,9 +80,7 @@ } }, "javascript-query-suggestions": { - "apiPackage": "src", "output": "#{cwd}/clients/algoliasearch-client-javascript/packages/client-query-suggestions", - "gitRepoId": "algoliasearch-client-javascript", "additionalProperties": { "npmName": "@experimental-api-clients-automation/client-query-suggestions", "buildFile": "client-query-suggestions", @@ -107,9 +91,7 @@ } }, "javascript-sources": { - "apiPackage": "src", "output": "#{cwd}/clients/algoliasearch-client-javascript/packages/client-sources", - "gitRepoId": "algoliasearch-client-javascript", "additionalProperties": { "npmName": "@experimental-api-clients-automation/client-sources", "buildFile": "client-sources", @@ -121,9 +103,7 @@ }, "javascript-predict": { "templateDir": "#{cwd}/templates/javascript/", - "apiPackage": "src", "output": "#{cwd}/clients/algoliasearch-client-javascript/packages/client-predict", - "gitRepoId": "algoliasearch-client-javascript", "additionalProperties": { "npmName": "@experimental-api-clients-automation/client-predict", "buildFile": "client-predict", @@ -135,36 +115,21 @@ }, "java-search": { "output": "#{cwd}/clients/algoliasearch-client-java-2", - "groupId": "com.algolia", - "apiPackage": "com.algolia.api", - "invokerPackage": "com.algolia", "modelPackage": "com.algolia.model.search", - "library": "okhttp-gson", - "gitRepoId": "algoliasearch-client-java-2", "additionalProperties": { "packageName": "algoliasearch-client-java" } }, "java-recommend": { "output": "#{cwd}/clients/algoliasearch-client-java-2", - "groupId": "com.algolia", - "apiPackage": "com.algolia.api", - "invokerPackage": "com.algolia", "modelPackage": "com.algolia.model.recommend", - "library": "okhttp-gson", - "gitRepoId": "algoliasearch-client-java-2", "additionalProperties": { "packageName": "algoliasearch-client-java" } }, "java-personalization": { "output": "#{cwd}/clients/algoliasearch-client-java-2", - "groupId": "com.algolia", - "apiPackage": "com.algolia.api", - "invokerPackage": "com.algolia", "modelPackage": "com.algolia.model.personalization", - "library": "okhttp-gson", - "gitRepoId": "algoliasearch-client-java-2", "additionalProperties": { "packageName": "algoliasearch-client-java", "hasRegionalHost": true @@ -172,12 +137,7 @@ }, "java-analytics": { "output": "#{cwd}/clients/algoliasearch-client-java-2", - "groupId": "com.algolia", - "apiPackage": "com.algolia.api", - "invokerPackage": "com.algolia", "modelPackage": "com.algolia.model.analytics", - "library": "okhttp-gson", - "gitRepoId": "algoliasearch-client-java-2", "additionalProperties": { "packageName": "algoliasearch-client-java", "hasRegionalHost": true @@ -185,12 +145,7 @@ }, "java-insights": { "output": "#{cwd}/clients/algoliasearch-client-java-2", - "groupId": "com.algolia", - "apiPackage": "com.algolia.api", - "invokerPackage": "com.algolia", "modelPackage": "com.algolia.model.insights", - "library": "okhttp-gson", - "gitRepoId": "algoliasearch-client-java-2", "additionalProperties": { "packageName": "algoliasearch-client-java", "hasRegionalHost": true @@ -198,12 +153,7 @@ }, "java-abtesting": { "output": "#{cwd}/clients/algoliasearch-client-java-2", - "groupId": "com.algolia", - "apiPackage": "com.algolia.api", - "invokerPackage": "com.algolia", "modelPackage": "com.algolia.model.abtesting", - "library": "okhttp-gson", - "gitRepoId": "algoliasearch-client-java-2", "additionalProperties": { "packageName": "algoliasearch-client-java", "hasRegionalHost": true @@ -211,12 +161,7 @@ }, "java-query-suggestions": { "output": "#{cwd}/clients/algoliasearch-client-java-2", - "groupId": "com.algolia", - "apiPackage": "com.algolia.api", - "invokerPackage": "com.algolia", "modelPackage": "com.algolia.model.querySuggestions", - "library": "okhttp-gson", - "gitRepoId": "algoliasearch-client-java-2", "additionalProperties": { "packageName": "algoliasearch-client-java", "hasRegionalHost": true @@ -224,20 +169,13 @@ }, "java-predict": { "output": "#{cwd}/clients/algoliasearch-client-java-2", - "groupId": "com.algolia", - "apiPackage": "com.algolia.api", - "invokerPackage": "com.algolia", "modelPackage": "com.algolia.model.predict", - "library": "okhttp-gson", - "gitRepoId": "algoliasearch-client-java-2", "additionalProperties": { "packageName": "algoliasearch-client-java" } }, "php-search": { "output": "#{cwd}/clients/algoliasearch-client-php", - "gitRepoId": "algoliasearch-client-php", - "invokerPackage": "Algolia\\AlgoliaSearch", "modelPackage": "Model\\Search", "additionalProperties": { "packageName": "algoliasearch-client-php" @@ -245,8 +183,6 @@ }, "php-recommend": { "output": "#{cwd}/clients/algoliasearch-client-php", - "gitRepoId": "algoliasearch-client-php", - "invokerPackage": "Algolia\\AlgoliaSearch", "modelPackage": "Model\\Recommend", "additionalProperties": { "packageName": "algoliasearch-client-php" @@ -254,8 +190,6 @@ }, "php-personalization": { "output": "#{cwd}/clients/algoliasearch-client-php", - "gitRepoId": "algoliasearch-client-php", - "invokerPackage": "Algolia\\AlgoliaSearch", "modelPackage": "Model\\Personalization", "additionalProperties": { "packageName": "algoliasearch-client-php", @@ -264,8 +198,6 @@ }, "php-analytics": { "output": "#{cwd}/clients/algoliasearch-client-php", - "gitRepoId": "algoliasearch-client-php", - "invokerPackage": "Algolia\\AlgoliaSearch", "modelPackage": "Model\\Analytics", "additionalProperties": { "packageName": "algoliasearch-client-php", @@ -274,8 +206,6 @@ }, "php-insights": { "output": "#{cwd}/clients/algoliasearch-client-php", - "gitRepoId": "algoliasearch-client-php", - "invokerPackage": "Algolia\\AlgoliaSearch", "modelPackage": "Model\\Insights", "additionalProperties": { "packageName": "algoliasearch-client-php", @@ -284,8 +214,6 @@ }, "php-abtesting": { "output": "#{cwd}/clients/algoliasearch-client-php", - "gitRepoId": "algoliasearch-client-php", - "invokerPackage": "Algolia\\AlgoliaSearch", "modelPackage": "Model\\Abtesting", "additionalProperties": { "packageName": "algoliasearch-client-php", @@ -293,15 +221,7 @@ } }, "php-query-suggestions": { - "config": "#{cwd}/openapitools.json", - "gitHost": "algolia", - "gitUserId": "algolia", - "glob": "specs/bundled/query-suggestions.yml", - "templateDir": "#{cwd}/templates/php/", - "generatorName": "algolia-php", "output": "#{cwd}/clients/algoliasearch-client-php", - "gitRepoId": "algoliasearch-client-php", - "invokerPackage": "Algolia\\AlgoliaSearch", "modelPackage": "Model\\QuerySuggestions", "additionalProperties": { "packageName": "algoliasearch-client-php" diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java index 75d38def06..0d309227c0 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java @@ -111,8 +111,11 @@ public String getHelp() { public void processOpts() { // generator specific options setDateLibrary("java8"); + setLibrary("okhttp-gson"); setSourceFolder("algoliasearch-core/src/main/java"); - setInvokerPackage("com.algolia"); + setGroupId("com.algolia"); + additionalProperties.put("invokerPackage", "com.algolia"); + setApiPackage("com.algolia.api"); setApiNameSuffix(Utils.API_SUFFIX); super.processOpts(); diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java index ccad9607d5..cd331c13b3 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java @@ -26,7 +26,7 @@ public void processOpts() { // generator specific options setSupportsES6(true); setModelPropertyNaming("original"); - + setApiPackage("src"); // clear all supported files to avoid unwanted ones supportingFiles.clear(); // model @@ -60,6 +60,7 @@ private void setDefaultGeneratorOptions() { additionalProperties.put("apiName", apiName); additionalProperties.put("capitalizedApiName", Utils.capitalize(apiName)); additionalProperties.put("userAgent", Utils.capitalize(CLIENT)); + additionalProperties.put("gitRepoId", "algoliasearch-client-javascript"); } /** Provides an opportunity to inspect and modify operation data before the code is generated. */ diff --git a/generators/src/main/java/com/algolia/codegen/AlgoliaPhpGenerator.java b/generators/src/main/java/com/algolia/codegen/AlgoliaPhpGenerator.java index a1c7294814..51c6b93e10 100644 --- a/generators/src/main/java/com/algolia/codegen/AlgoliaPhpGenerator.java +++ b/generators/src/main/java/com/algolia/codegen/AlgoliaPhpGenerator.java @@ -72,6 +72,7 @@ public void processOpts() { // generator specific options setApiNameSuffix(Utils.API_SUFFIX); setParameterNamingConvention("camelCase"); + additionalProperties.put("invokerPackage", "Algolia\\AlgoliaSearch"); super.processOpts(); @@ -88,4 +89,8 @@ public void processOpts() { ) ); } + + public String getComposerPackageName() { + return "algolia/algoliasearch-client-php"; + } } diff --git a/scripts/common.ts b/scripts/common.ts index a060ca23fd..bf0bf875fd 100644 --- a/scripts/common.ts +++ b/scripts/common.ts @@ -86,36 +86,6 @@ export function splitGeneratorKey( return { language, client, key: generatorKey }; } -type GitHubUrl = ( - lang: string, - options?: { - token?: string; - } -) => string; - -export const getGitHubUrl: GitHubUrl = ( - lang: string, - { token } = {} -): string => { - const entry = Object.entries(openapiConfig['generator-cli'].generators).find( - (_entry) => _entry[0].startsWith(`${lang}-`) - ); - - if (!entry) { - throw new Error(`\`${lang}\` is not found from \`openapitools.json\`.`); - } - const { gitRepoId } = entry[1]; - - // GitHub Action provides a default token for authentication - // https://docs.github.com/en/actions/security-guides/automatic-token-authentication - // But it has access to only the self repository. - // If we want to do something like pushing commits to other repositories, - // we need to specify a token with more access. - return token - ? `https://${token}:${token}@github.com/algolia/${gitRepoId}` - : `https://github.com/algolia/${gitRepoId}`; -}; - export function createGeneratorKey({ language, client, diff --git a/scripts/config.ts b/scripts/config.ts index cdd9c39f93..f55dc0f791 100644 --- a/scripts/config.ts +++ b/scripts/config.ts @@ -35,3 +35,19 @@ export function getPackageVersionDefault(language: Language): string { } return clientsConfig[language].packageVersion; } + +export function getGitHubUrl( + language: Language, + options?: { token: string } +): string { + const { gitRepoId } = clientsConfig[language]; + + // GitHub Action provides a default token for authentication + // https://docs.github.com/en/actions/security-guides/automatic-token-authentication + // But it has access to only the self repository. + // If we want to do something like pushing commits to other repositories, + // we need to specify a token with more access. + return options?.token + ? `https://${options.token}:${options.token}@github.com/algolia/${gitRepoId}` + : `https://github.com/algolia/${gitRepoId}`; +} diff --git a/scripts/release/common.ts b/scripts/release/common.ts index f6432ca691..c0c21ee309 100644 --- a/scripts/release/common.ts +++ b/scripts/release/common.ts @@ -3,7 +3,9 @@ import path from 'path'; import { Octokit } from '@octokit/rest'; import config from '../../config/release.config.json'; -import { getGitHubUrl, run } from '../common'; +import { run } from '../common'; +import { getGitHubUrl } from '../config'; +import type { Language } from '../types'; export const RELEASED_TAG = config.releasedTag; export const TEAM_SLUG = config.teamSlug; @@ -50,7 +52,7 @@ export async function cloneRepository({ githubToken, tempDir, }: { - lang: string; + lang: Language; githubToken: string; tempDir: string; }): Promise<{ tempGitDir: string }> { diff --git a/scripts/release/process-release.ts b/scripts/release/process-release.ts index 8cde7e4c1d..b63e9909dc 100755 --- a/scripts/release/process-release.ts +++ b/scripts/release/process-release.ts @@ -13,7 +13,6 @@ import { toAbsolutePath, run, exists, - getGitHubUrl, gitCommit, OWNER, REPO, @@ -21,7 +20,11 @@ import { GENERATORS, LANGUAGES, } from '../common'; -import { getLanguageFolder, getPackageVersionDefault } from '../config'; +import { + getGitHubUrl, + getLanguageFolder, + getPackageVersionDefault, +} from '../config'; import type { Language } from '../types'; import { @@ -287,7 +290,7 @@ async function processRelease(): Promise { versionsToRelease )) { const { tempGitDir } = await cloneRepository({ - lang, + lang: lang as Language, githubToken: process.env.GITHUB_TOKEN, tempDir: process.env.RUNNER_TEMP!, });