Skip to content

Commit

Permalink
Fix snapshot publications
Browse files Browse the repository at this point in the history
  • Loading branch information
serpro69 committed Mar 30, 2024
1 parent f2191d1 commit 570f847
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 58 deletions.
37 changes: 4 additions & 33 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 27 additions & 12 deletions bom/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -95,19 +101,28 @@ signing {
sign(publishing.publications["FakerBom"])
}

/*
* copy from faker-lib-conventions.gradle.kts:219
*/
tasks.withType<PublishToMavenRepository>().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<PublishToMavenLocal>().configureEach {
onlyIf("In development") { isSnapshot.get() }
onlyIf("In development") { isDev.get() || isSnapshot.get() }
}

/*
* copy from faker-lib-conventions.gradle.kts:230
*/
tasks.withType<Sign>().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() }
}
31 changes: 18 additions & 13 deletions buildSrc/src/main/kotlin/faker-lib-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -213,23 +217,24 @@ signing {
sign(publishing.publications[publicationName])
}

tasks.withType<DokkaTask>().configureEach {
onlyIf("Not dev") { !isDev.get() }
onlyIf("Release or snapshot") { isRelease.get() || isSnapshot.get() }
}

tasks.withType<PublishToMavenRepository>().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<PublishToMavenLocal>().configureEach {
onlyIf("In development") { isSnapshot.get() }
}

tasks.withType<DokkaTask>().configureEach {
onlyIf("Not snapshot") { !isSnapshot.get() }
onlyIf("In development") { isDev.get() || isSnapshot.get() }
}

tasks.withType<Sign>().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() }
}
4 changes: 4 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -53,6 +54,9 @@ settings.extensions.configure<SemverPluginExtension>("semantic-versioning") {
ignoreCase = true
}
}
version {
useSnapshots = true
}
monorepo {
fakers.forEach { f ->
module(":faker:$f") {
Expand Down

0 comments on commit 570f847

Please sign in to comment.