[
https://issues.apache.org/jira/browse/KAFKA-20085?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18053276#comment-18053276
]
Chia-Ping Tsai commented on KAFKA-20085:
----------------------------------------
{code:java}
def updateVersionTask = tasks.register('updateVersion') {
group = "Release"
description = "Syncs python, pom, and script versions with gradle.properties.
Fails if files or patterns are missing."
doLast {
def rawVersion = project.version.toString()
// Python Package Version (PEP 440): 4.3.0.dev0
def pythonVersion = rawVersion.contains("SNAPSHOT") ?
rawVersion.replace("-SNAPSHOT", ".dev0") :
rawVersion
def baseVersion = rawVersion.replace("-SNAPSHOT", "")
def targets = [
// 1. kafka-merge-pr.py
[
path: "committer-tools/kafka-merge-pr.py",
// Regex 說明: 匹配 DEFAULT_FIX_VERSION =
os.environ.get("DEFAULT_FIX_VERSION", "...")
pattern:
/DEFAULT_FIX_VERSION\s*=\s*os\.environ\.get\("DEFAULT_FIX_VERSION",\s*".*?"\)/,
replace: "DEFAULT_FIX_VERSION = os.environ.get(\"DEFAULT_FIX_VERSION\",
\"${baseVersion}\")"
],
// 2. version.py
[
path: "tests/kafkatest/version.py",
pattern: /DEV_VERSION\s*=\s*KafkaVersion\(".*"\)/,
replace: "DEV_VERSION = KafkaVersion(\"${rawVersion}\")"
],
// 3. __init__.py
[
path: "tests/kafkatest/__init__.py",
pattern: /__version__\s*=\s*'.*'/,
replace: "__version__ = '${pythonVersion}'"
],
// 4. Maven POMs
[
path: "streams/quickstart/pom.xml",
pattern:
/(?s)(<artifactId>streams-quickstart<\/artifactId>.*?<version>)([^<]+)(<\/version>)/,
replace: { "\$1${rawVersion}\$3" }
],
[
path: "streams/quickstart/java/pom.xml",
pattern:
/(?s)(<artifactId>streams-quickstart<\/artifactId>.*?<version>)([^<]+)(<\/version>)/,
replace: { "\$1${rawVersion}\$3" }
],
[
path:
"streams/quickstart/java/src/main/resources/archetype-resources/pom.xml",
pattern: /(<kafka\.version>)([^<]+)(<\/kafka\.version>)/,
replace: { "\$1${rawVersion}\$3" }
]
]
targets.each { item ->
def f = file("${project.rootDir}/${item.path}")
// Check 1: file must be existed
if (!f.exists()) {
throw new GradleException("File not found: ${item.path}")
}
def content = f.text
// Check 2: regex must be matched
def matcher = (content =~ item.pattern)
if (!matcher.find()) {
throw new GradleException("Pattern not found in ${item.path}.\nExpected
pattern: ${item.pattern}")
}
def replacementStr = item.replace instanceof Closure ?
item.replace.call() : item.replace
def newContent = content.replaceAll(item.pattern, replacementStr)
if (content != newContent) {
f.text = newContent
}
}
}
}
check.dependsOn updateVersionTask{code}
this works on my local
> Let's replace this verbose instruction with a custom Gradle task
> ----------------------------------------------------------------
>
> Key: KAFKA-20085
> URL: https://issues.apache.org/jira/browse/KAFKA-20085
> Project: Kafka
> Issue Type: Improvement
> Reporter: Chia-Ping Tsai
> Assignee: Chia-Ping Tsai
> Priority: Minor
>
> Instead of writing the following verbose comment, we should add a gradle task
> to automate it
> {code:java}
> # NOTE: When you change this version number, you should also make sure to
> update
> # the version numbers in
> # - tests/kafkatest/__init__.py
> # - tests/kafkatest/version.py (variable DEV_VERSION)
> # - kafka-merge-pr.py
> # - streams/quickstart/pom.xml
> # - streams/quickstart/java/src/main/resources/archetype-resources/pom.xml
> # - streams/quickstart/java/pom.xml {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)