Skip to content
Open
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
6 changes: 3 additions & 3 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ jobs:
[ $(find Sources -type f | rev | cut -d '/' -f1 | rev | sort | uniq -d | wc -l) -gt 0 ] && echo "Duplicates found" && exit 1 || echo "No duplicate found"
- name: Build the playground
run: yarn cli build playground ${{ matrix.client.language }}
run: yarn cli build playground ${{ matrix.client.language }} --language-version ${{ matrix.client.version }}

- name: Run Java 'algoliasearch' public API validation
id: breakingChanges
Expand Down Expand Up @@ -397,13 +397,13 @@ jobs:
run: yarn cli cts run ${{ matrix.client.language }} --benchmark --no-client --no-requests --no-e2e

- name: Generate code snippets
run: yarn cli snippets ${{ matrix.client.language }}
run: yarn cli snippets ${{ matrix.client.language }} --language-version ${{ matrix.client.version }}

- name: Build the snippets to check validity
run: yarn cli build snippets ${{ matrix.client.language }}

- name: Generate code guides
run: yarn cli guides ${{ matrix.client.language }}
run: yarn cli guides ${{ matrix.client.language }} ${{ matrix.client.language != 'java' && format('--language-version {0}', matrix.client.version) || '' }}

- name: Build the guides to check validity
run: yarn cli build guides ${{ matrix.client.language }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
global-json-file: global.json
dotnet-version: 10.0.100

- name: Create Nugget package
run: dotnet pack --configuration Release --output nugget
Expand Down
6 changes: 0 additions & 6 deletions clients/algoliasearch-client-csharp/global.json

This file was deleted.

7 changes: 6 additions & 1 deletion config/clients.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@
"snippets": {
"extension": ".cs",
"outputFolder": "src"
}
},
"supportedVersions": [
"8.0.416",
"9.0.307",
"10.0.100"
]
},
"dart": {
"clients": [
Expand Down
2 changes: 1 addition & 1 deletion config/clients.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
},
"supportedVersions": {
"type": "array",
"description": "hints the CI on what matrix to generate for this client, this must be language specific versions, e.g. versions of node",
"description": "hints the CI on what matrix to generate for this client, this must be language specific versions, e.g. versions of node. The last item is the version that will be released",
"items": { "type": "string" }
}
},
Expand Down
3 changes: 1 addition & 2 deletions config/generation.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export const patterns = [
// C#
'clients/algoliasearch-client-csharp/**',
'!clients/algoliasearch-client-csharp/*',
'clients/algoliasearch-client-csharp/global.json',
'!clients/algoliasearch-client-csharp/algoliasearch/Clients/AlgoliaConfig.cs',
'!clients/algoliasearch-client-csharp/algoliasearch/Exceptions/**',
'!clients/algoliasearch-client-csharp/algoliasearch/Serializer/**',
Expand All @@ -25,7 +24,7 @@ export const patterns = [
'!clients/algoliasearch-client-csharp/algoliasearch/Transport/**',
'!clients/algoliasearch-client-csharp/algoliasearch/Models/Common/**',

'tests/output/csharp/global.json',
'tests/output/csharp/src/Algolia.Search.Tests.csproj',

// Dart
'!clients/algoliasearch-client-dart/**',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ public void processOpts() {

// repository
supportingFiles.add(new SupportingFile("Solution.mustache", "../", "Algolia.Search.sln"));
supportingFiles.add(new SupportingFile("globaljson.mustache", "../", "global.json"));
supportingFiles.add(new SupportingFile("netcore_project.mustache", "Algolia.Search.csproj"));
supportingFiles.add(new SupportingFile("Configuration.mustache", "Clients", packageName + "Configuration.cs"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void processOpts() {
language = (String) additionalProperties.get("language");
client = (String) additionalProperties.get("client");
mode = (String) additionalProperties.get("mode");
ctsManager = CTSManagerFactory.getManager(language, client);
ctsManager = CTSManagerFactory.getManager(language, client, (String) additionalProperties.getOrDefault("languageVersion", ""));

if (ctsManager == null) {
// skip the generation
Expand Down Expand Up @@ -162,6 +162,9 @@ public Map<String, Object> postProcessSupportingFileData(Map<String, Object> obj
ctsManager.addMustacheLambdas(lambda);
bundle.put("lambda", lambda);

// Set some default values in the bundle
bundle.put("packageVersion", ctsManager.getPackageVersion());

String languageVersion = ctsManager.getLanguageVersion((String) additionalProperties.getOrDefault("languageVersion", ""));
bundle.put("languageVersion", languageVersion);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
import com.algolia.codegen.exceptions.GeneratorException;
import com.algolia.codegen.utils.*;
import com.samskivert.mustache.Mustache.Lambda;
import java.io.IOException;
import java.util.*;
import org.openapitools.codegen.SupportingFile;

public class CSharpCTSManager implements CTSManager {

private final String client;
private final String overrideLanguageVersion;

public CSharpCTSManager(String client) {
public CSharpCTSManager(String client, String overrideLanguageVersion) {
this.client = client;
this.overrideLanguageVersion = overrideLanguageVersion;
}

public String getLanguage() {
Expand All @@ -25,7 +28,9 @@ public String getClient() {

@Override
public void addTestsSupportingFiles(List<SupportingFile> supportingFiles) {
supportingFiles.add(new SupportingFile("globaljson.mustache", "tests/output/csharp", "global.json"));
supportingFiles.add(
new SupportingFile("tests/Algolia.Search.Tests.csproj.mustache", "tests/output/csharp/src", "Algolia.Search.Tests.csproj")
);
}

@Override
Expand All @@ -43,7 +48,13 @@ public void addSnippetsSupportingFiles(List<SupportingFile> supportingFiles, Str

@Override
public void addDataToBundle(Map<String, Object> bundle) throws GeneratorException {
bundle.put("packageVersion", getVersion());
try {
String dotnetVersion = getLanguageVersion(overrideLanguageVersion);
String[] parts = dotnetVersion.split("\\.");
bundle.put("dotnetVersion", parts[0] + "." + parts[1]);
} catch (IOException e) {
throw new GeneratorException("Failed to compute dotnet version", e);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public default String getLanguageCased() {
return Helpers.capitalize(getLanguage());
}

public default String getVersion() {
public default String getPackageVersion() {
return Helpers.getClientConfigField(getLanguage(), "packageVersion");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ private CTSManagerFactory() {
// NO-OP
}

public static CTSManager getManager(String language, String client) {
public static CTSManager getManager(String language, String client, String overrideLanguageVersion) {
return switch (language) {
case "javascript" -> new JavascriptCTSManager(client);
case "java" -> new JavaCTSManager(client);
Expand All @@ -17,7 +17,7 @@ public static CTSManager getManager(String language, String client) {
case "ruby" -> new RubyCTSManager(client);
case "scala" -> new ScalaCTSManager(client);
case "python" -> new PythonCTSManager(client);
case "csharp" -> new CSharpCTSManager(client);
case "csharp" -> new CSharpCTSManager(client, overrideLanguageVersion);
case "swift" -> new SwiftCTSManager(client);
default -> null;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public String getClient() {

@Override
public void addDataToBundle(Map<String, Object> bundle) throws GeneratorException {
bundle.put("packageVersion", getVersion());
if (client.equals("algoliasearch")) {
bundle.put("import", "package:algoliasearch/algoliasearch_lite.dart");
bundle.put("client", "SearchClient");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ public String getClient() {

@Override
public String getLanguageVersion(String override) throws IOException {
if (override != null && !override.isEmpty()) {
return override.split("\\.")[0];
}

return Helpers.getLanguageVersion(getLanguage()).split("\\.")[0];
return CTSManager.super.getLanguageVersion(override).split("\\.")[0];
}

@Override
Expand All @@ -46,7 +42,6 @@ public void addSnippetsSupportingFiles(List<SupportingFile> supportingFiles, Str

@Override
public void addDataToBundle(Map<String, Object> bundle) throws GeneratorException {
bundle.put("packageVersion", getVersion());
bundle.put("import", Helpers.camelize(this.client).toLowerCase());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public String getClient() {
return client;
}

public String getVersion() {
public String getPackageVersion() {
return Helpers.getPackageJsonVersion(AlgoliaJavascriptGenerator.getPackageName(client));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public void addSnippetsSupportingFiles(List<SupportingFile> supportingFiles, Str

@Override
public void addDataToBundle(Map<String, Object> bundle) throws GeneratorException {
bundle.put("packageVersion", getVersion());
bundle.put("import", Helpers.camelize(this.client).toLowerCase());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public String getClient() {

@Override
public void addDataToBundle(Map<String, Object> bundle) throws GeneratorException {
bundle.put("packageVersion", getVersion());
bundle.put("modelModule", Helpers.capitalize(Helpers.camelize(client)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private String injectVariables(String json) {
return json
.replace("${{language}}", language)
.replace("${{languageCased}}", ctsManager.getLanguageCased())
.replace("${{languageVersion}}", ctsManager.getVersion())
.replace("${{languageVersion}}", ctsManager.getPackageVersion())
.replace("${{clientPascalCase}}", Helpers.capitalize(Helpers.camelize(Helpers.getClientConfigClientName(client))))
.replace("\"${{nowRounded}}\"", String.valueOf(Math.round(System.currentTimeMillis() / threeDays) * threeDays));
}
Expand Down
2 changes: 1 addition & 1 deletion playground/csharp/Performances/Performances.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Performances</RootNamespace>
Expand Down
2 changes: 1 addition & 1 deletion playground/csharp/Playground/Playground.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<TargetFramework>net9</TargetFramework>
<LangVersion>12</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
1 change: 0 additions & 1 deletion renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@
"**/ingestion/**",
"**/monitoring/**",
"**/recommend/**",
"clients/algoliasearch-client-csharp/global.json",
"clients/algoliasearch-client-php/composer.json",
"tests/output/dart/**",
"tests/output/java/**",
Expand Down
16 changes: 13 additions & 3 deletions scripts/buildLanguages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { existsSync } from 'node:fs';
import { createClientName, run, toAbsolutePath } from './common.ts';
import { getLanguageFolder, getSwiftBuildFolder } from './config.ts';
import { formatter } from './formatter.ts';
import { updatePlaygroundLanguageVersion } from './playground.ts';
import { createSpinner } from './spinners.ts';
import type { Generator, Language } from './types.ts';

Expand All @@ -26,11 +27,20 @@ function getFolder(buildType: BuildType, language: Language): string {
/**
* Build code for a specific language.
*/
async function buildLanguage(language: Language, gens: Generator[], buildType: BuildType): Promise<void> {
async function buildLanguage(
language: Language,
gens: Generator[],
buildType: BuildType,
languageVersion = '',
): Promise<void> {
if (!gens || gens.length === 0) {
return;
}

if (buildType === 'playground' && languageVersion) {
await updatePlaygroundLanguageVersion(language, languageVersion);
}

const cwd = getFolder(buildType, language);
const spinner = createSpinner(`building ${buildType} for '${language}'`);
switch (language) {
Expand Down Expand Up @@ -98,7 +108,7 @@ async function buildLanguage(language: Language, gens: Generator[], buildType: B
spinner.succeed();
}

export async function buildLanguages(generators: Generator[], scope: BuildType): Promise<void> {
export async function buildLanguages(generators: Generator[], scope: BuildType, languageVersion = ''): Promise<void> {
const langs = [...new Set(generators.map((gen) => gen.language))];
const generatorsMap = generators.reduce(
(map, gen) => {
Expand All @@ -118,5 +128,5 @@ export async function buildLanguages(generators: Generator[], scope: BuildType):
{} as Record<Language, Generator[]>,
);

await Promise.all(langs.map((lang) => buildLanguage(lang, generatorsMap[lang], scope)));
await Promise.all(langs.map((lang) => buildLanguage(lang, generatorsMap[lang], scope, languageVersion)));
}
2 changes: 1 addition & 1 deletion scripts/ci/githubActions/createMatrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async function createClientMatrix(baseBranch: string): Promise<void> {
// language specific options
switch (language) {
case 'csharp':
languageMatrix.testsToStore = `${languageMatrix.testsToStore} ${testsRootFolder}/global.json`;
languageMatrix.testsToStore = `${languageMatrix.testsToStore} ${testsRootFolder}/src/Algolia.Search.Tests.csproj`;
break;
case 'go':
languageMatrix.testsToStore = `${languageMatrix.testsToStore} ${testsOutputBase}/echo.go ${testsRootFolder}/go.sum ${testsRootFolder}/go.mod`;
Expand Down
Loading