Skip to content

Commit f0ed6ec

Browse files
authored
chore(playgroud): add a build playground step (#3420)
1 parent 6cf1c80 commit f0ed6ec

File tree

17 files changed

+72
-33
lines changed

17 files changed

+72
-33
lines changed

.github/workflows/check.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ jobs:
213213
- name: Build clients
214214
run: ${{ fromJSON(needs.setup.outputs.JAVASCRIPT_DATA).buildCommand }}
215215

216+
- name: Build the playground
217+
run: yarn cli build playground javascript
218+
216219
- name: Run common and requester tests
217220
run: cd clients/algoliasearch-client-javascript && yarn test ${{ !contains(fromJSON(needs.setup.outputs.JAVASCRIPT_DATA).toRun, 'algoliasearch') && '--ignore algoliasearch' || '' }}
218221

@@ -323,6 +326,9 @@ jobs:
323326
- name: Build clients
324327
run: ${{ matrix.client.buildCommand }}
325328

329+
- name: Build the playground
330+
run: yarn cli build playground ${{ matrix.client.language }}
331+
326332
- name: Run Java 'algoliasearch' public API validation
327333
if: ${{ matrix.client.language == 'java' }}
328334
run: |

playground/csharp/Playground/Playgrounds/Ingestion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public async Task Run()
2727
{
2828
// Get existing JSON source
2929
Console.WriteLine("--- Get existing JSON source `GetSourcesAsync` ---");
30-
var jsonSources = await _client.GetSourcesAsync(type: [SourceType.Json]).ConfigureAwait(false);
30+
var jsonSources = await _client.ListSourcesAsync(type: [SourceType.Json]).ConfigureAwait(false);
3131
Console.WriteLine(jsonSources.Sources.Count == 0
3232
? "There is no JSON Source !"
3333
: $"There is {jsonSources.Sources.Count} JSON source(s)");

playground/csharp/Playground/Playgrounds/Search.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,20 +184,20 @@ private async Task ApiKey()
184184
Indexes = [DefaultIndex]
185185
});
186186
var createdApiKey = await PlaygroundHelper.Start($"Saving new API Key", async () =>
187-
await _client.WaitForApiKeyAsync(ApiKeyOperation.Add, addApiKeyResponse.Key), "New key has been created !");
187+
await _client.WaitForApiKeyAsync(addApiKeyResponse.Key, ApiKeyOperation.Add), "New key has been created !");
188188

189189
Console.WriteLine("--- Update api key `UpdateApiKeyAsync` ---");
190190
var modifiedApiKey = createdApiKey.ToApiKey();
191191
modifiedApiKey.Description = "Updated description";
192192

193193
var updateApiKey = await _client.UpdateApiKeyAsync(addApiKeyResponse.Key, modifiedApiKey);
194194
await PlaygroundHelper.Start("Updating API Key`", async () =>
195-
await _client.WaitForApiKeyAsync(ApiKeyOperation.Update, updateApiKey.Key, modifiedApiKey), "Key updated !");
195+
await _client.WaitForApiKeyAsync(updateApiKey.Key, ApiKeyOperation.Update, modifiedApiKey), "Key updated !");
196196

197197
Console.WriteLine("--- Delete api key `UpdateApiKeyAsync` ---");
198198
await _client.DeleteApiKeyAsync(addApiKeyResponse.Key);
199199
await PlaygroundHelper.Start("Deleting API Key", async () =>
200-
await _client.WaitForApiKeyAsync(ApiKeyOperation.Delete, updateApiKey.Key), "Key deleted !");
200+
await _client.WaitForApiKeyAsync(updateApiKey.Key, ApiKeyOperation.Delete), "Key deleted !");
201201

202202
Console.WriteLine("--- Generate Secured API Keys `GenerateSecuredApiKeys` ---");
203203
var generateSecuredApiKeys = _client.GenerateSecuredApiKey(_configuration.SearchApiKey,

playground/javascript/node/ingestion.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const client = ingestionClient(appId, apiKey, 'us', {authMode: 'WithinHeaders',
1414

1515
async function testIngestion() {
1616
try {
17-
const res = await client.getAuthentications();
17+
const res = await client.listAuthentications();
1818

1919
console.log(`[OK]`, res);
2020
} catch (e) {

playground/javascript/node/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"start:query-suggestions": "tsc && node dist/query-suggestions.js",
1313
"start:recommend": "tsc && node dist/recommend.js",
1414
"start:search": "tsc && node dist/search.js",
15-
"start:sources": "tsc && node dist/sources.js"
15+
"start:sources": "tsc && node dist/sources.js",
16+
"build": "tsc"
1617
},
1718
"dependencies": {
1819
"@algolia/client-abtesting": "link:../../../clients/algoliasearch-client-javascript/packages/client-abtesting",

playground/kotlin/src/main/kotlin/com/algolia/playground/Ingestion.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ suspend fun main() {
1515
options = ClientOptions(logLevel = LogLevel.BODY),
1616
)
1717

18-
val response = client.getAuthentications()
18+
val response = client.listAuthentications()
1919
println(response)
2020

2121
exitProcess(0)

playground/kotlin/src/main/kotlin/com/algolia/playground/Recommend.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package com.algolia.playground
33
import com.algolia.client.api.RecommendClient
44
import com.algolia.client.configuration.ClientOptions
55
import com.algolia.client.model.recommend.GetRecommendationsParams
6-
import com.algolia.client.model.recommend.RecommendationModels
7-
import com.algolia.client.model.recommend.RecommendationsQuery
6+
import com.algolia.client.model.recommend.FbtModel
7+
import com.algolia.client.model.recommend.BoughtTogetherQuery
88
import io.github.cdimascio.dotenv.Dotenv
99
import io.ktor.client.plugins.logging.*
1010
import kotlin.system.exitProcess
@@ -24,11 +24,11 @@ suspend fun main() {
2424
val recommendations = client.getRecommendations(
2525
getRecommendationsParams = GetRecommendationsParams(
2626
requests = listOf(
27-
RecommendationsQuery(
27+
BoughtTogetherQuery(
2828
indexName = searchIndex,
29-
model = RecommendationModels.BoughtTogether,
29+
model = FbtModel.BoughtTogether,
3030
objectID = "6445156",
31-
threshold = 0,
31+
threshold = 0.0,
3232
)
3333
)
3434
)

playground/scala/src/main/scala/search.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ def main(): Unit = {
4040
val value = Await.result(res, Duration(100, "sec"))
4141
val response = value.results.head.asInstanceOf[SearchResponse]
4242
for (hit <- response.hits) {
43-
val actor = hit.extract[Actor]
44-
println(actor)
43+
//val actor = hit.extract[Actor]
44+
//println(actor)
4545
}
4646
}
4747

scripts/.eslintrc.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,6 @@ module.exports = {
4444
complexity: 0,
4545
'no-param-reassign': 0,
4646
'@typescript-eslint/consistent-type-assertions': 0,
47+
curly: ['error', 'all'],
4748
},
4849
};

scripts/buildClients.ts

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,29 @@ import { createSpinner } from './spinners.js';
44
import type { Generator, Language } from './types.js';
55

66
/**
7-
* Build client for a language at the same time, for those who live in the same folder.
7+
* Build code for a specific language.
88
*/
9-
async function buildClient(language: Language, gens: Generator[]): Promise<void> {
10-
const cwd = getLanguageFolder(language);
11-
const spinner = createSpinner(`building '${language}'`);
9+
async function buildLanguage(
10+
language: Language,
11+
gens: Generator[],
12+
playground: boolean,
13+
): Promise<void> {
14+
const cwd = playground ? `playground/${language}` : getLanguageFolder(language);
15+
const spinner = createSpinner(`building ${playground ? 'playground' : 'client'} '${language}'`);
1216
switch (language) {
1317
case 'csharp':
1418
await run('dotnet build --configuration Release', { cwd, language });
1519
break;
1620
case 'javascript':
17-
// eslint-disable-next-line no-case-declarations
18-
const packageNames = gens.map(({ additionalProperties: { packageName } }) =>
19-
packageName === 'algoliasearch' ? packageName : `@algolia/${packageName}`,
20-
);
21-
2221
await run('YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install', { cwd });
23-
await run(`yarn build:many '{${packageNames.join(',')},}'`, { cwd });
22+
if (playground) {
23+
await run('cd node && yarn build', { cwd });
24+
} else {
25+
const packageNames = gens.map(({ additionalProperties: { packageName } }) =>
26+
packageName === 'algoliasearch' ? packageName : `@algolia/${packageName}`,
27+
);
28+
await run(`yarn build:many '{${packageNames.join(',')},}'`, { cwd });
29+
}
2430

2531
break;
2632
case 'java':
@@ -34,7 +40,10 @@ async function buildClient(language: Language, gens: Generator[]): Promise<void>
3440
await run(`sbt --batch -Dsbt.server.forcestart=true +compile`, { cwd, language });
3541
break;
3642
case 'swift':
37-
await run(`swift build -Xswiftc -suppress-warnings`, { cwd, language });
43+
// make this work in the playground
44+
if (!playground) {
45+
await run(`swift build -Xswiftc -suppress-warnings`, { cwd, language });
46+
}
3847
break;
3948
default:
4049
}
@@ -56,5 +65,9 @@ export async function buildClients(generators: Generator[]): Promise<void> {
5665
{} as Record<Language, Generator[]>,
5766
);
5867

59-
await Promise.all(langs.map((lang) => buildClient(lang, generatorsMap[lang])));
68+
await Promise.all(langs.map((lang) => buildLanguage(lang, generatorsMap[lang], false)));
69+
}
70+
71+
export async function buildPlaygrounds(languages: Language[]): Promise<void> {
72+
await Promise.all(languages.map((lang) => buildLanguage(lang, [], true)));
6073
}

0 commit comments

Comments
 (0)