Skip to content

Commit 6fdedfc

Browse files
authored
chore(csharp): test the support of multiple dotnet versions (#5620)
1 parent c88e91b commit 6fdedfc

32 files changed

+146
-80
lines changed

.github/workflows/check.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ jobs:
353353
[ $(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"
354354
355355
- name: Build the playground
356-
run: yarn cli build playground ${{ matrix.client.language }}
356+
run: yarn cli build playground ${{ matrix.client.language }} --language-version ${{ matrix.client.version }}
357357

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

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

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

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

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

clients/algoliasearch-client-csharp/.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Setup .NET
1717
uses: actions/setup-dotnet@v5
1818
with:
19-
global-json-file: global.json
19+
dotnet-version: 10.0.100
2020

2121
- name: Create Nugget package
2222
run: dotnet pack --configuration Release --output nugget

clients/algoliasearch-client-csharp/global.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

config/clients.config.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@
2727
"snippets": {
2828
"extension": ".cs",
2929
"outputFolder": "src"
30-
}
30+
},
31+
"supportedVersions": [
32+
"8.0.416",
33+
"9.0.307",
34+
"10.0.100"
35+
]
3136
},
3237
"dart": {
3338
"clients": [

config/clients.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
},
9494
"supportedVersions": {
9595
"type": "array",
96-
"description": "hints the CI on what matrix to generate for this client, this must be language specific versions, e.g. versions of node",
96+
"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",
9797
"items": { "type": "string" }
9898
}
9999
},

config/generation.config.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export const patterns = [
1616
// C#
1717
'clients/algoliasearch-client-csharp/**',
1818
'!clients/algoliasearch-client-csharp/*',
19-
'clients/algoliasearch-client-csharp/global.json',
2019
'!clients/algoliasearch-client-csharp/algoliasearch/Clients/AlgoliaConfig.cs',
2120
'!clients/algoliasearch-client-csharp/algoliasearch/Exceptions/**',
2221
'!clients/algoliasearch-client-csharp/algoliasearch/Serializer/**',
@@ -25,7 +24,7 @@ export const patterns = [
2524
'!clients/algoliasearch-client-csharp/algoliasearch/Transport/**',
2625
'!clients/algoliasearch-client-csharp/algoliasearch/Models/Common/**',
2726

28-
'tests/output/csharp/global.json',
27+
'tests/output/csharp/src/Algolia.Search.Tests.csproj',
2928

3029
// Dart
3130
'!clients/algoliasearch-client-dart/**',

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ public void processOpts() {
110110

111111
// repository
112112
supportingFiles.add(new SupportingFile("Solution.mustache", "../", "Algolia.Search.sln"));
113-
supportingFiles.add(new SupportingFile("globaljson.mustache", "../", "global.json"));
114113
supportingFiles.add(new SupportingFile("netcore_project.mustache", "Algolia.Search.csproj"));
115114
supportingFiles.add(new SupportingFile("Configuration.mustache", "Clients", packageName + "Configuration.cs"));
116115

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void processOpts() {
4444
language = (String) additionalProperties.get("language");
4545
client = (String) additionalProperties.get("client");
4646
mode = (String) additionalProperties.get("mode");
47-
ctsManager = CTSManagerFactory.getManager(language, client);
47+
ctsManager = CTSManagerFactory.getManager(language, client, (String) additionalProperties.getOrDefault("languageVersion", ""));
4848

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

165+
// Set some default values in the bundle
166+
bundle.put("packageVersion", ctsManager.getPackageVersion());
167+
165168
String languageVersion = ctsManager.getLanguageVersion((String) additionalProperties.getOrDefault("languageVersion", ""));
166169
bundle.put("languageVersion", languageVersion);
167170

generators/src/main/java/com/algolia/codegen/cts/manager/CSharpCTSManager.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
44
import com.algolia.codegen.exceptions.GeneratorException;
55
import com.algolia.codegen.utils.*;
66
import com.samskivert.mustache.Mustache.Lambda;
7+
import java.io.IOException;
78
import java.util.*;
89
import org.openapitools.codegen.SupportingFile;
910

1011
public class CSharpCTSManager implements CTSManager {
1112

1213
private final String client;
14+
private final String overrideLanguageVersion;
1315

14-
public CSharpCTSManager(String client) {
16+
public CSharpCTSManager(String client, String overrideLanguageVersion) {
1517
this.client = client;
18+
this.overrideLanguageVersion = overrideLanguageVersion;
1619
}
1720

1821
public String getLanguage() {
@@ -25,7 +28,9 @@ public String getClient() {
2528

2629
@Override
2730
public void addTestsSupportingFiles(List<SupportingFile> supportingFiles) {
28-
supportingFiles.add(new SupportingFile("globaljson.mustache", "tests/output/csharp", "global.json"));
31+
supportingFiles.add(
32+
new SupportingFile("tests/Algolia.Search.Tests.csproj.mustache", "tests/output/csharp/src", "Algolia.Search.Tests.csproj")
33+
);
2934
}
3035

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

4449
@Override
4550
public void addDataToBundle(Map<String, Object> bundle) throws GeneratorException {
46-
bundle.put("packageVersion", getVersion());
51+
try {
52+
String dotnetVersion = getLanguageVersion(overrideLanguageVersion);
53+
String[] parts = dotnetVersion.split("\\.");
54+
bundle.put("dotnetVersion", parts[0] + "." + parts[1]);
55+
} catch (IOException e) {
56+
throw new GeneratorException("Failed to compute dotnet version", e);
57+
}
4758
}
4859

4960
@Override

generators/src/main/java/com/algolia/codegen/cts/manager/CTSManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public default String getLanguageCased() {
1616
return Helpers.capitalize(getLanguage());
1717
}
1818

19-
public default String getVersion() {
19+
public default String getPackageVersion() {
2020
return Helpers.getClientConfigField(getLanguage(), "packageVersion");
2121
}
2222

0 commit comments

Comments
 (0)