aboutsummaryrefslogtreecommitdiff
path: root/buildSrc
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2021-05-02 07:36:18 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2021-05-02 07:36:18 +0530
commitec7daf895ed743c22d0d8a0f50df34fb778b164e (patch)
treeb57032c328f41fd0d7b6979cb4b08d4c5ba3be61 /buildSrc
parentfb110e5a9a9478616a636b56faf658600b4997e7 (diff)
build: trigger a Crowdin build before syncing strings
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
Diffstat (limited to 'buildSrc')
-rw-r--r--buildSrc/build.gradle.kts1
-rw-r--r--buildSrc/src/main/java/CrowdinDownloadPlugin.kt18
2 files changed, 19 insertions, 0 deletions
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<Project> {
@@ -27,7 +30,22 @@ class CrowdinDownloadPlugin : Plugin<Project> {
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<Download>("downloadCrowdin") {
+ setDependsOn(setOf("buildOnApi"))
src("https://crowdin.com/backend/download/project/$projectName.zip")
dest("$buildDir/translations.zip")
overwrite(true)