From acfc9fb7e065777693c17d181f0e40ae43c56ee1 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Mon, 1 Jul 2024 15:37:51 +0200 Subject: [PATCH 1/8] fix(ci): kotlin on macos --- .github/workflows/check.yml | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 014fa7a8a8..dc11270b48 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -320,6 +320,38 @@ jobs: name: clients-${{matrix.client.language }} path: clients-${{matrix.client.language }}.zip + kotlin_build_macos: + timeout-minutes: 10 + runs-on: macos-latest + needs: + - setup + - client_gen + if: | + always() && + !contains(needs.*.result, 'cancelled') && + !contains(needs.*.result, 'failure') + env: + ALGOLIA_APPLICATION_ID: ${{ secrets.ALGOLIA_APPLICATION_ID }} + ALGOLIA_ADMIN_KEY: ${{ secrets.ALGOLIA_ADMIN_KEY }} + MONITORING_API_KEY: ${{ secrets.MONITORING_API_KEY }} + steps: + - uses: actions/checkout@v4 + + - name: Download artifacts + uses: ./scripts/ci/actions/restore-artifacts + with: + type: languages + languages: | + kotlin + + - name: Setup + uses: ./.github/actions/setup + with: + language: kotlin + + - name: Run CTS + run: yarn cli build clients kotlin + swift_cts_macos: timeout-minutes: 20 runs-on: macos-latest @@ -364,9 +396,9 @@ jobs: - client_gen - client_gen_javascript - swift_cts_macos + - kotlin_build_macos if: | always() && - (needs.swift_cts_macos.result == 'success' || needs.swift_cts_macos.result == 'skipped') && !contains(needs.*.result, 'cancelled') && !contains(needs.*.result, 'failure') outputs: From cba16dc165d95969dccec851b350150c21915138 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Mon, 1 Jul 2024 16:16:09 +0200 Subject: [PATCH 2/8] fix: only run kotlin --- .github/workflows/check.yml | 10 ++++++---- scripts/.eslintrc.cjs | 1 + scripts/ci/githubActions/createMatrix.ts | 11 +++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 07b581321e..e4ba7a2d69 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -117,6 +117,8 @@ jobs: SWIFT_DATA: ${{ steps.gen-matrix.outputs.SWIFT_DATA }} RUN_MACOS_SWIFT_CTS: ${{ steps.gen-matrix.outputs.RUN_MACOS_SWIFT_CTS }} + RUN_MACOS_KOTLIN_BUILD: ${{ steps.gen-matrix.outputs.RUN_MACOS_KOTLIN_BUILD }} + scripts: runs-on: ubuntu-22.04 timeout-minutes: 10 @@ -346,6 +348,7 @@ jobs: - client_gen if: | always() && + needs.setup.outputs.RUN_MACOS_KOTLIN_BUILD == 'true' && !contains(needs.*.result, 'cancelled') && !contains(needs.*.result, 'failure') env: @@ -365,10 +368,10 @@ jobs: - name: Setup uses: ./.github/actions/setup with: + type: minimal language: kotlin - - name: Run CTS - run: yarn cli build clients kotlin + - run: yarn cli build clients kotlin swift_cts_macos: timeout-minutes: 20 @@ -403,8 +406,7 @@ jobs: type: minimal language: swift - - name: Run CTS - run: yarn cli cts run swift ${{ fromJSON(needs.setup.outputs.SWIFT_DATA).toRun }} + - run: yarn cli cts run swift ${{ fromJSON(needs.setup.outputs.SWIFT_DATA).toRun }} codegen: runs-on: ubuntu-22.04 diff --git a/scripts/.eslintrc.cjs b/scripts/.eslintrc.cjs index 0cb86820a2..60ab493a7b 100644 --- a/scripts/.eslintrc.cjs +++ b/scripts/.eslintrc.cjs @@ -41,6 +41,7 @@ module.exports = { }, ], '@typescript-eslint/sort-type-union-intersection-members': 0, + complexity: 0, 'no-param-reassign': 0, '@typescript-eslint/consistent-type-assertions': 0, }, diff --git a/scripts/ci/githubActions/createMatrix.ts b/scripts/ci/githubActions/createMatrix.ts index d741b12110..c3a448f2d6 100644 --- a/scripts/ci/githubActions/createMatrix.ts +++ b/scripts/ci/githubActions/createMatrix.ts @@ -19,6 +19,10 @@ async function createClientMatrix(baseBranch: string): Promise { // iterate over every generators to see what changed for (const { language, client, output } of Object.values(GENERATORS)) { + if (language !== 'kotlin') { + continue; + } + const bundledSpec = client === 'algoliasearch' ? 'search' : client; if (!commonDependenciesChanged) { @@ -143,6 +147,13 @@ async function createClientMatrix(baseBranch: string): Promise { core.setOutput('RUN_MACOS_SWIFT_CTS', true); } + // If there are updates for the Kotlin client, we allow ourselves to run the build step on macOS + const runKotlin = clientMatrix.client.find((c) => c.language === 'kotlin'); + if (runKotlin) { + core.setOutput('SWIFT_DATA', JSON.stringify(swiftData)); + core.setOutput('RUN_MACOS_KOTLIN_BUILD', true); + } + const javascriptData = clientMatrix.client.find((c) => c.language === 'javascript'); if (javascriptData) { core.setOutput('JAVASCRIPT_DATA', JSON.stringify(javascriptData)); From 26e8e4d0bba238ff383b90781a74bfa542ac85bb Mon Sep 17 00:00:00 2001 From: shortcuts Date: Mon, 1 Jul 2024 16:44:51 +0200 Subject: [PATCH 3/8] fix: java stuff --- .../com/algolia/client/extensions/internal/SearchClient.kt | 7 +++---- .../kotlin/com/algolia/client/TestSecureApiKey.kt | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/extensions/internal/SearchClient.kt b/clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/extensions/internal/SearchClient.kt index c472445cc3..11014b4e70 100644 --- a/clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/extensions/internal/SearchClient.kt +++ b/clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/extensions/internal/SearchClient.kt @@ -7,14 +7,13 @@ import io.ktor.http.* import kotlinx.serialization.json.JsonArray import kotlinx.serialization.json.jsonObject import kotlinx.serialization.json.jsonPrimitive -import java.util.SortedMap -import java.util.TreeMap +import kotlin.collections.LinkedHashMap /** * Builds a restriction string based on provided [SecuredApiKeyRestrictions]. */ internal fun SearchClient.buildRestrictionString(restriction: SecuredApiKeyRestrictions): String { - val sortedParams: SortedMap = TreeMap() + val sortedParams = LinkedHashMap() restriction.searchParams?.let { searchParams -> val json = options.json.encodeToJsonElement(SearchParamsObject.serializer(), searchParams).jsonObject @@ -23,7 +22,7 @@ internal fun SearchClient.buildRestrictionString(restriction: SecuredApiKeyRestr is JsonArray -> element.joinToString(",") { it.jsonPrimitive.content } else -> element.jsonPrimitive.content } - sortedParams[key] = value + sortedParams.put(key, value) } } diff --git a/clients/algoliasearch-client-kotlin/client/src/commonTest/kotlin/com/algolia/client/TestSecureApiKey.kt b/clients/algoliasearch-client-kotlin/client/src/commonTest/kotlin/com/algolia/client/TestSecureApiKey.kt index c3a6b23f5a..583583348e 100644 --- a/clients/algoliasearch-client-kotlin/client/src/commonTest/kotlin/com/algolia/client/TestSecureApiKey.kt +++ b/clients/algoliasearch-client-kotlin/client/src/commonTest/kotlin/com/algolia/client/TestSecureApiKey.kt @@ -1,7 +1,7 @@ package com.algolia.client import com.algolia.client.api.SearchClient -import com.algolia.client.extensions.SecuredApiKeyRestrictions +import com.algolia.client.model.search.SecuredApiKeyRestrictions import com.algolia.client.extensions.generateSecuredApiKey import com.algolia.client.extensions.securedApiKeyRemainingValidity import com.algolia.client.model.search.SearchParamsObject From 9c2e42f2e8b833ec617db48534c32a17c6c1039a Mon Sep 17 00:00:00 2001 From: shortcuts Date: Mon, 1 Jul 2024 16:49:40 +0200 Subject: [PATCH 4/8] chore: remove unused file --- .../com/algolia/client/TestSecureApiKey.kt | 28 ------------------- 1 file changed, 28 deletions(-) delete mode 100644 clients/algoliasearch-client-kotlin/client/src/commonTest/kotlin/com/algolia/client/TestSecureApiKey.kt diff --git a/clients/algoliasearch-client-kotlin/client/src/commonTest/kotlin/com/algolia/client/TestSecureApiKey.kt b/clients/algoliasearch-client-kotlin/client/src/commonTest/kotlin/com/algolia/client/TestSecureApiKey.kt deleted file mode 100644 index 583583348e..0000000000 --- a/clients/algoliasearch-client-kotlin/client/src/commonTest/kotlin/com/algolia/client/TestSecureApiKey.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.algolia.client - -import com.algolia.client.api.SearchClient -import com.algolia.client.model.search.SecuredApiKeyRestrictions -import com.algolia.client.extensions.generateSecuredApiKey -import com.algolia.client.extensions.securedApiKeyRemainingValidity -import com.algolia.client.model.search.SearchParamsObject -import kotlinx.datetime.Clock -import kotlin.test.Test -import kotlin.test.assertTrue -import kotlin.time.Duration.Companion.days - -class TestSecureApiKey { - - @Test - fun securedApiKey() { - val parentApiKey = "SearchOnlyApiKeyKeptPrivate" - val restriction = SecuredApiKeyRestrictions( - query = SearchParamsObject(filters = "_tags:user_42"), - validUntil = Clock.System.now() + 2.days, - ) - - val client = SearchClient("appId", "apiKey") - val securedApiKey = client.generateSecuredApiKey(parentApiKey, restriction) - val validity = securedApiKeyRemainingValidity(securedApiKey) - assertTrue { validity > 1.days } - } -} From 8eb95d4269bfb4c9437b5f6b5419f4e432f870f8 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Mon, 1 Jul 2024 16:50:47 +0200 Subject: [PATCH 5/8] chore: remove secrets from action --- .github/workflows/check.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index e4ba7a2d69..8d3a79ed75 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -351,10 +351,6 @@ jobs: needs.setup.outputs.RUN_MACOS_KOTLIN_BUILD == 'true' && !contains(needs.*.result, 'cancelled') && !contains(needs.*.result, 'failure') - env: - ALGOLIA_APPLICATION_ID: ${{ secrets.ALGOLIA_APPLICATION_ID }} - ALGOLIA_ADMIN_KEY: ${{ secrets.ALGOLIA_ADMIN_KEY }} - MONITORING_API_KEY: ${{ secrets.MONITORING_API_KEY }} steps: - uses: actions/checkout@v4 From 656b2f50272ff08e43a276074f18bc521b5163fc Mon Sep 17 00:00:00 2001 From: shortcuts Date: Mon, 1 Jul 2024 17:08:46 +0200 Subject: [PATCH 6/8] fix: sort? --- .../com/algolia/client/extensions/internal/SearchClient.kt | 2 +- scripts/ci/githubActions/createMatrix.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/extensions/internal/SearchClient.kt b/clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/extensions/internal/SearchClient.kt index 11014b4e70..e26306de01 100644 --- a/clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/extensions/internal/SearchClient.kt +++ b/clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/extensions/internal/SearchClient.kt @@ -42,5 +42,5 @@ internal fun SearchClient.buildRestrictionString(restriction: SecuredApiKeyRestr sortedParams["validUntil"] = it.toString() } - return sortedParams.entries.joinToString("&") { "${it.key}=${it.value.encodeURLParameter()}" } + return sortedParams.toSortedMap().entries.joinToString("&") { "${it.key}=${it.value.encodeURLParameter()}" } } diff --git a/scripts/ci/githubActions/createMatrix.ts b/scripts/ci/githubActions/createMatrix.ts index c3a448f2d6..0fa02778d0 100644 --- a/scripts/ci/githubActions/createMatrix.ts +++ b/scripts/ci/githubActions/createMatrix.ts @@ -150,7 +150,6 @@ async function createClientMatrix(baseBranch: string): Promise { // If there are updates for the Kotlin client, we allow ourselves to run the build step on macOS const runKotlin = clientMatrix.client.find((c) => c.language === 'kotlin'); if (runKotlin) { - core.setOutput('SWIFT_DATA', JSON.stringify(swiftData)); core.setOutput('RUN_MACOS_KOTLIN_BUILD', true); } From 2c96e5b3ca2bac4049f613288f9c45ccc34cf606 Mon Sep 17 00:00:00 2001 From: shortcuts Date: Mon, 1 Jul 2024 17:42:55 +0200 Subject: [PATCH 7/8] fix: entries --- .../com/algolia/client/extensions/internal/SearchClient.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/extensions/internal/SearchClient.kt b/clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/extensions/internal/SearchClient.kt index e26306de01..fd66c45683 100644 --- a/clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/extensions/internal/SearchClient.kt +++ b/clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/extensions/internal/SearchClient.kt @@ -42,5 +42,7 @@ internal fun SearchClient.buildRestrictionString(restriction: SecuredApiKeyRestr sortedParams["validUntil"] = it.toString() } - return sortedParams.toSortedMap().entries.joinToString("&") { "${it.key}=${it.value.encodeURLParameter()}" } + return sortedParams.entries + .sortedBy { it.key } + .joinToString("&") { "${it.key}=${it.value.encodeURLParameter()}" } } From 1415e03ae92d06b9236e202e57c42259224175be Mon Sep 17 00:00:00 2001 From: shortcuts Date: Mon, 1 Jul 2024 18:00:56 +0200 Subject: [PATCH 8/8] chore: revert skip --- scripts/ci/githubActions/createMatrix.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/scripts/ci/githubActions/createMatrix.ts b/scripts/ci/githubActions/createMatrix.ts index 0fa02778d0..5dd205eb9d 100644 --- a/scripts/ci/githubActions/createMatrix.ts +++ b/scripts/ci/githubActions/createMatrix.ts @@ -19,10 +19,6 @@ async function createClientMatrix(baseBranch: string): Promise { // iterate over every generators to see what changed for (const { language, client, output } of Object.values(GENERATORS)) { - if (language !== 'kotlin') { - continue; - } - const bundledSpec = client === 'algoliasearch' ? 'search' : client; if (!commonDependenciesChanged) {