From 25c9711aa297aca5a0de7acad572436f3ec053e5 Mon Sep 17 00:00:00 2001 From: Serhii Prodan <22973227+serpro69@users.noreply.github.com> Date: Sat, 30 Mar 2024 20:52:02 +0100 Subject: [PATCH] Fix snapshot publications Fix #230 --- Makefile | 37 ++---------------- bom/build.gradle.kts | 39 +++++++++++++------ .../kotlin/faker-lib-conventions.gradle.kts | 31 ++++++++------- settings.gradle.kts | 4 ++ 4 files changed, 53 insertions(+), 58 deletions(-) diff --git a/Makefile b/Makefile index 95310938d..26090d6e4 100644 --- a/Makefile +++ b/Makefile @@ -33,40 +33,11 @@ deploy-docs: ## deploys documentation with orchid ./gradlew :docs:orchidDeploy -PorchidEnvironment=prod -PorchidDiagnose=$(ORCHID_DIAGNOSE) git checkout ./docs/src/orchid/resources/config.yml -.PHONY: snapshot-in-pre-release -_snapshot-in-pre-release: ## (DEPRECATED) publishes next snapshot in current pre-release version - ./gradlew test integrationTest \ - printVersion \ - nativeCompile \ - publishToSonatype \ - -PpromoteRelease \ - --info - -.PHONY: snapshot-major -_snapshot-major: ## (DEPRECATED) publishes next snapshot with a major version bump - ./gradlew test integrationTest \ - printVersion \ - nativeCompile \ - publishToSonatype \ - -Pincrement=major \ - --info - .PHONY: snapshot-minor -snapshot-minor: check_java ## publishes next snapshot with a minor version bump - @:$(call check_defined, VERSION, semantic version string - 'X.Y.Z(-rc.\d+)?') - - ./gradlew clean test integrationTest -Pversion='$(VERSION)-SNAPSHOT' - ./gradlew nativeCompile -Pversion='$(VERSION)-SNAPSHOT' --info - ./gradlew publishToSonatype -Pversion='$(VERSION)-SNAPSHOT' --info - -.PHONY: snapshot-patch -_snapshot-patch: ## (DEPRECATED) publishes next snapshot with a patch version bump - ./gradlew test integrationTest \ - printVersion \ - nativeCompile \ - publishToSonatype \ - -Pincrement=patch \ - --info +snapshot-minor: ## publishes next snapshot with a minor version bump + ./gradlew clean test integrationTest + ./gradlew nativeCompile + ./gradlew publishToSonatype --info .PHONY: pre-release-major pre-release-major: ## publishes next pre-release version with a major version bump diff --git a/bom/build.gradle.kts b/bom/build.gradle.kts index ddda5c880..86a7687bd 100644 --- a/bom/build.gradle.kts +++ b/bom/build.gradle.kts @@ -9,15 +9,21 @@ plugins { } val bom = project + +val isDev = provider { version.toString().startsWith("0.0.0") } val isSnapshot = provider { - version.toString().startsWith("0.0.0") - || version.toString().endsWith("SNAPSHOT") + // QUESTION do we need to check if rootProject is also set to snapshot? + // Likely not, since "isRelease" will not just check for the version, but also for the actual tag creation + // rootProject.version.toString().endsWith("SNAPSHOT") && + version.toString().endsWith("SNAPSHOT") } -val newTag = provider { +val isRelease = provider { val tag = project.tasks.getByName("tag", TagTask::class) - /* ':bom' shares the tag with 'root', ':cli-bot' and ':core' modules, - and hence the tag might already exist and didWork will return false for ':bom' */ - tag.didWork || tag.tagExists + /* all fakers have their own tags, so checking if tag.didWork is enough for them, + ':core' shares the tag with 'root', ':bom' and ':cli-bot' modules, + and hence the tag might already exist and didWork will return false for ':core' */ + val tagCreated = if (project.name != "core") tag.didWork else tag.didWork || tag.tagExists + !isDev.get() && !isSnapshot.get() && tagCreated } // Exclude subprojects that will never be published so that when configuring this project @@ -95,19 +101,28 @@ signing { sign(publishing.publications["FakerBom"]) } +/* + * copy from faker-lib-conventions.gradle.kts:219 + */ tasks.withType().configureEach { dependsOn(project.tasks.getByName("tag")) - dependsOn(tasks.withType(Sign::class.java)) - onlyIf("Not snapshot") { !isSnapshot.get() } - onlyIf("New tag") { newTag.get() } + dependsOn(project.tasks.withType(Sign::class.java)) + onlyIf("Not dev") { !isDev.get() } + onlyIf("Release or snapshot") { isRelease.get() || isSnapshot.get() } } +/* + * copy from faker-lib-conventions.gradle.kts:226 + */ tasks.withType().configureEach { - onlyIf("In development") { isSnapshot.get() } + onlyIf("In development") { isDev.get() || isSnapshot.get() } } +/* + * copy from faker-lib-conventions.gradle.kts:230 + */ tasks.withType().configureEach { dependsOn(project.tasks.getByName("tag")) - onlyIf("Not snapshot") { !isSnapshot.get() } - onlyIf("New tag") { newTag.get() } + onlyIf("Not dev") { !isDev.get() } + onlyIf("Release or snapshot") { isRelease.get() || isSnapshot.get() } } diff --git a/buildSrc/src/main/kotlin/faker-lib-conventions.gradle.kts b/buildSrc/src/main/kotlin/faker-lib-conventions.gradle.kts index e93359285..2f4dbb96f 100644 --- a/buildSrc/src/main/kotlin/faker-lib-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/faker-lib-conventions.gradle.kts @@ -22,16 +22,20 @@ plugins { private val fullName: String = if (project.name == "core") rootProject.name else "${rootProject.name}-${project.name}" +val isDev = provider { version.toString().startsWith("0.0.0") } val isSnapshot = provider { - version.toString().startsWith("0.0.0") - || version.toString().endsWith("SNAPSHOT") + // QUESTION do we need to check if rootProject is also set to snapshot? + // Likely not, since "isRelease" will not just check for the version, but also for the actual tag creation + // rootProject.version.toString().endsWith("SNAPSHOT") && + version.toString().endsWith("SNAPSHOT") } -val newTag = provider { +val isRelease = provider { val tag = project.tasks.getByName("tag", TagTask::class) /* all fakers have their own tags, so checking if tag.didWork is enough for them, ':core' shares the tag with 'root', ':bom' and ':cli-bot' modules, and hence the tag might already exist and didWork will return false for ':core' */ - if (project.name != "core") tag.didWork else tag.didWork || tag.tagExists + val tagCreated = if (project.name != "core") tag.didWork else tag.didWork || tag.tagExists + !isDev.get() && !isSnapshot.get() && tagCreated } configurations { @@ -213,23 +217,24 @@ signing { sign(publishing.publications[publicationName]) } +tasks.withType().configureEach { + onlyIf("Not dev") { !isDev.get() } + onlyIf("Release or snapshot") { isRelease.get() || isSnapshot.get() } +} + tasks.withType().configureEach { dependsOn(project.tasks.getByName("tag")) dependsOn(project.tasks.withType(Sign::class.java)) - onlyIf("Not snapshot") { !isSnapshot.get() } - onlyIf("New tag") { newTag.get() } + onlyIf("Not dev") { !isDev.get() } + onlyIf("Release or snapshot") { isRelease.get() || isSnapshot.get() } } tasks.withType().configureEach { - onlyIf("In development") { isSnapshot.get() } -} - -tasks.withType().configureEach { - onlyIf("Not snapshot") { !isSnapshot.get() } + onlyIf("In development") { isDev.get() || isSnapshot.get() } } tasks.withType().configureEach { dependsOn(project.tasks.getByName("tag")) - onlyIf("Not snapshot") { !isSnapshot.get() } - onlyIf("New tag") { newTag.get() } + onlyIf("Not dev") { !isDev.get() } + onlyIf("Release or snapshot") { isRelease.get() || isSnapshot.get() } } diff --git a/settings.gradle.kts b/settings.gradle.kts index 7bb079729..84d611d3f 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,4 +1,5 @@ import io.github.serpro69.semverkt.gradle.plugin.SemverPluginExtension +import io.github.serpro69.semverkt.release.configuration.CleanRule import io.github.serpro69.semverkt.release.configuration.TagPrefix pluginManagement { @@ -53,6 +54,9 @@ settings.extensions.configure("semantic-versioning") { ignoreCase = true } } + version { + useSnapshots = true + } monorepo { fakers.forEach { f -> module(":faker:$f") {