@@ -30,28 +30,32 @@ import (
3030const commitPrefix = "releaser:"
3131
3232// New initializes a ReleaseHandler.
33- func New (skipPush , try bool , step int ) (* ReleaseHandler , error ) {
33+ // Note that version is only used for testig. In CI we derive the version from the branch name.
34+ func New (skipPush , try bool , step int , version string ) (* ReleaseHandler , error ) {
3435 if step < 1 || step > 2 {
3536 return nil , fmt .Errorf ("step must be 1 or 2" )
3637 }
3738
38- prefix := "release-"
39- branch , err := git ("rev-parse" , "--abbrev-ref" , "HEAD" )
40- if err != nil {
41- return nil , err
42- }
43- branch = strings .TrimSpace (branch )
39+ if version == "" {
40+ prefix := "release-"
41+ branch , err := git ("rev-parse" , "--abbrev-ref" , "HEAD" )
42+ if err != nil {
43+ return nil , err
44+ }
45+ branch = strings .TrimSpace (branch )
46+
47+ if ! strings .HasPrefix (branch , prefix ) {
48+ return nil , fmt .Errorf ("branch %q is not a release branch" , branch )
49+ }
4450
45- if ! strings .HasPrefix (branch , prefix ) {
46- return nil , fmt .Errorf ("branch %q is not a release branch" , branch )
51+ version = strings .TrimPrefix (branch , prefix )
4752 }
4853
49- version := strings .TrimPrefix (branch , prefix )
5054 version = strings .TrimPrefix (version , "v" )
5155
52- logf ("Branch: %s| Version: v%s\n " , branch , version )
56+ logf ("Version: v%s\n " , version )
5357
54- rh := & ReleaseHandler {branchVersion : version , skipPush : skipPush , try : try , step : step }
58+ rh := & ReleaseHandler {version : version , skipPush : skipPush , try : try , step : step }
5559
5660 if try {
5761 rh .git = func (args ... string ) (string , error ) {
@@ -70,7 +74,7 @@ func New(skipPush, try bool, step int) (*ReleaseHandler, error) {
7074// go run -tags release main.go release --skip-publish --try -r 0.90.0
7175// Or a variation of the above -- the skip-publish flag makes sure that any changes are performed to the local Git only.
7276type ReleaseHandler struct {
73- branchVersion string
77+ version string
7478
7579 // 1 or 2.
7680 step int
@@ -89,8 +93,8 @@ func (r *ReleaseHandler) Run() error {
8993 newVersion , finalVersion := r .calculateVersions ()
9094 version := newVersion .String ()
9195 tag := "v" + version
92- mainVersion := newVersion
93- mainVersion . PatchLevel = 0
96+
97+ logf ( "New version %q (prerelease: %t), final version %q \n " , newVersion , newVersion . IsAlphaBetaOrRC (), finalVersion )
9498
9599 r .gitPull ()
96100
@@ -167,14 +171,15 @@ func (r *ReleaseHandler) bumpVersions(ver version.Version) error {
167171}
168172
169173func (r ReleaseHandler ) calculateVersions () (version.Version , version.Version ) {
170- newVersion := version .MustParseVersion (r .branchVersion )
171- finalVersion := newVersion . Next ()
172- finalVersion . PatchLevel = 0
173-
174- if newVersion . Suffix != "-test" {
175- newVersion . Suffix = ""
174+ newVersion := version .MustParseVersion (r .version )
175+ var finalVersion version. Version
176+ if newVersion . IsAlphaBetaOrRC () {
177+ finalVersion = newVersion
178+ } else {
179+ finalVersion = newVersion . Next ()
176180 }
177181
182+ finalVersion .PatchLevel = 0
178183 finalVersion .Suffix = "-DEV"
179184
180185 return newVersion , finalVersion
0 commit comments