Skip to content

Commit

Permalink
Remove leading and trailing whitespaces from VERSION files for crate …
Browse files Browse the repository at this point in the history
…and maven assembly rules (#414)

## What is the goal of this PR?

We resolve issue #380 by trimming input `version` values from `VERSION`
files for `maven` and `crate` artifacts assembly rules. It solves the
problem of `VERSION` files being passed as `version_file` to the
respective rules after being formatted to have an additional empty line
in the end, which is a standard convention for files and a common IDE
setting, or just being formatted incorrectly while containing a valid
value.

From now on, `VERSION` files passed into `assemble_maven` and
`assemble_crate` can have any leading and trailing whitespaces.
  • Loading branch information
farost authored Jun 3, 2024
1 parent 0040e49 commit 8767cde
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions crates/CrateAssembler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class CrateAssembler : Callable<Unit> {
}

private fun writeCrateArchive(config: UnmodifiableConfig) {
val prefix = "$name-${versionFile.readText()}"
val prefix = "$name-${versionFile.readText().trim()}"
outputCrateFile.outputStream().use { fos ->
BufferedOutputStream(fos).use { bos ->
GZIPOutputStream(bos).use { gzos ->
Expand Down Expand Up @@ -235,7 +235,7 @@ class CrateAssembler : Callable<Unit> {
cargoToml.set<Config>("package", this)
set<String>("name", name)
set<String>("edition", edition)
set<String>("version", tagToVersion(versionFile.readText()))
set<String>("version", tagToVersion(versionFile.readText().trim()))
set<Array<String>>("authors", authors.filter { it != "" })
set<String>("homepage", homepage)
set<String>("repository", repository)
Expand Down
2 changes: 1 addition & 1 deletion maven/PomGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class PomGenerator : Callable<Unit> {
}

override fun call() {
val version = tagToVersion(versionFile.readText())
val version = tagToVersion(versionFile.readText().trim())
val workspaceRefs = Json.parse(workspaceRefsFile.readText()).asObject()

// Create an XML document for constructing the POM
Expand Down
3 changes: 3 additions & 0 deletions maven/templates/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ def unpack_args(_, a, b=False):

version = version.text

if version != version.strip():
raise Exception('Version "{}" has leading or trailing whitespaces'.format(version))

snapshot = 'snapshot'
version_snapshot_regex = '^[0-9]+.[0-9]+.[0-9]+-[0-9|a-f|A-F]{40}$|.*-SNAPSHOT$'
release = 'release'
Expand Down

0 comments on commit 8767cde

Please sign in to comment.