Skip to content

Commit

Permalink
add tag flag
Browse files Browse the repository at this point in the history
  • Loading branch information
pete911 committed Dec 31, 2021
1 parent 78a5bb1 commit 945b454
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Usage of hcr:
The GitHub pages branch (default "gh-pages")
-remote string
The Git remote for the GitHub Pages branch (default "origin")
-tag string
Release tag, defaults to chart version
-token string
GitHub Auth Token
```
Expand Down
3 changes: 3 additions & 0 deletions internal/flag/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
type flags struct {
pagesBranch string
chartsDir string
tag string
remote string
token string
}
Expand All @@ -20,6 +21,7 @@ func ParseFlags() (hcr.Config, error) {

flagSet.StringVar(&f.pagesBranch, "pages-branch", getStringEnv("HCR_PAGES_BRANCH", "gh-pages"), "The GitHub pages branch")
flagSet.StringVar(&f.chartsDir, "charts-dir", getStringEnv("HCR_CHARTS_DIR", "charts"), "The Helm charts location")
flagSet.StringVar(&f.tag, "tag", getStringEnv("HCR_TAG", ""), "Release tag, defaults to chart version")
flagSet.StringVar(&f.remote, "remote", getStringEnv("HCR_REMOTE", "origin"), "The Git remote for the GitHub Pages branch")
flagSet.StringVar(&f.token, "token", getStringEnv("HCR_TOKEN", ""), "GitHub Auth Token")

Expand All @@ -34,6 +36,7 @@ func ParseFlags() (hcr.Config, error) {
return hcr.Config{
PagesBranch: f.pagesBranch,
ChartsDir: f.chartsDir,
Tag: f.tag,
Remote: f.remote,
Token: f.token,
}, nil
Expand Down
3 changes: 2 additions & 1 deletion internal/hcr/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "fmt"
type Config struct {
PagesBranch string
ChartsDir string
Tag string
Remote string
Token string
}
Expand All @@ -14,5 +15,5 @@ func (c Config) String() string {
if len(c.Token) == 0 {
token = "<empty>"
}
return fmt.Sprintf("pages-branch: %q, charts-dir: %q, remote: %q, token: %q", c.PagesBranch, c.ChartsDir, c.Remote, token)
return fmt.Sprintf("pages-branch: %q, charts-dir: %q, tag: %q, remote: %q, token: %q", c.PagesBranch, c.ChartsDir, c.Tag, c.Remote, token)
}
11 changes: 7 additions & 4 deletions internal/hcr/releaser.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,21 @@ func (r Releaser) releaseAndUpdateIndex(ctx context.Context, ghPagesDir string,
var updated bool
indexFile := filepath.Join(ghPagesDir, "index.yaml")
for chPath, ch := range charts {
tag := fmt.Sprintf("%s-%s", ch.Name(), ch.Metadata.Version)
tag := r.config.Tag
if tag == "" {
tag = ch.Metadata.Version
}
ok, err := r.ghClient.ReleaseExists(ctx, owner, repo, tag)
if err != nil {
return false, fmt.Errorf("release %s exists: %w", tag, err)
return false, fmt.Errorf("%s release %s exists: %w", ch.Name(), tag, err)
}
if ok {
r.log.Info(fmt.Sprintf("release %s already exists, skipping", tag))
r.log.Info(fmt.Sprintf("%s release %s already exists, skipping", ch.Name(), tag))
continue
}

release := github.Release{
Name: tag,
Name: fmt.Sprintf("%s-%s", ch.Name(), ch.Metadata.Version),
Description: fmt.Sprintf("Kubernetes %s Helm chart", ch.Name()),
AssetPath: chPath,
PreRelease: false,
Expand Down

0 comments on commit 945b454

Please sign in to comment.