Skip to content

Commit

Permalink
error messages and stderr (#281)
Browse files Browse the repository at this point in the history
  • Loading branch information
ATGardner authored Feb 5, 2024
1 parent 8582572 commit 8e408a5
Showing 1 changed file with 35 additions and 13 deletions.
48 changes: 35 additions & 13 deletions hack/release/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func getCurrentCommitSha() (string, error) {
if err != nil {
return "", err
}

rs := strings.Split(string(result), "\n")
return strings.Split(rs[0], " ")[0], nil
}
Expand All @@ -34,12 +35,14 @@ func getArgoCDVersion() (string, error) {
if err != nil {
return "", err
}

pattern := `release-(\d+\.\d+)`
re := regexp.MustCompile(pattern)
matches := re.FindStringSubmatch(string(result))
if len(matches) >= 2 {
return matches[1], nil
}

return "", fmt.Errorf("failed to get argocd version")
}

Expand All @@ -50,10 +53,12 @@ func getLatestVersion() (string, error) {
if err != nil {
return "", err
}

argocdVersion, err := getArgoCDVersion()
if err != nil {
return "", err
}

return fmt.Sprintf("%s-%s-%s", argocdVersion, time.Now().Format("2006.1.2"), commitSha), nil
}

Expand All @@ -78,6 +83,7 @@ func readChangelog() (string, error) {
if err != nil {
return "", err
}

return string(data), nil
}

Expand All @@ -86,11 +92,14 @@ func moveChangelog() error {
if err != nil {
return err
}

// mv changelog/CHANGELOG.md changelog/CHANGELOG-<version>.md
cmd := exec.Command("mv", "changelog/CHANGELOG.md", fmt.Sprintf("changelog/CHANGELOG-%s.md", version))
if err := cmd.Run(); err != nil {
if output, err := cmd.CombinedOutput(); err != nil {
fmt.Print(string(output))
return err
}

return nil
}

Expand All @@ -99,62 +108,75 @@ func release() error {
if err != nil {
return err
}

fmt.Printf("Releasing version: %s\n", version)
err = updateVersion(version)
if err != nil {
return err
}

changelog, err := readChangelog()
if err != nil {
return err
}

fmt.Printf("Changelog: %s\n", changelog)
release := fmt.Sprintf("release-v%s", version)
fmt.Printf("Release: %s\n", release)
err = moveChangelog()
if err != nil {
return err
}

err = commitChanges(version)
if err != nil {
return err
}

// git tag -a v2.9.3-2021.07.07-3a4b7f4 -m "Codefresh version for synced 2.9.3"
_ = exec.Command("git", "tag", "-d", release).Run()
cmd := exec.Command("git", "tag", "-a", release, "-m", changelog)
if err := cmd.Run(); err != nil {
return err
if output, err := cmd.CombinedOutput(); err != nil {
fmt.Print(string(output))
return fmt.Errorf("failed to tag: %w", err)
}

// git push remote-name --delete tag-name
_ = exec.Command("git", "push", "origin", "--delete", release).Run()
// git push origin tags/version
cmd = exec.Command("git", "push", "origin", "tags/"+release)
if err := cmd.Run(); err != nil {
return err
if output, err := cmd.CombinedOutput(); err != nil {
fmt.Print(string(output))
return fmt.Errorf("failed to push tag: %w", err)
}

return exec.Command("git", "push", "origin", "--delete", release).Run()
}

func commitChanges(version string) error {
// git add VERSION
cmd := exec.Command("git", "add", "VERSION")
if err := cmd.Run(); err != nil {
return err
if output, err := cmd.CombinedOutput(); err != nil {
fmt.Print(string(output))
return fmt.Errorf("failed to add version: %w", err)
}

cmd = exec.Command("git", "add", fmt.Sprintf("changelog/CHANGELOG-%s.md", version))
if err := cmd.Run(); err != nil {
return err
if output, err := cmd.CombinedOutput(); err != nil {
fmt.Print(string(output))
return fmt.Errorf("failed to add changelog: %w", err)
}

cmd = exec.Command("git", "commit", "-a", "-m", fmt.Sprintf("chore: update version to %s", version))
if err := cmd.Run(); err != nil {
return err
if output, err := cmd.CombinedOutput(); err != nil {
fmt.Print(string(output))
return fmt.Errorf("failed to commit changes: %w", err)
}

cmd = exec.Command("git", "push")
if err := cmd.Run(); err != nil {
return err
if output, err := cmd.CombinedOutput(); err != nil {
fmt.Print(string(output))
return fmt.Errorf("failed to push changes: %w", err)
}

return nil
Expand Down

0 comments on commit 8e408a5

Please sign in to comment.