mirror of
https://github.com/helm/chart-releaser.git
synced 2026-02-05 09:45:23 +01:00
* add packages-with-index flag Signed-off-by: Steven Barnes <Steven.Barnes@topgolf.com> * Add unit tests Signed-off-by: Steven Barnes <Steven.Barnes@topgolf.com> * delete files created by test Signed-off-by: Steven Barnes <Steven.Barnes@topgolf.com> * Authenticate to get existing index.yaml Signed-off-by: Steven Barnes <Steven.Barnes@topgolf.com> * update docs Signed-off-by: cpanato <ctadeu@gmail.com> * fix lints Signed-off-by: cpanato <ctadeu@gmail.com> * add git pull function Signed-off-by: cpanato <ctadeu@gmail.com> * update help text for upload command Signed-off-by: cpanato <ctadeu@gmail.com> --------- Signed-off-by: Steven Barnes <Steven.Barnes@topgolf.com> Signed-off-by: cpanato <ctadeu@gmail.com> Co-authored-by: cpanato <ctadeu@gmail.com>
97 lines
3.0 KiB
Go
97 lines
3.0 KiB
Go
// Copyright The Helm Authors
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package git
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
type Git struct{}
|
|
|
|
// AddWorktree creates a new Git worktree with a detached HEAD for the given committish and returns its path.
|
|
func (g *Git) AddWorktree(workingDir string, committish string) (string, error) {
|
|
dir, err := os.MkdirTemp("", "chart-releaser-")
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
command := exec.Command("git", "worktree", "add", "--detach", dir, committish)
|
|
|
|
if err := runCommand(workingDir, command); err != nil {
|
|
return "", err
|
|
}
|
|
return dir, nil
|
|
}
|
|
|
|
// RemoveWorktree removes the Git worktree with the given path.
|
|
func (g *Git) RemoveWorktree(workingDir string, path string) error {
|
|
command := exec.Command("git", "worktree", "remove", path, "--force")
|
|
return runCommand(workingDir, command)
|
|
}
|
|
|
|
// Add runs 'git add' with the given args.
|
|
func (g *Git) Add(workingDir string, args ...string) error {
|
|
if len(args) == 0 {
|
|
return fmt.Errorf("no args specified")
|
|
}
|
|
addArgs := []string{"add"}
|
|
addArgs = append(addArgs, args...)
|
|
command := exec.Command("git", addArgs...)
|
|
return runCommand(workingDir, command)
|
|
}
|
|
|
|
// Commit runs 'git commit' with the given message. the commit is signed off.
|
|
func (g *Git) Commit(workingDir string, message string) error {
|
|
command := exec.Command("git", "commit", "--message", message, "--signoff")
|
|
return runCommand(workingDir, command)
|
|
}
|
|
|
|
// UpdateBranch runs 'git pull' with the given args.
|
|
func (g *Git) Pull(workingDir string, args ...string) error {
|
|
pullArgs := []string{"pull"}
|
|
pullArgs = append(pullArgs, args...)
|
|
command := exec.Command("git", pullArgs...)
|
|
return runCommand(workingDir, command)
|
|
}
|
|
|
|
// Push runs 'git push' with the given args.
|
|
func (g *Git) Push(workingDir string, args ...string) error {
|
|
pushArgs := []string{"push"}
|
|
pushArgs = append(pushArgs, args...)
|
|
command := exec.Command("git", pushArgs...)
|
|
return runCommand(workingDir, command)
|
|
}
|
|
|
|
// GetPushURL returns the push url with a token inserted
|
|
func (g *Git) GetPushURL(remote string, token string) (string, error) {
|
|
pushURL, err := exec.Command("git", "remote", "get-url", "--push", remote).Output()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
pushURLArray := strings.SplitAfter(strings.TrimSpace(string(pushURL)), "https://")
|
|
pushURLWithToken := fmt.Sprintf("https://x-access-token:%s@%s", token, pushURLArray[1])
|
|
return pushURLWithToken, nil
|
|
}
|
|
|
|
func runCommand(workingDir string, command *exec.Cmd) error {
|
|
command.Dir = workingDir
|
|
command.Stdout = os.Stdout
|
|
command.Stderr = os.Stderr
|
|
return command.Run()
|
|
}
|