Skip to content

Commit

Permalink
Fix bug where specifying promoteTrack used incorrect release notes an…
Browse files Browse the repository at this point in the history
…d name (#733)

Signed-off-by: Alex Saveau <[email protected]>
  • Loading branch information
SUPERCILEX authored Oct 30, 2019
1 parent 07dc011 commit 0feba82
Show file tree
Hide file tree
Showing 18 changed files with 244 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@ internal abstract class PromoteRelease @Inject constructor(
}
}

abstract class Promoter :
ArtifactWorkerBase<ArtifactWorkerBase.ArtifactPublishingParams>() {
abstract class Promoter : ArtifactWorkerBase<ArtifactWorkerBase.ArtifactPublishingParams>() {
override fun upload() {
edits2.promoteRelease(
config.promoteTrackOrDefault,
config.fromTrack,
config.releaseStatus,
findReleaseName(),
findReleaseNotes(),
findReleaseName(config.promoteTrackOrDefault),
findReleaseNotes(config.promoteTrackOrDefault),
config.userFraction,
config.retain.artifacts
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ internal abstract class PublishApk @Inject constructor(
parameters.skippedMarker.get().asFile.exists(),
config.trackOrDefault,
config.releaseStatusOrDefault,
findReleaseName(),
findReleaseNotes(),
findReleaseName(config.trackOrDefault),
findReleaseNotes(config.trackOrDefault),
config.userFractionOrDefault,
config.retain.artifacts
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ internal abstract class PublishBundle @Inject constructor(
parameters.skippedMarker.get().asFile.exists(),
config.trackOrDefault,
config.releaseStatusOrDefault,
findReleaseName(),
findReleaseNotes(),
findReleaseName(config.trackOrDefault),
findReleaseNotes(config.trackOrDefault),
config.userFractionOrDefault,
config.retain.artifacts
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.github.triplet.gradle.common.utils.orNull
import com.github.triplet.gradle.common.utils.readProcessed
import com.github.triplet.gradle.play.internal.RELEASE_NAMES_DEFAULT_NAME
import com.github.triplet.gradle.play.internal.RELEASE_NOTES_DEFAULT_NAME
import com.github.triplet.gradle.play.internal.trackOrDefault
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Property
Expand Down Expand Up @@ -32,12 +31,12 @@ internal abstract class ArtifactWorkerBase<T : ArtifactWorkerBase.ArtifactPublis
return onTheFlyBuild
}

protected fun findReleaseName(): String? {
protected fun findReleaseName(track: String): String? {
return if (config.releaseName != null) {
config.releaseName
} else if (parameters.consoleNamesDir.isPresent) {
val dir = parameters.consoleNamesDir.get()
val file = dir.file("${config.trackOrDefault}.txt").asFile.orNull()
val file = dir.file("$track.txt").asFile.orNull()
?: dir.file(RELEASE_NAMES_DEFAULT_NAME).asFile.orNull()

file?.readProcessed()?.lines()?.firstOrNull()
Expand All @@ -46,10 +45,10 @@ internal abstract class ArtifactWorkerBase<T : ArtifactWorkerBase.ArtifactPublis
}
}

protected fun findReleaseNotes(): Map<String, String?> {
protected fun findReleaseNotes(track: String): Map<String, String?> {
val locales = parameters.releaseNotesDir.orNull?.asFile?.listFiles().orEmpty()
return locales.mapNotNull { locale ->
var result = File(locale, "${config.trackOrDefault}.txt").orNull()
var result = File(locale, "$track.txt").orNull()
if (result == null) result = File(locale, RELEASE_NOTES_DEFAULT_NAME).orNull()
result
}.associate { notes ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
myCustomName
Original file line number Diff line number Diff line change
@@ -1 +1 @@
myCustomName
myDefaultName
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
myPromoteName
Original file line number Diff line number Diff line change
@@ -1 +1 @@
My custom release notes
My default release notes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Promote track release notes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
myCustomName
Original file line number Diff line number Diff line change
@@ -1 +1 @@
myCustomName
myDefaultName
Original file line number Diff line number Diff line change
@@ -1 +1 @@
My custom release notes
My default release notes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
myCustomName
Original file line number Diff line number Diff line change
@@ -1 +1 @@
myCustomName
myDefaultName
Original file line number Diff line number Diff line change
@@ -1 +1 @@
My custom release notes
My default release notes
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class PromoteReleaseIntegrationTest : IntegrationTestBase() {
}

@Test
fun `Build uses correct release name`() {
fun `Build picks default release name when no track specific ones are available`() {
@Suppress("UnnecessaryQualifiedReference")
// language=gradle
val config = """
Expand All @@ -160,13 +160,60 @@ class PromoteReleaseIntegrationTest : IntegrationTestBase() {

val result = execute(config, "promoteConsoleNamesArtifact")

assertThat(result.task(":promoteConsoleNamesArtifact")).isNotNull()
assertThat(result.task(":promoteConsoleNamesArtifact")!!.outcome)
.isEqualTo(TaskOutcome.SUCCESS)
assertThat(result.output).contains("promoteRelease(")
assertThat(result.output).contains("releaseName=myDefaultName")
}

@Test
fun `Build picks track specific release name when available`() {
@Suppress("UnnecessaryQualifiedReference")
// language=gradle
val config = """
com.github.triplet.gradle.play.tasks.PromoteReleaseIntegrationBridge.installFactories()
android.buildTypes {
consoleNames {}
}
play.track 'custom-track'
"""

val result = execute(config, "promoteConsoleNamesArtifact")

assertThat(result.task(":promoteConsoleNamesArtifact")).isNotNull()
assertThat(result.task(":promoteConsoleNamesArtifact")!!.outcome)
.isEqualTo(TaskOutcome.SUCCESS)
assertThat(result.output).contains("promoteRelease(")
assertThat(result.output).contains("releaseName=myCustomName")
}

@Test
fun `Build picks promote track specific release name when available`() {
@Suppress("UnnecessaryQualifiedReference")
// language=gradle
val config = """
com.github.triplet.gradle.play.tasks.PromoteReleaseIntegrationBridge.installFactories()
android.buildTypes {
consoleNames {}
}
play.track 'custom-track'
play.promoteTrack 'promote-track'
"""

val result = execute(config, "promoteConsoleNamesArtifact")

assertThat(result.task(":promoteConsoleNamesArtifact")).isNotNull()
assertThat(result.task(":promoteConsoleNamesArtifact")!!.outcome)
.isEqualTo(TaskOutcome.SUCCESS)
assertThat(result.output).contains("promoteRelease(")
assertThat(result.output).contains("releaseName=myPromoteName")
}

@Test
fun `Build picks default release notes when no track specific ones are available`() {
@Suppress("UnnecessaryQualifiedReference")
Expand All @@ -185,7 +232,7 @@ class PromoteReleaseIntegrationTest : IntegrationTestBase() {
assertThat(result.task(":promoteReleaseNotesArtifact")!!.outcome)
.isEqualTo(TaskOutcome.SUCCESS)
assertThat(result.output).contains("promoteRelease(")
assertThat(result.output).contains("releaseNotes={en-US=My custom release notes, " +
assertThat(result.output).contains("releaseNotes={en-US=My default release notes, " +
"fr-FR=Mes notes de mise à jour}")
}

Expand Down Expand Up @@ -213,6 +260,31 @@ class PromoteReleaseIntegrationTest : IntegrationTestBase() {
"fr-FR=Mes notes de mise à jour}")
}

@Test
fun `Build picks promote track specific release notes when available`() {
@Suppress("UnnecessaryQualifiedReference")
// language=gradle
val config = """
com.github.triplet.gradle.play.tasks.PromoteReleaseIntegrationBridge.installFactories()
android.buildTypes {
releaseNotes {}
}
play.track 'custom-track'
play.promoteTrack 'promote-track'
"""

val result = execute(config, "promoteReleaseNotesArtifact")

assertThat(result.task(":promoteReleaseNotesArtifact")).isNotNull()
assertThat(result.task(":promoteReleaseNotesArtifact")!!.outcome)
.isEqualTo(TaskOutcome.SUCCESS)
assertThat(result.output).contains("promoteRelease(")
assertThat(result.output).contains("releaseNotes={en-US=Promote track release notes, " +
"fr-FR=Mes notes de mise à jour}")
}

@Test
fun `Build uses correct user fraction`() {
@Suppress("UnnecessaryQualifiedReference")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ class PublishApkIntegrationTest : IntegrationTestBase() {
}

@Test
fun `Build uses correct release name`() {
fun `Build picks default release name when no track specific ones are available`() {
@Suppress("UnnecessaryQualifiedReference")
// language=gradle
val config = """
Expand All @@ -446,6 +446,53 @@ class PublishApkIntegrationTest : IntegrationTestBase() {

val result = execute(config, "publishConsoleNamesApk")

assertThat(result.task(":publishConsoleNamesApk")).isNotNull()
assertThat(result.task(":publishConsoleNamesApk")!!.outcome)
.isEqualTo(TaskOutcome.SUCCESS)
assertThat(result.output).contains("publishApk(")
assertThat(result.output).contains("releaseName=myDefaultName")
}

@Test
fun `Build picks track specific release name when available`() {
@Suppress("UnnecessaryQualifiedReference")
// language=gradle
val config = """
com.github.triplet.gradle.play.tasks.PublishApkIntegrationBridge.installFactories()
android.buildTypes {
consoleNames {}
}
play.track 'custom-track'
"""

val result = execute(config, "publishConsoleNamesApk")

assertThat(result.task(":publishConsoleNamesApk")).isNotNull()
assertThat(result.task(":publishConsoleNamesApk")!!.outcome)
.isEqualTo(TaskOutcome.SUCCESS)
assertThat(result.output).contains("publishApk(")
assertThat(result.output).contains("releaseName=myCustomName")
}

@Test
fun `Build ignores promote track specific release name when available`() {
@Suppress("UnnecessaryQualifiedReference")
// language=gradle
val config = """
com.github.triplet.gradle.play.tasks.PublishApkIntegrationBridge.installFactories()
android.buildTypes {
consoleNames {}
}
play.track 'custom-track'
play.promoteTrack 'promote-track'
"""

val result = execute(config, "publishConsoleNamesApk")

assertThat(result.task(":publishConsoleNamesApk")).isNotNull()
assertThat(result.task(":publishConsoleNamesApk")!!.outcome)
.isEqualTo(TaskOutcome.SUCCESS)
Expand All @@ -471,7 +518,7 @@ class PublishApkIntegrationTest : IntegrationTestBase() {
assertThat(result.task(":publishReleaseNotesApk")!!.outcome)
.isEqualTo(TaskOutcome.SUCCESS)
assertThat(result.output).contains("publishApk(")
assertThat(result.output).contains("releaseNotes={en-US=My custom release notes, " +
assertThat(result.output).contains("releaseNotes={en-US=My default release notes, " +
"fr-FR=Mes notes de mise à jour}")
}

Expand Down Expand Up @@ -499,6 +546,31 @@ class PublishApkIntegrationTest : IntegrationTestBase() {
"fr-FR=Mes notes de mise à jour}")
}

@Test
fun `Build ignores promote track specific release notes when available`() {
@Suppress("UnnecessaryQualifiedReference")
// language=gradle
val config = """
com.github.triplet.gradle.play.tasks.PublishApkIntegrationBridge.installFactories()
android.buildTypes {
releaseNotes {}
}
play.track 'custom-track'
play.promoteTrack 'promote-track'
"""

val result = execute(config, "publishReleaseNotesApk")

assertThat(result.task(":publishReleaseNotesApk")).isNotNull()
assertThat(result.task(":publishReleaseNotesApk")!!.outcome)
.isEqualTo(TaskOutcome.SUCCESS)
assertThat(result.output).contains("publishApk(")
assertThat(result.output).contains("releaseNotes={en-US=Custom track release notes, " +
"fr-FR=Mes notes de mise à jour}")
}

@Test
fun `Build uses correct user fraction`() {
@Suppress("UnnecessaryQualifiedReference")
Expand Down
Loading

0 comments on commit 0feba82

Please sign in to comment.