Skip to content

Commit

Permalink
Merge pull request #51 from cianru/snapshot-1.4.1
Browse files Browse the repository at this point in the history
Snapshot 1.4.1
  • Loading branch information
cosic authored Dec 18, 2023
2 parents ef2f517 + 8cb2971 commit da60c07
Show file tree
Hide file tree
Showing 18 changed files with 501 additions and 223 deletions.
37 changes: 37 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
# 1.4.1

##### Add
* [issue#50] Added new parameter `removeHtmlTags` to remove html tags from Release Notes and support of the same Release Notes as for Google Play.

##### Fix
* Fix correct mustRunAfter publish task for `assemble*` and `bundle*` tasks for Gradle 8.

##### Breaking changes

Changed `releaseNotes` configuration block. Instead of
```
releaseNotes = listOf(
ru.cian.rustore.publish.ReleaseNote(
lang = "en-US",
filePath = "$projectDir/release-notes-en.txt"
),
)
```
new configuration would
```
releaseNotes = ru.cian.huawei.publish.ReleaseNotesExtension(
descriptions = listOf(
ru.cian.huawei.publish.ReleaseNote(
lang = "en-US",
filePath = "$projectDir/release-notes-en.txt"
)
),
removeHtmlTags = false
)
```

# 1.3.7

##### Fix
* Fix correct mustRunAfter publish task for `assemble*` and `bundle*` tasks for Gradle 7.

# 1.4.0

##### Add
Expand Down
282 changes: 149 additions & 133 deletions README.md

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ minSdkVersion = "21"

jvm = "17"
kotlin = "1.8.21"
detekt = "1.22.0"
junitJupiter = "5.9.2"
androidGradlePlugin = "8.0.0"
sampleHuaweiPlugin = "1.4.0-SNAPSHOT"
detekt = "1.23.4"
junitJupiter = "5.9.3"
androidGradlePlugin = "8.0.2"
sampleHuaweiPlugin = "1.4.1-SNAPSHOT"

[libraries]
appcompat = "androidx.appcompat:appcompat:1.6.1"
Expand All @@ -24,7 +24,7 @@ androidGradlePlugin = { group = "com.android.tools.build", name = "gradle", vers
detektFormating = { group = "io.gitlab.arturbosch.detekt", name = "detekt-formatting", version.ref = "detekt" }
detektLibraries = { group = "io.gitlab.arturbosch.detekt", name = "detekt-rules-libraries", version.ref = "detekt" }

test-assertk = "com.willowtreeapps.assertk:assertk-jvm:0.23"
test-assertk = "com.willowtreeapps.assertk:assertk-jvm:0.26.1"
test-hamcreast = "org.hamcrest:hamcrest:2.2"
test-mockk = "io.mockk:mockk:1.13.5"
test-mockitoCore = "org.mockito:mockito-core:5.3.0"
Expand Down
21 changes: 15 additions & 6 deletions plugin/config/detekt/detekt-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,21 @@ style:
active: true
ForbiddenComment:
active: true
values:
- 'TODO:'
- 'FIXME:'
- 'STOPSHIP:'
- '@author'
- '@requiresTypeResolution'
comments:
- reason: 'Forbidden TODO todo marker in comment, please do the changes.'
value: 'TODO:'
- reason: 'Forbidden FIXME todo marker in comment, please fix the problem.'
value: 'FIXME:'
- reason: 'Forbidden STOPSHIP todo marker in comment, please address the problem before shipping the code.'
value: 'STOPSHIP:'
- reason: 'include an issue link at the beginning preceded by a space'
value: 'BUG:(?! https://github\.com/company/repo/issues/\d+).*'
- reason: 'Authors are not recorded in KDoc.'
value: '@author'
- reason: 'KDoc tag should have a value.'
value: '^\s*@(?!suppress|hide)\w+\s*$'
- reason: 'Use @androidx.annotation.VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) instead.'
value: '^private$'
excludes: ['**/detekt-rules-style/**/ForbiddenComment.kt']
ForbiddenVoid:
active: true
Expand Down
3 changes: 2 additions & 1 deletion plugin/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8
org.gradle.workers.max=4
kotlin.code.style=official
org.gradle.parallel=false

Expand All @@ -8,7 +9,7 @@ android.enableJetifier=true
####################################################################################################

GROUP=ru.cian
VERSION_NAME=1.4.0
VERSION_NAME=1.4.1
IS_SNAPSHOT=true

POM_ARTIFACT_ID=huawei-publish-gradle-plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal data class HuaweiPublishConfig(
val publishPeriodMs: Long,
val releaseTime: String?,
val releasePhase: ReleasePhaseConfig?,
val releaseNotes: List<ReleaseNotesConfig>?,
val releaseNotes: ReleaseNotesConfig?,
val appBasicInfoFile: File?
)

Expand Down Expand Up @@ -40,11 +40,16 @@ internal data class HuaweiPublishCliParam(
val releasePhaseEndTime: String? = null,
val releasePhasePercent: String? = null,
val releaseNotes: String? = null,
val removeHtmlTags: Boolean? = null,
val apiStub: Boolean? = null,
val appBasicInfo: String? = null
val appBasicInfo: String? = null,
)

internal data class ReleaseNotesConfig(
val descriptions: List<ReleaseNotesDescriptionsConfig>?,
val removeHtmlTags: Boolean,
)
internal data class ReleaseNotesDescriptionsConfig(
val lang: String,
val newFeatures: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class HuaweiPublishExtensionConfig(
var buildFile: String? = null
var releaseTime: String? = null
var releasePhase: ReleasePhaseExtension? = null
var releaseNotes: List<ReleaseNote>? = null
var releaseNotes: ReleaseNotesExtension? = null
var appBasicInfo: String? = null

init {
Expand All @@ -53,6 +53,12 @@ class HuaweiPublishExtensionConfig(
return releasePhase!!
}

fun releaseNotes(closure: Closure<ReleaseNotesExtension>): ReleaseNotesExtension {
releaseNotes = ReleaseNotesExtension()
project.configure(releaseNotes!!, closure)
return releaseNotes!!
}

override fun toString(): String {
return "HuaweiPublishExtensionConfig(" +
"name='$name', " +
Expand All @@ -64,8 +70,8 @@ class HuaweiPublishExtensionConfig(
"buildFile='$buildFile', " +
"releaseTime='$releaseTime', " +
"releasePhase='$releasePhase', " +
"releaseNotes='$releaseNotes'" +
"appBasicInfo='$appBasicInfo'" +
"releaseNotes='$releaseNotes', " +
"appBasicInfo='$appBasicInfo', " +
")"
}
}
Expand Down Expand Up @@ -93,6 +99,30 @@ open class ReleasePhaseExtension {
}
}

open class ReleaseNotesExtension {

var descriptions: List<ReleaseNote>? = null
var removeHtmlTags: Boolean? = null

constructor()

constructor(descriptions: List<ReleaseNote>?) {
this.descriptions = descriptions
}

constructor(descriptions: List<ReleaseNote>?, removeHtmlTags: Boolean) {
this.descriptions = descriptions
this.removeHtmlTags = removeHtmlTags
}

override fun toString(): String {
return "ReleaseNotesExtension(" +
"descriptions='$descriptions', " +
"removeHtmlTags='$removeHtmlTags'" +
")"
}
}

open class ReleaseNote {

lateinit var lang: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.android.build.api.variant.VariantSelector
import com.android.build.gradle.AppPlugin
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.TaskProvider
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.getByType
import org.gradle.kotlin.dsl.register
Expand All @@ -32,16 +33,35 @@ class HuaweiPublishPlugin : Plugin<Project> {
}

@Suppress("DefaultLocale")
private fun createTask(project: Project, variant: ApplicationVariant) {
private fun createTask(
project: Project,
variant: ApplicationVariant,
) {
val variantName = variant.name.capitalize()
val publishTaskName = "${HuaweiPublishTask.TASK_NAME}$variantName"
project.tasks.register<HuaweiPublishTask>(publishTaskName, variant).configure {
setMustRunAfter(
setOf(
project.tasks.named("assemble$variantName"),
project.tasks.named("bundle$variantName"),
)
)
val publishTask = project.tasks.register<HuaweiPublishTask>(publishTaskName, variant)
scheduleTasksOrder(publishTask, project, variantName)
}

private fun scheduleTasksOrder(
publishTask: TaskProvider<HuaweiPublishTask>,
project: Project,
variantName: String
) {
project.gradle.projectsEvaluated {
mustRunAfter(project, publishTask, "assemble$variantName")
mustRunAfter(project, publishTask, "bundle$variantName")
}
}

private fun mustRunAfter(
project: Project,
publishTask: TaskProvider<HuaweiPublishTask>,
taskBeforeName: String,
) {
if (project.tasks.findByName(taskBeforeName) != null) {
val assembleTask = project.tasks.named(taskBeforeName).get()
publishTask.get().mustRunAfter(assembleTask)
}
}
}
33 changes: 28 additions & 5 deletions plugin/src/main/kotlin/ru/cian/huawei/publish/HuaweiPublishTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,19 @@ open class HuaweiPublishTask
var releaseNotes: String? = null

@get:Internal
@set:Option(option = "apiStub", description = "Use RestAPI stub instead of real RestAPI requests")
@set:Option(
option = "removeHtmlTags",
description = "EXPERIMENTAL (Default: False). " +
"True - if needs to remove html tags from provided release notes. " +
"For example, to support Google Play release notes."
)
var removeHtmlTags: Boolean? = null

@get:Internal
@set:Option(
option = "apiStub",
description = "Use RestAPI stub instead of real RestAPI requests",
)
var apiStub: Boolean? = false

@Suppress("MaximumLineLength", "MaxLineLength")
Expand Down Expand Up @@ -179,6 +191,7 @@ open class HuaweiPublishTask
releasePhaseEndTime = releasePhaseEndTime,
releasePhasePercent = releasePhasePercent,
releaseNotes = releaseNotes,
removeHtmlTags = removeHtmlTags,
apiStub = apiStub,
appBasicInfo = appBasicInfo
)
Expand Down Expand Up @@ -231,15 +244,25 @@ open class HuaweiPublishTask
)
logger.i("fileInfoListResult=$fileInfoListResult")

if (!config.releaseNotes.isNullOrEmpty()) {
config.releaseNotes.forEachIndexed { index, releaseNote ->
logger.v("Upload release notes: ${index + 1}/${config.releaseNotes.size}, lang=${releaseNote.lang}")
if (!config.releaseNotes?.descriptions.isNullOrEmpty()) {
config.releaseNotes?.descriptions?.forEachIndexed { index, releaseNote ->
val newFeatures = releaseNote.newFeatures
logger.v(
"Upload release notes: ${index + 1}/${config.releaseNotes.descriptions.size}, " +
"lang=${releaseNote.lang}"
)
logger.i(
"Upload release notes: ${index + 1}/${config.releaseNotes.descriptions.size}, " +
"lang=${releaseNote.lang}, " +
"removeHtmlTags=${config.releaseNotes.removeHtmlTags}, " +
"features=$newFeatures"
)
huaweiService.updateReleaseNotes(
clientId = config.credentials.clientId,
accessToken = token,
appId = appInfo.value,
lang = releaseNote.lang,
newFeatures = releaseNote.newFeatures,
newFeatures = newFeatures,
)
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ru.cian.huawei.publish.HuaweiPublishCliParam
import ru.cian.huawei.publish.HuaweiPublishConfig
import ru.cian.huawei.publish.HuaweiPublishExtensionConfig
import ru.cian.huawei.publish.ReleaseNotesConfig
import ru.cian.huawei.publish.ReleaseNotesDescriptionsConfig
import ru.cian.huawei.publish.ReleasePhaseConfig

internal class ConfigProvider(
Expand Down Expand Up @@ -174,16 +175,22 @@ internal class ConfigProvider(
}
}

private fun getReleaseNotesConfig(): List<ReleaseNotesConfig>? {
private fun getReleaseNotesConfig(): ReleaseNotesConfig? {

val releaseNotePairs = cli.releaseNotes?.split(";")?.map {
val split = it.split(":")
split[0] to split[1]
} ?: extension.releaseNotes?.map {
} ?: extension.releaseNotes?.descriptions?.map {
it.lang to it.filePath
}

return releaseNotePairs?.map {
if (releaseNotePairs == null) {
return null
}

val removeHtmlTags = cli.removeHtmlTags ?: extension.releaseNotes?.removeHtmlTags ?: false

val descriptions = releaseNotePairs.map {

val lang = it.first
val filePath = it.second
Expand All @@ -198,18 +205,33 @@ internal class ConfigProvider(
"File '$filePath' with Release Notes for '$lang' language is not exist."
}

val newFeatures = file.readText(Charsets.UTF_8)
val newFeatures = if (removeHtmlTags) {
file.readText(Charsets.UTF_8)
// remove html tags
.replace("\\<[^>]*>".toRegex(), "")
// remove html symbols
.replace("(&#)[^;]*;".toRegex(), "*")
// compress all non-newline whitespaces to single space
.replace("[\\s&&[^\\n]]+".toRegex(), " ")
} else {
file.readText(Charsets.UTF_8)
}

require(newFeatures.length <= RELEASE_NOTES_MAX_LENGTH) {
"Release notes from '$filePath' for '$lang' language " +
"must be less or equals to $RELEASE_NOTES_MAX_LENGTH sign."
}

ReleaseNotesConfig(
ReleaseNotesDescriptionsConfig(
lang = lang,
newFeatures = newFeatures
)
}

return ReleaseNotesConfig(
descriptions = descriptions,
removeHtmlTags = removeHtmlTags,
)
}

private fun getAppBasicInfoFile(): File? {
Expand Down
Loading

0 comments on commit da60c07

Please sign in to comment.