From aa23fdf92f45c355a609efe0c1c4dc1769cb3926 Mon Sep 17 00:00:00 2001 From: fankesyooni Date: Wed, 17 Jan 2024 13:52:26 +0800 Subject: [PATCH] chore: add dev publish function --- build.gradle.kts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index abfba65..8816313 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,6 +12,7 @@ plugins { libraryProjects { afterEvaluate { + resolveDevPublishWorkflow() configure { repositories { val repositoryDir = gradle.gradleUserHomeDir @@ -33,6 +34,35 @@ libraryProjects { } } +/** + * How to enable dev publish: + * + * 1. Create a file named "publish_dev" in the project build directory. + * + * 2. Run "./gradlew :(project name):publishDev" to publish a dev version. + * + * - Note: If you delete the "publish_dev" file, the dev publish will be disabled and lost the last dev version code. + */ +fun Project.resolveDevPublishWorkflow() { + fun String.parseCode() = (trim().toIntOrNull() ?: 0).toString().padStart(4, '0') + fun String.nextCode() = (toInt() + 1).toString().parseCode() + val devFile = projectDir.resolve("build").resolve("publish_dev") + val isDevMode = devFile.exists() + val code = (if (isDevMode) devFile.readText() else "1").parseCode() + val devVersion = "$version-dev$code" + version = if (isDevMode) devVersion else version + if (isDevMode) println("Detected dev mode of $name, publish version is $devVersion") + tasks.register("publishDev") { + group = "publishing" + dependsOn("publishAllPublicationsToHighCapableMavenSnapShotsRepository") + doLast { + val nextCode = code.nextCode() + println("Dev publish is finished, next dev code is $nextCode") + devFile.writeText(nextCode) + } + } +} + fun libraryProjects(action: Action) { val libraries = listOf( Libraries.FLEXIUI_CORE,