Skip to content

Commit

Permalink
#1364 Auto-versioning problem when updating same file
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoraboeuf committed Dec 7, 2024
1 parent 3d2a03c commit e75c1ff
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class AutoVersioningProcessingServiceImpl(
}
// Map of current versions per path
val currentVersions = mutableMapOf<String, String>()
// Caching the updated content of each path
val updatedContent = mutableMapOf<String, List<String>>()
// For each target path
val targetPathUpdated: List<Boolean> = try {
order.allPaths.flatMap { configPath ->
Expand All @@ -118,10 +120,12 @@ class AutoVersioningProcessingServiceImpl(
}
configPath.paths.map { targetPath ->
// Gets the content of the target file
val lines = scm.download(scmBranch, targetPath, retryOnNotFound = true)
?.toString(Charsets.UTF_8)
?.lines()
?: throw AutoVersioningNoContentException(scmBranch, targetPath)
val lines = updatedContent.getOrPut(targetPath) {
scm.download(scmBranch, targetPath, retryOnNotFound = true)
?.toString(Charsets.UTF_8)
?.lines()
?: throw AutoVersioningNoContentException(scmBranch, targetPath)
}
// Gets the current version in this file
val currentVersion: String = autoVersioningTargetFileService.readVersion(configPath, lines)
?: throw AutoVersioningVersionNotFoundException(targetPath)
Expand All @@ -133,14 +137,8 @@ class AutoVersioningProcessingServiceImpl(
val updatedLines = configPath.replaceVersion(lines, targetVersion)
// Audit
autoVersioningAuditService.onProcessingUpdatingFile(order, upgradeBranch, targetPath)
// Uploads of the file content
scm.uploadLines(
upgradeBranch,
commitId,
targetPath,
updatedLines,
message = order.getCommitMessage()
)
// Updating the cache
updatedContent[targetPath] = updatedLines
// Changed
true
} else {
Expand All @@ -160,6 +158,26 @@ class AutoVersioningProcessingServiceImpl(
// At least one path was changed
if (targetPathUpdated.any { it }) {

// Uploading the file contents
try {
updatedContent.forEach { (targetPath, updatedLines) ->
scm.uploadLines(
upgradeBranch,
commitId,
targetPath,
updatedLines,
message = order.getCommitMessage()
)
}
} catch (e: Exception) {
autoVersioningEventService.sendError(
order,
e.message?.takeIf { it.isNotBlank() } ?: "Issue while uploading the change",
e
)
throw e
}

// Templating renderer
val avRenderer = autoVersioningTemplatingService.createAutoVersioningTemplateRenderer(
order = order,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,62 @@ class ACCAutoVersioningMultiplePaths : AbstractACCAutoVersioningTestSupport() {
}
}

@Test
fun `Auto versioning with additional paths using the same path`() {
withMockScmRepository(ontrack) {
withAutoVersioning {
repositoryFile("gradle.properties") {
"""
one-version = 1.0.0
another-version = 1.0.0
""".trimIndent()
}
val dependency = branchWithPromotion(promotion = "IRON")
project {
branch {
configuredForMockRepository()
setAutoVersioningConfig(
listOf(
AutoVersioningSourceConfig(
sourceProject = dependency.project.name,
sourceBranch = dependency.name,
sourcePromotion = "IRON",
targetPath = "gradle.properties",
targetProperty = "one-version",
additionalPaths = listOf(
AutoVersioningSourceConfigPath(
path = "gradle.properties",
property = "another-version",
)
)
)
)
)

dependency.apply {
build(name = "2.0.0") {
setMetaInfoProperty("toml", "2.0.0-toml")
promote("IRON")
}
}

waitForAutoVersioningCompletion()

assertThatMockScmRepository {
fileContains("gradle.properties") {
"""
one-version = 2.0.0
another-version = 2.0.0
""".trimIndent()
}
}

}
}
}
}
}

@Test
fun `Auto versioning on multiple paths`() {
withMockScmRepository(ontrack) {
Expand Down

0 comments on commit e75c1ff

Please sign in to comment.