Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prerelease option added #452

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Flags:
-t, --token string GitHub Auth Token
--make-release-latest bool Mark the created GitHub release as 'latest' (default "true")
--packages-with-index Host the package files in the GitHub Pages branch
--prerelease Mark this as 'Pre-release' (default: false)

Global Flags:
--config string Config file (default is $HOME/.cr.yaml)
Expand Down
1 change: 1 addition & 0 deletions cr/cmd/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ func init() {
uploadCmd.Flags().Bool("push", false, "Push the chart package to the GitHub Pages branch (must not be set if --pr is set)")
uploadCmd.Flags().Bool("pr", false, "Create a pull request for the chart package against the GitHub Pages branch (must not be set if --push is set)")
uploadCmd.Flags().Bool("packages-with-index", false, "Host the package files in the GitHub Pages branch")
uploadCmd.Flags().Bool("prerelease", false, "Mark this as 'Pre-release' (default: false)")
}
1 change: 1 addition & 0 deletions doc/cr_upload.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ cr upload [flags]
--packages-with-index Host the package files in the GitHub Pages branch
--pages-branch string The GitHub pages branch (default "gh-pages")
--pr Create a pull request for the chart package against the GitHub Pages branch (must not be set if --push is set)
--prerelease Mark this as 'Pre-release' (default: false)
--push Push the chart package to the GitHub Pages branch (must not be set if --pr is set)
--release-name-template string Go template for computing release names, using chart metadata (default "{{ .Name }}-{{ .Version }}")
--release-notes-file string Markdown file with chart release notes. If it is set to empty string, or the file is not found, the chart description will be used instead. The file is read from the chart package
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type Options struct {
GenerateReleaseNotes bool `mapstructure:"generate-release-notes"`
MakeReleaseLatest bool `mapstructure:"make-release-latest"`
PackagesWithIndex bool `mapstructure:"packages-with-index"`
Prerelease bool `mapstructure:"prerelease"`
}

func LoadConfiguration(cfgFile string, cmd *cobra.Command, requiredFlags []string) (*Options, error) {
Expand Down
2 changes: 2 additions & 0 deletions pkg/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Release struct {
Commit string
GenerateReleaseNotes bool
MakeLatest string
Prerelease bool
}

type Asset struct {
Expand Down Expand Up @@ -111,6 +112,7 @@ func (c *Client) CreateRelease(_ context.Context, input *Release) error {
TargetCommitish: &input.Commit,
GenerateReleaseNotes: &input.GenerateReleaseNotes,
MakeLatest: &input.MakeLatest,
Prerelease: &input.Prerelease,
}

release, _, err := c.Repositories.CreateRelease(context.TODO(), c.owner, c.repo, req)
Expand Down
4 changes: 2 additions & 2 deletions pkg/releaser/releaser.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@ func (r *Releaser) UpdateIndexFile() (bool, error) {
// if pages-index-path doesn't end with index.yaml we can try and fix it
if filepath.Base(r.config.PagesIndexPath) != "index.yaml" {
// if path is a directory then add index.yaml
if stat, err := os.Stat(filepath.Join(worktree, r.config.PagesIndexPath)); err == nil && stat.IsDir() {
if err := os.MkdirAll(filepath.Join(worktree, r.config.PagesIndexPath), 0755); err == nil {
r.config.PagesIndexPath = filepath.Join(r.config.PagesIndexPath, "index.yaml")
// otherwise error out
} else {
fmt.Printf("pages-index-path (%s) should be a directory or a file called index.yaml\n", r.config.PagesIndexPath)
os.Exit(1) // nolint: gocritic
Expand Down Expand Up @@ -317,6 +316,7 @@ func (r *Releaser) CreateReleases() error {
Commit: r.config.Commit,
GenerateReleaseNotes: r.config.GenerateReleaseNotes,
MakeLatest: strconv.FormatBool(r.config.MakeReleaseLatest),
Prerelease: r.config.Prerelease,
}
provFile := fmt.Sprintf("%s.prov", p)
if _, err := os.Stat(provFile); err == nil {
Expand Down
7 changes: 7 additions & 0 deletions pkg/releaser/releaser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func (f *FakeGitHub) GetRelease(ctx context.Context, tag string) (*github.Releas
URL: "https://myrepo/charts/third-party-file-0.1.0.txt",
},
},
Prerelease: false,
}
return release, nil
}
Expand Down Expand Up @@ -362,6 +363,7 @@ func TestReleaser_CreateReleases(t *testing.T) {
version string
commit string
latest string
prerelease bool
Releaser *Releaser
error bool
}{
Expand All @@ -378,6 +380,7 @@ func TestReleaser_CreateReleases(t *testing.T) {
Commit: "",
PackagesWithIndex: false,
MakeReleaseLatest: true,
Prerelease: false,
},
},
error: true,
Expand All @@ -395,6 +398,7 @@ func TestReleaser_CreateReleases(t *testing.T) {
Commit: "",
PackagesWithIndex: false,
MakeReleaseLatest: true,
Prerelease: false,
},
},
error: false,
Expand All @@ -412,6 +416,7 @@ func TestReleaser_CreateReleases(t *testing.T) {
Commit: "5e239bd19fbefb9eb0181ecf0c7ef73b8fe2753c",
PackagesWithIndex: false,
MakeReleaseLatest: true,
Prerelease: false,
},
},
error: false,
Expand All @@ -430,6 +435,7 @@ func TestReleaser_CreateReleases(t *testing.T) {
PackagesWithIndex: true,
Push: true,
MakeReleaseLatest: true,
Prerelease: false,
},
},
error: false,
Expand Down Expand Up @@ -466,6 +472,7 @@ func TestReleaser_CreateReleases(t *testing.T) {
assert.Equal(t, assetPath, fakeGitHub.release.Assets[0].Path)
assert.Equal(t, tt.commit, fakeGitHub.release.Commit)
assert.Equal(t, tt.latest, fakeGitHub.release.MakeLatest)
assert.Equal(t, tt.prerelease, fakeGitHub.release.Prerelease)
assert.Equal(t, tt.Releaser.config.Commit, fakeGitHub.release.Commit)
fakeGitHub.AssertNumberOfCalls(t, "CreateRelease", 1)
}
Expand Down