From c5e56204fbe966e78793fc12496022ae751ae55b Mon Sep 17 00:00:00 2001 From: Manish Gupta Date: Wed, 4 Sep 2024 21:22:39 +0530 Subject: [PATCH 1/3] Prerelease option added Signed-off-by: Manish Gupta --- README.md | 1 + cr/cmd/upload.go | 1 + doc/cr_upload.md | 1 + pkg/config/config.go | 1 + pkg/github/github.go | 2 ++ pkg/releaser/releaser.go | 1 + pkg/releaser/releaser_test.go | 1 + 7 files changed, 8 insertions(+) diff --git a/README.md b/README.md index 4c0d0249..08109de3 100644 --- a/README.md +++ b/README.md @@ -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' Global Flags: --config string Config file (default is $HOME/.cr.yaml) diff --git a/cr/cmd/upload.go b/cr/cmd/upload.go index 032f8a5c..13fd0c4b 100644 --- a/cr/cmd/upload.go +++ b/cr/cmd/upload.go @@ -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'") } diff --git a/doc/cr_upload.md b/doc/cr_upload.md index a6bf1ec6..82c95a5d 100644 --- a/doc/cr_upload.md +++ b/doc/cr_upload.md @@ -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' --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 diff --git a/pkg/config/config.go b/pkg/config/config.go index a0d309ca..310dc11c 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -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) { diff --git a/pkg/github/github.go b/pkg/github/github.go index 4143c50d..80217f63 100644 --- a/pkg/github/github.go +++ b/pkg/github/github.go @@ -36,6 +36,7 @@ type Release struct { Commit string GenerateReleaseNotes bool MakeLatest string + Prerelease bool } type Asset struct { @@ -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) diff --git a/pkg/releaser/releaser.go b/pkg/releaser/releaser.go index 439ae818..58e1d8c6 100644 --- a/pkg/releaser/releaser.go +++ b/pkg/releaser/releaser.go @@ -317,6 +317,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 { diff --git a/pkg/releaser/releaser_test.go b/pkg/releaser/releaser_test.go index 55c7841f..9974b5d3 100644 --- a/pkg/releaser/releaser_test.go +++ b/pkg/releaser/releaser_test.go @@ -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 } From be40a307cd1cc50f39c7c92d473236e017c4d139 Mon Sep 17 00:00:00 2001 From: Manish Gupta Date: Thu, 5 Sep 2024 12:12:12 +0530 Subject: [PATCH 2/3] updated Help content and test case Signed-off-by: Manish Gupta --- README.md | 2 +- cr/cmd/upload.go | 2 +- doc/cr_upload.md | 2 +- pkg/releaser/releaser_test.go | 6 ++++++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 08109de3..5f8e558e 100644 --- a/README.md +++ b/README.md @@ -107,7 +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' + --prerelease Mark this as 'Pre-release' (default: false) Global Flags: --config string Config file (default is $HOME/.cr.yaml) diff --git a/cr/cmd/upload.go b/cr/cmd/upload.go index 13fd0c4b..cd436657 100644 --- a/cr/cmd/upload.go +++ b/cr/cmd/upload.go @@ -62,5 +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'") + uploadCmd.Flags().Bool("prerelease", false, "Mark this as 'Pre-release' (default: false)") } diff --git a/doc/cr_upload.md b/doc/cr_upload.md index 82c95a5d..59b709a9 100644 --- a/doc/cr_upload.md +++ b/doc/cr_upload.md @@ -25,7 +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' + --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 diff --git a/pkg/releaser/releaser_test.go b/pkg/releaser/releaser_test.go index 9974b5d3..62d82170 100644 --- a/pkg/releaser/releaser_test.go +++ b/pkg/releaser/releaser_test.go @@ -363,6 +363,7 @@ func TestReleaser_CreateReleases(t *testing.T) { version string commit string latest string + prerelease bool Releaser *Releaser error bool }{ @@ -379,6 +380,7 @@ func TestReleaser_CreateReleases(t *testing.T) { Commit: "", PackagesWithIndex: false, MakeReleaseLatest: true, + Prerelease: false, }, }, error: true, @@ -396,6 +398,7 @@ func TestReleaser_CreateReleases(t *testing.T) { Commit: "", PackagesWithIndex: false, MakeReleaseLatest: true, + Prerelease: false, }, }, error: false, @@ -413,6 +416,7 @@ func TestReleaser_CreateReleases(t *testing.T) { Commit: "5e239bd19fbefb9eb0181ecf0c7ef73b8fe2753c", PackagesWithIndex: false, MakeReleaseLatest: true, + Prerelease: false, }, }, error: false, @@ -431,6 +435,7 @@ func TestReleaser_CreateReleases(t *testing.T) { PackagesWithIndex: true, Push: true, MakeReleaseLatest: true, + Prerelease: false, }, }, error: false, @@ -467,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) } From 0a5bd257517ea3298371aba184318742e33be47a Mon Sep 17 00:00:00 2001 From: Manish Gupta Date: Mon, 9 Sep 2024 13:41:29 +0530 Subject: [PATCH 3/3] added folder creation as per pages-index-path Signed-off-by: Manish Gupta --- pkg/releaser/releaser.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/releaser/releaser.go b/pkg/releaser/releaser.go index 58e1d8c6..3e0ffa0f 100644 --- a/pkg/releaser/releaser.go +++ b/pkg/releaser/releaser.go @@ -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