diff --git a/cmd/index.go b/cmd/index.go index e4385e5..042ce86 100644 --- a/cmd/index.go +++ b/cmd/index.go @@ -62,5 +62,5 @@ func init() { flags.Bool("push", false, "Push index.yaml to the GitHub Pages branch (must not be set if --pr is set)") flags.Bool("pr", false, "Create a pull request for index.yaml against the GitHub Pages branch (must not be set if --push is set)") flags.String("release-name-template", "{{ .Name }}-{{ .Version }}", "Go template for computing release names, using chart metadata") - flags.Bool("packages-with-index", false, "Save a copy of the package files to the GitHub pages branch and reference them in the index") + flags.Bool("packages-with-index", false, "Override the download url to point to files in the GitHub Pages branch instead of the release assets") } diff --git a/cmd/upload.go b/cmd/upload.go index 2d42990..56808a5 100644 --- a/cmd/upload.go +++ b/cmd/upload.go @@ -53,4 +53,5 @@ func init() { uploadCmd.Flags().StringP("commit", "c", "", "Target commit for release") uploadCmd.Flags().Bool("skip-existing", false, "Skip upload if release exists") uploadCmd.Flags().String("release-name-template", "{{ .Name }}-{{ .Version }}", "Go template for computing release names, using chart metadata") + uploadCmd.Flags().Bool("packages-with-index", false, "Save a copy of the package files to the GitHub Pages branch") } diff --git a/pkg/releaser/releaser.go b/pkg/releaser/releaser.go index 6e92fb8..1a020ad 100644 --- a/pkg/releaser/releaser.go +++ b/pkg/releaser/releaser.go @@ -19,7 +19,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "math/rand" "net/http" "net/url" @@ -180,13 +179,6 @@ func (r *Releaser) UpdateIndexFile() (bool, error) { if err := r.addToIndexFile(indexFile, downloadUrl.String()); err != nil { return false, err } - if r.config.PackagesWithIndex { - indexBasePath := filepath.Dir(r.config.IndexPath) - chartTargetPath := filepath.Join(indexBasePath, filepath.Base(chartPackage)) - if err := copyFile(chartPackage, chartTargetPath); err != nil { - return false, err - } - } update = true break } @@ -217,24 +209,14 @@ func (r *Releaser) UpdateIndexFile() (bool, error) { } defer r.git.RemoveWorktree("", worktree) // nolint, errcheck - indexBasePath := filepath.Dir(r.config.IndexPath) - files, _ := ioutil.ReadDir(indexBasePath) - for _, file := range files { - oldFilePath := filepath.Join(indexBasePath, file.Name()) - newFilePath := filepath.Join(worktree, file.Name()) - if err := copyFile(oldFilePath, newFilePath); err != nil { - return false, err - } - if err := r.git.Add(worktree, newFilePath); err != nil { - return false, err - } + indexYamlPath := filepath.Join(worktree, "index.yaml") + if err := copyFile(r.config.IndexPath, indexYamlPath); err != nil { + return false, err } - - commitMsg := "Update index.yaml" - if r.config.PackagesWithIndex { - commitMsg = "Publishing chart" + if err := r.git.Add(worktree, indexYamlPath); err != nil { + return false, err } - if err := r.git.Commit(worktree, commitMsg); err != nil { + if err := r.git.Commit(worktree, "Update index.yaml"); err != nil { return false, err } @@ -308,8 +290,9 @@ func (r *Releaser) addToIndexFile(indexFile *repo.IndexFile, url string) error { s := strings.Split(url, "/") s = s[:len(s)-1] - // the chart will be stored in the same repo as the index file so let's make the path relative if r.config.PackagesWithIndex { + // the chart will be stored in the same repo as + // the index file so let's make the path relative s = s[:0] } @@ -362,6 +345,27 @@ func (r *Releaser) CreateReleases() error { if err := r.github.CreateRelease(context.TODO(), release); err != nil { return errors.Wrapf(err, "error creating GitHub release %s", releaseName) } + + if r.config.PackagesWithIndex { + worktree, err := r.git.AddWorktree("", r.config.Remote+"/"+r.config.PagesBranch) + if err != nil { + return err + } + defer r.git.RemoveWorktree("", worktree) // nolint, errcheck + + pkgTargetPath := filepath.Join(worktree, filepath.Base(p)) + if err := copyFile(p, pkgTargetPath); err != nil { + return err + } + + if err := r.git.Add(worktree, pkgTargetPath); err != nil { + return err + } + + if err := r.git.Commit(worktree, fmt.Sprintf("Publishing chart package for %s", releaseName)); err != nil { + return err + } + } } return nil