aboutsummaryrefslogtreecommitdiffhomepage
path: root/releaser
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2021-12-08 09:23:18 +0100
committerBjørn Erik Pedersen <[email protected]>2021-12-08 09:38:15 +0100
commit0fa40ce58f612b3d38842d896a71c2322df4d80b (patch)
tree6575532ad887a3d833bfb362a6332f12ede0e25e /releaser
parentbf537f1c6d7dafe3c16f6d2d0b16d3f98754594c (diff)
downloadhugo-0fa40ce58f612b3d38842d896a71c2322df4d80b.tar.gz
hugo-0fa40ce58f612b3d38842d896a71c2322df4d80b.zip
releaser: Simplify the release process
Make it into a one step even for major releases.
Diffstat (limited to 'releaser')
-rw-r--r--releaser/releasenotes_writer.go42
-rw-r--r--releaser/releaser.go98
2 files changed, 39 insertions, 101 deletions
diff --git a/releaser/releasenotes_writer.go b/releaser/releasenotes_writer.go
index 3bca5b70a..e7d9255e7 100644
--- a/releaser/releasenotes_writer.go
+++ b/releaser/releasenotes_writer.go
@@ -163,54 +163,22 @@ func fetchThemeCount() (int, error) {
return bytes.Count(b, []byte("\n")) - bytes.Count(b, []byte("#")), nil
}
-func getReleaseNotesDocsTempDirAndName(version string, final bool) (string, string) {
- if final {
- return hugoFilepath("temp"), fmt.Sprintf("%s-relnotes-ready.md", version)
- }
- return hugoFilepath("temp"), fmt.Sprintf("%s-relnotes.md", version)
-}
-
-func getReleaseNotesDocsTempFilename(version string, final bool) string {
- return filepath.Join(getReleaseNotesDocsTempDirAndName(version, final))
-}
-
-func (r *ReleaseHandler) releaseNotesState(version string) (releaseNotesState, error) {
- docsTempPath, name := getReleaseNotesDocsTempDirAndName(version, false)
- _, err := os.Stat(filepath.Join(docsTempPath, name))
-
- if err == nil {
- return releaseNotesCreated, nil
- }
+func getReleaseNotesFilename(version string) string {
+ return filepath.FromSlash(fmt.Sprintf("temp/%s-relnotes-ready.md", version))
- docsTempPath, name = getReleaseNotesDocsTempDirAndName(version, true)
- _, err = os.Stat(filepath.Join(docsTempPath, name))
-
- if err == nil {
- return releaseNotesReady, nil
- }
-
- if !os.IsNotExist(err) {
- return releaseNotesNone, err
- }
-
- return releaseNotesNone, nil
}
func (r *ReleaseHandler) writeReleaseNotesToTemp(version string, isPatch bool, infosMain, infosDocs gitInfos) (string, error) {
- docsTempPath, name := getReleaseNotesDocsTempDirAndName(version, isPatch)
+ filename := getReleaseNotesFilename(version)
var w io.WriteCloser
if !r.try {
- os.Mkdir(docsTempPath, os.ModePerm)
-
- f, err := os.Create(filepath.Join(docsTempPath, name))
+ f, err := os.Create(filename)
if err != nil {
return "", err
}
- name = f.Name()
-
defer f.Close()
w = f
@@ -223,5 +191,5 @@ func (r *ReleaseHandler) writeReleaseNotesToTemp(version string, isPatch bool, i
return "", err
}
- return name, nil
+ return filename, nil
}
diff --git a/releaser/releaser.go b/releaser/releaser.go
index e87836fd5..bb2abc553 100644
--- a/releaser/releaser.go
+++ b/releaser/releaser.go
@@ -32,15 +32,10 @@ import (
const commitPrefix = "releaser:"
-type releaseNotesState int
-
-const (
- releaseNotesNone = iota
- releaseNotesCreated
- releaseNotesReady
-)
-
// ReleaseHandler provides functionality to release a new version of Hugo.
+// Test this locally without doing an actual release:
+// go run -tags release main.go release --skip-publish --try -r 0.90.0
+// Or a variation of the above -- the skip-publish flag makes sure that any changes are performed to the local Git only.
type ReleaseHandler struct {
cliVersion string
@@ -91,6 +86,8 @@ func (r *ReleaseHandler) Run() error {
return errors.New("GITHUB_TOKEN not set, create one here with the repo scope selected: https://github.com/settings/tokens/new")
}
+ fmt.Printf("Start release from %q\n", wd())
+
newVersion, finalVersion := r.calculateVersions()
version := newVersion.String()
@@ -124,61 +121,35 @@ func (r *ReleaseHandler) Run() error {
var (
gitCommits gitInfos
gitCommitsDocs gitInfos
- relNotesState releaseNotesState
)
- relNotesState, err = r.releaseNotesState(version)
+ defer r.gitPush() // TODO(bep)
+
+ gitCommits, err = getGitInfos(changeLogFromTag, "hugo", "", !r.try)
if err != nil {
return err
}
- prepareReleaseNotes := isPatch || relNotesState == releaseNotesNone
- shouldRelease := isPatch || relNotesState == releaseNotesReady
-
- defer r.gitPush() // TODO(bep)
-
- if prepareReleaseNotes || shouldRelease {
- gitCommits, err = getGitInfos(changeLogFromTag, "hugo", "", !r.try)
- if err != nil {
- return err
- }
-
- // TODO(bep) explicit tag?
- gitCommitsDocs, err = getGitInfos("", "hugoDocs", "../hugoDocs", !r.try)
- if err != nil {
- return err
- }
+ // TODO(bep) explicit tag?
+ gitCommitsDocs, err = getGitInfos("", "hugoDocs", "../hugoDocs", !r.try)
+ if err != nil {
+ return err
}
- if relNotesState == releaseNotesCreated {
- fmt.Println("Release notes created, but not ready. Rename to *-ready.md to continue ...")
- return nil
+ releaseNotesFile, err := r.writeReleaseNotesToTemp(version, isPatch, gitCommits, gitCommitsDocs)
+ if err != nil {
+ return err
}
- if prepareReleaseNotes {
- releaseNotesFile, err := r.writeReleaseNotesToTemp(version, isPatch, gitCommits, gitCommitsDocs)
- if err != nil {
- return err
- }
-
- if _, err := r.git("add", releaseNotesFile); err != nil {
- return err
- }
-
- commitMsg := fmt.Sprintf("%s Add release notes for %s", commitPrefix, newVersion)
- if !isPatch {
- commitMsg += "\n\nRename to *-ready.md to continue."
- }
- commitMsg += "\n[ci skip]"
-
- if _, err := r.git("commit", "-m", commitMsg); err != nil {
- return err
- }
+ if _, err := r.git("add", releaseNotesFile); err != nil {
+ return err
}
- if !shouldRelease {
- fmt.Printf("Skip release ... ")
- return nil
+ commitMsg := fmt.Sprintf("%s Add release notes for %s", commitPrefix, newVersion)
+ commitMsg += "\n[ci skip]"
+
+ if _, err := r.git("commit", "-m", commitMsg); err != nil {
+ return err
}
if err := r.bumpVersions(newVersion); err != nil {
@@ -189,7 +160,7 @@ func (r *ReleaseHandler) Run() error {
return err
}
- if _, err := r.git("tag", "-a", tag, "-m", fmt.Sprintf("%s %s [ci skip]", commitPrefix, newVersion)); err != nil {
+ if _, err := r.git("tag", "-a", tag, "-m", fmt.Sprintf("%s %s\n\n[ci skip]", commitPrefix, newVersion)); err != nil {
return err
}
@@ -199,8 +170,6 @@ func (r *ReleaseHandler) Run() error {
}
}
- releaseNotesFile := getReleaseNotesDocsTempFilename(version, true)
-
if err := r.release(releaseNotesFile); err != nil {
return err
}
@@ -295,8 +264,8 @@ func (r *ReleaseHandler) bumpVersions(ver hugo.Version) error {
}
func (r *ReleaseHandler) replaceInFile(filename string, oldNew ...string) error {
- fullFilename := hugoFilepath(filename)
- fi, err := os.Stat(fullFilename)
+ filename = filepath.FromSlash(filename)
+ fi, err := os.Stat(filename)
if err != nil {
return err
}
@@ -306,7 +275,7 @@ func (r *ReleaseHandler) replaceInFile(filename string, oldNew ...string) error
return nil
}
- b, err := ioutil.ReadFile(fullFilename)
+ b, err := ioutil.ReadFile(filename)
if err != nil {
return err
}
@@ -317,17 +286,18 @@ func (r *ReleaseHandler) replaceInFile(filename string, oldNew ...string) error
newContent = re.ReplaceAllString(newContent, oldNew[i+1])
}
- return ioutil.WriteFile(fullFilename, []byte(newContent), fi.Mode())
+ return ioutil.WriteFile(filename, []byte(newContent), fi.Mode())
+}
+
+func isCI() bool {
+ return os.Getenv("CI") != ""
}
-func hugoFilepath(filename string) string {
- pwd, err := os.Getwd()
+func wd() string {
+ p, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
- return filepath.Join(pwd, filename)
-}
+ return p
-func isCI() bool {
- return os.Getenv("CI") != ""
}