-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(Makefile): add push_patch and push_minor commands
- Loading branch information
Showing
4 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
build_local: | ||
goreleaser release --snapshot --clean | ||
|
||
push_patch: | ||
next_tag=$$(cd tools && go run next_tag/main.go patch) && git tag $$next_tag && git push origin tag $$next_tag | ||
|
||
push_minor: | ||
next_tag=$$(cd tools && go run next_tag/main.go minor) && git tag $$next_tag && git push origin tag $$next_tag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/paragor/simple_cdn/tools | ||
|
||
go 1.23.0 | ||
|
||
require github.com/Masterminds/semver/v3 v3.3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/Masterminds/semver/v3 v3.3.0 h1:B8LGeaivUe71a5qox1ICM/JLl0NqZSW5CHyL+hmvYS0= | ||
github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"github.com/Masterminds/semver/v3" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"slices" | ||
"strings" | ||
"time" | ||
) | ||
|
||
func main() { | ||
args := os.Args | ||
if len(args) != 2 { | ||
panic("only one arg require") | ||
} | ||
upgradeType := strings.ToLower(args[1]) | ||
switch upgradeType { | ||
case "major", "minor", "patch": | ||
default: | ||
log.Fatalln("arg[1] should one of: major, minor, patch") | ||
} | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30) | ||
defer cancel() | ||
stdout := bytes.NewBuffer(nil) | ||
stderr := bytes.NewBuffer(nil) | ||
gitTag := exec.CommandContext(ctx, "git", "tag") | ||
gitTag.Stdout = stdout | ||
gitTag.Stderr = stderr | ||
if err := gitTag.Run(); err != nil { | ||
log.Fatalf("cant run git tag: %w. stderr: %s", err, stderr.String()) | ||
} | ||
rawTags := strings.Split(strings.TrimSpace(stdout.String()), "\n") | ||
tags := []*semver.Version{} | ||
for _, rawTag := range rawTags { | ||
if !strings.HasPrefix(rawTag, "v") { | ||
continue | ||
} | ||
rawTag = strings.TrimPrefix(rawTag, "v") | ||
tag, err := semver.StrictNewVersion(rawTag) | ||
if err != nil { | ||
continue | ||
} | ||
tags = append(tags, tag) | ||
} | ||
|
||
slices.SortFunc(tags, func(a, b *semver.Version) int { | ||
return b.Compare(a) | ||
}) | ||
|
||
newTag := *tags[0] | ||
if strings.ToLower(args[1]) == "major" { | ||
newTag = newTag.IncMajor() | ||
} else if strings.ToLower(args[1]) == "minor" { | ||
newTag = newTag.IncMinor() | ||
} else { | ||
newTag = newTag.IncPatch() | ||
} | ||
fmt.Printf("v%s", newTag.String()) | ||
} |