Skip to content

Commit

Permalink
Fixed resolution of packaged chart artifact for helmPublish task
Browse files Browse the repository at this point in the history
fixes #8
  • Loading branch information
tkrullmann committed Apr 19, 2019
1 parent cf0a022 commit 50b8b2b
Showing 1 changed file with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ import org.unbrokendome.gradle.plugins.helm.publishing.dsl.HelmPublishingReposit
import org.unbrokendome.gradle.plugins.helm.publishing.dsl.publishConvention
import org.unbrokendome.gradle.plugins.helm.publishing.tasks.HelmPublishChart
import org.unbrokendome.gradle.plugins.helm.rules.AbstractRule
import org.unbrokendome.gradle.plugins.helm.rules.dirArtifactConfigurationName
import org.unbrokendome.gradle.plugins.helm.rules.packagedArtifactConfigurationName


/**
* Rule that creates a task for publishing a given chart to a given repository.
*/
internal class HelmPublishChartToRepositoryTaskRule(
private val project: Project,
private val charts: NamedDomainObjectCollection<HelmChart>,
private val repositories: NamedDomainObjectCollection<HelmPublishingRepository>
private val project: Project,
private val charts: NamedDomainObjectCollection<HelmChart>,
private val repositories: NamedDomainObjectCollection<HelmPublishingRepository>
) : AbstractRule() {

internal companion object {
fun getTaskName(chartName: String, repositoryName: String) =
"helmPublish${chartName.capitalize()}ChartTo${repositoryName.capitalize()}Repo"
"helmPublish${chartName.capitalize()}ChartTo${repositoryName.capitalize()}Repo"
}

private val regex = Regex(getTaskName("(\\p{Upper}.*)", "(\\p{Upper}.*)"))


override fun getDescription(): String =
"Pattern: ${getTaskName("<Chart>", "<Repo>")}"
"Pattern: ${getTaskName("<Chart>", "<Repo>")}"


override fun apply(taskName: String) {
Expand All @@ -38,7 +38,8 @@ internal class HelmPublishChartToRepositoryTaskRule(
val chart = charts.findByName(chartName) ?: charts.findByName(chartName.capitalize())

val repositoryName = matchResult.groupValues[2].decapitalize()
val repository = repositories.findByName(repositoryName) ?: repositories.findByName(repositoryName.capitalize())
val repository =
repositories.findByName(repositoryName) ?: repositories.findByName(repositoryName.capitalize())

if (chart != null && repository != null) {

Expand All @@ -47,11 +48,13 @@ internal class HelmPublishChartToRepositoryTaskRule(

task.onlyIf { chart.publishConvention.publish.get() }

task.chartFile.set(project.layout.file(
task.chartFile.set(
project.layout.file(
project.provider {
project.configurations.getByName(chart.dirArtifactConfigurationName)
.singleFile
}))
project.configurations.getByName(chart.packagedArtifactConfigurationName)
.artifacts.single().file
})
)
task.targetRepository = repository
task.dependsOn(chart)
}
Expand All @@ -68,4 +71,4 @@ internal class HelmPublishChartToRepositoryTaskRule(
* @param repositoryName the name of the repository
*/
internal fun HelmChart.publishToRepositoryTaskName(repositoryName: String) =
HelmPublishChartToRepositoryTaskRule.getTaskName(name, repositoryName)
HelmPublishChartToRepositoryTaskRule.getTaskName(name, repositoryName)

0 comments on commit 50b8b2b

Please sign in to comment.