Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
templating support for asset names:
Browse files Browse the repository at this point in the history
'filename-darwin-{{.ReleaseVersion}'
  • Loading branch information
AnalogJ committed Oct 5, 2018
1 parent 0073833 commit 982732c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
15 changes: 14 additions & 1 deletion pkg/scm/scm_bitbucket.go
Expand Up @@ -16,6 +16,8 @@ import (
"capsulecd/pkg/utils"
"strconv"
"path"
"bytes"
"text/template"
)

type scmBitbucket struct {
Expand Down Expand Up @@ -373,11 +375,22 @@ func (b *scmBitbucket) PublishAssets(releaseData interface{}) error {
parts := strings.Split(b.Config.GetString("scm_repo_full_name"), "/")

for _, assetData := range b.PipelineData.ReleaseAssets {
// handle templated destination artifact names
artifactNameTmpl, err := template.New("artifactName").Parse(assetData.ArtifactName)
if err != nil {
return err
}

var artifactNamePopulated bytes.Buffer
if err := artifactNameTmpl.Execute(&artifactNamePopulated, b.PipelineData); err != nil {
return err
}

b.publishAsset(
b.Client,
parts[0],
parts[1],
assetData.ArtifactName,
artifactNamePopulated.String(),
path.Join(b.PipelineData.GitLocalPath, assetData.LocalPath),
5)
}
Expand Down
15 changes: 14 additions & 1 deletion pkg/scm/scm_github.go
Expand Up @@ -18,6 +18,8 @@ import (
"strconv"
"strings"
"time"
"text/template"
"bytes"
)

type scmGithub struct {
Expand Down Expand Up @@ -307,12 +309,23 @@ func (g *scmGithub) PublishAssets(releaseData interface{}) error {
parts := strings.Split(g.Config.GetString("scm_repo_full_name"), "/")

for _, assetData := range g.PipelineData.ReleaseAssets {
// handle templated destination artifact names
artifactNameTmpl, err := template.New("artifactName").Parse(assetData.ArtifactName)
if err != nil {
return err
}

var artifactNamePopulated bytes.Buffer
if err := artifactNameTmpl.Execute(&artifactNamePopulated, g.PipelineData); err != nil {
return err
}

g.publishGithubAsset(
g.Client,
ctx,
parts[0],
parts[1],
assetData.ArtifactName,
artifactNamePopulated.String(),
path.Join(g.PipelineData.GitLocalPath, assetData.LocalPath),
releaseId,
5)
Expand Down

0 comments on commit 982732c

Please sign in to comment.