From ec7daf895ed743c22d0d8a0f50df34fb778b164e Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sun, 2 May 2021 07:36:18 +0530 Subject: build: trigger a Crowdin build before syncing strings Signed-off-by: Harsh Shandilya --- buildSrc/build.gradle.kts | 1 + buildSrc/src/main/java/CrowdinDownloadPlugin.kt | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) (limited to 'buildSrc') diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index abdc6def..003bbd6f 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -45,5 +45,6 @@ dependencies { implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0") implementation("com.ncorti.ktfmt.gradle:plugin:0.5.0") implementation("com.vanniktech:gradle-maven-publish-plugin:0.13.0") + implementation("com.squareup.okhttp3:okhttp:4.9.0") implementation("com.vdurmont:semver4j:3.1.0") } diff --git a/buildSrc/src/main/java/CrowdinDownloadPlugin.kt b/buildSrc/src/main/java/CrowdinDownloadPlugin.kt index 7a0f9d95..e8bf7b5b 100644 --- a/buildSrc/src/main/java/CrowdinDownloadPlugin.kt +++ b/buildSrc/src/main/java/CrowdinDownloadPlugin.kt @@ -6,6 +6,8 @@ import de.undercouch.gradle.tasks.download.Download import java.io.File import javax.xml.parsers.DocumentBuilderFactory +import okhttp3.OkHttpClient +import okhttp3.Request import org.gradle.api.GradleException import org.gradle.api.Plugin import org.gradle.api.Project @@ -16,6 +18,7 @@ import org.w3c.dom.Document private const val EXCEPTION_MESSAGE = """Applying `crowdin-plugin` requires a projectName to be configured via the "crowdin" extension.""" +private const val CROWDIN_BUILD_API_URL = "https://api.crowdin.com/api/project/%s/export?login=%s&account-key=%s" class CrowdinDownloadPlugin : Plugin { @@ -27,7 +30,22 @@ class CrowdinDownloadPlugin : Plugin { if (projectName.isEmpty()) { throw GradleException(EXCEPTION_MESSAGE) } + tasks.register("buildOnApi") { + val login = providers.environmentVariable("CROWDIN_LOGIN").forUseAtConfigurationTime() + val key = providers.environmentVariable("CROWDIN_PROJECT_KEY").forUseAtConfigurationTime() + if (!login.isPresent) { + throw GradleException("CROWDIN_LOGIN environment variable must be set") + } + if (!key.isPresent) { + throw GradleException("CROWDIN_PROJECT_KEY environment variable must be set") + } + val client = OkHttpClient() + val url = CROWDIN_BUILD_API_URL.format(projectName, login.get(), key.get()) + val request = Request.Builder().url(url).get().build() + client.newCall(request).execute() + } tasks.register("downloadCrowdin") { + setDependsOn(setOf("buildOnApi")) src("https://crowdin.com/backend/download/project/$projectName.zip") dest("$buildDir/translations.zip") overwrite(true) -- cgit v1.2.3