Skip to content

Commit

Permalink
Add option to not mark GitHub release as latest (#237)
Browse files Browse the repository at this point in the history
Signed-off-by: Philipp Trulson <[email protected]>

Signed-off-by: Philipp Trulson <[email protected]>
  • Loading branch information
der-eismann authored Jan 5, 2023
1 parent 3719ff6 commit ee26f50
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Flags:
--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
--skip-existing Skip upload if release exists
-t, --token string GitHub Auth Token
--make-release-latest bool Mark the created GitHub release as 'latest' (default "true")

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 @@ -56,4 +56,5 @@ func init() {
uploadCmd.Flags().String("release-notes-file", "", "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")
uploadCmd.Flags().Bool("generate-release-notes", false, "Whether to automatically generate the name and body for this release. See https://docs.github.com/en/rest/releases/releases")
uploadCmd.Flags().Bool("make-release-latest", true, "Mark the created GitHub release as 'latest'")
}
1 change: 1 addition & 0 deletions doc/cr_upload.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ cr upload [flags]
-r, --git-repo string GitHub repository
-u, --git-upload-url string GitHub Upload URL (only needed for private GitHub) (default "https://uploads.github.com/")
-h, --help help for upload
--make-release-latest Mark the created GitHub release as 'latest' (default true)
-o, --owner string GitHub username or organization
-p, --package-path string Path to directory with chart packages (default ".cr-release-packages")
--release-name-template string Go template for computing release names, using chart metadata (default "{{ .Name }}-{{ .Version }}")
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type Options struct {
SkipExisting bool `mapstructure:"skip-existing"`
ReleaseNotesFile string `mapstructure:"release-notes-file"`
GenerateReleaseNotes bool `mapstructure:"generate-release-notes"`
MakeReleaseLatest bool `mapstructure:"make-release-latest"`
}

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 @@ -35,6 +35,7 @@ type Release struct {
Assets []*Asset
Commit string
GenerateReleaseNotes bool
MakeLatest string
}

type Asset struct {
Expand Down Expand Up @@ -109,6 +110,7 @@ func (c *Client) CreateRelease(ctx context.Context, input *Release) error {
TagName: &input.Name,
TargetCommitish: &input.Commit,
GenerateReleaseNotes: &input.GenerateReleaseNotes,
MakeLatest: &input.MakeLatest,
}

release, _, err := c.Repositories.CreateRelease(context.TODO(), c.owner, c.repo, req)
Expand Down
2 changes: 2 additions & 0 deletions pkg/releaser/releaser.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"net/url"
"os"
"path/filepath"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -337,6 +338,7 @@ func (r *Releaser) CreateReleases() error {
},
Commit: r.config.Commit,
GenerateReleaseNotes: r.config.GenerateReleaseNotes,
MakeLatest: strconv.FormatBool(r.config.MakeReleaseLatest),
}
provFile := fmt.Sprintf("%s.prov", p)
if _, err := os.Stat(provFile); err == nil {
Expand Down
6 changes: 6 additions & 0 deletions pkg/releaser/releaser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ func TestReleaser_CreateReleases(t *testing.T) {
chart string
version string
commit string
latest string
error bool
}{
{
Expand All @@ -309,6 +310,7 @@ func TestReleaser_CreateReleases(t *testing.T) {
"test-chart",
"0.1.0",
"",
"true",
true,
},
{
Expand All @@ -317,6 +319,7 @@ func TestReleaser_CreateReleases(t *testing.T) {
"test-chart",
"0.1.0",
"",
"true",
false,
},
{
Expand All @@ -325,6 +328,7 @@ func TestReleaser_CreateReleases(t *testing.T) {
"test-chart",
"0.1.0",
"5e239bd19fbefb9eb0181ecf0c7ef73b8fe2753c",
"true",
false,
},
}
Expand All @@ -336,6 +340,7 @@ func TestReleaser_CreateReleases(t *testing.T) {
PackagePath: tt.packagePath,
Commit: tt.commit,
ReleaseNameTemplate: "{{ .Name }}-{{ .Version }}",
MakeReleaseLatest: true,
},
github: fakeGitHub,
}
Expand All @@ -355,6 +360,7 @@ func TestReleaser_CreateReleases(t *testing.T) {
assert.Len(t, fakeGitHub.release.Assets, 1)
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)
fakeGitHub.AssertNumberOfCalls(t, "CreateRelease", 1)
}
})
Expand Down

0 comments on commit ee26f50

Please sign in to comment.