Skip to content
This repository was archived by the owner on Aug 26, 2023. It is now read-only.

Commit 3b9b56c

Browse files
authored
feature(main): add release for branch (#33)
* feature(main): add release for branch Signed-off-by: cuisongliu <cuisongliu@qq.com> * feature(main): add release for branch Signed-off-by: cuisongliu <cuisongliu@qq.com> --------- Signed-off-by: cuisongliu <cuisongliu@qq.com>
1 parent c9bf839 commit 3b9b56c

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,12 @@ message:
115115

116116
- [x] 支持release
117117
`SEALOS_TYPE: "/comment"` # 评论触发
118-
118+
example:
119+
```markdown
120+
/release v1.2.1
121+
/release v1.2.3 release-v1.2
122+
```
123+
> 目标分支为`release-v1.2`,如果没有则默认为`main`分支,该功能v0.0.7-rc1支持
119124
- [x] 支持PR文本替换回复
120125
- `SEALOS_TYPE: "pr_comment"` # PR文本替换回复
121126
- `SEALOS_filename: "README.md"` # PR文本替换回复文件位置

pkg/gh/consts.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const (
3131
gitCommit = "cd /tmp/fork-sealos-repo && git commit -am '%s' -s"
3232
gitRelease = "cd /tmp/fork-sealos-repo && git describe --abbrev=0 --tags"
3333
gitTag = "cd /tmp/fork-sealos-repo && git fetch --tags && git tag -l"
34+
gitCheck = "cd /tmp/fork-sealos-repo && git checkout fork/%s"
3435
gitNewTag = "cd /tmp/fork-sealos-repo && git tag %s"
3536
gitAddRemote = "cd /tmp/fork-sealos-repo && git remote add fork https://%s:%s@github.com/%s.git"
3637
gitPushRemote = "cd /tmp/fork-sealos-repo && git push -f fork %s"

pkg/gh/tag.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,22 @@ import (
2222
"github.com/pkg/errors"
2323
)
2424

25-
func Tag(tag string) error {
25+
func Tag(tag, branch string) error {
2626
if err := setPreGithub(); err != nil {
2727
return err
2828
}
29+
var firstShell any
30+
if branch == "" {
31+
firstShell = utils.SkipShell("")
32+
} else {
33+
firstShell = fmt.Sprintf(gitCheck, branch)
34+
}
2935
if ok, err := checkRemoteTagExists(tag); err != nil {
3036
return err
3137
} else {
3238
if !ok {
3339
shells := []any{
40+
firstShell,
3441
fmt.Sprintf(gitNewTag, tag),
3542
fmt.Sprintf(gitPushRemote, tag),
3643
}

pkg/utils/shell.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
type RetryShell string
3030
type RetrySecretShell string
3131
type SecretShell string
32+
type SkipShell string
3233

3334
func ExecShellForAny(secrets ...string) func(shells []any) error {
3435
return func(shells []any) error {
@@ -55,11 +56,15 @@ func ExecShellForAny(secrets ...string) func(shells []any) error {
5556
return err
5657
}
5758
}
59+
if _, ok := sh.(SkipShell); ok {
60+
continue
61+
}
5862
if s, ok := sh.(string); ok {
5963
if err := RunCommand("bash", "-c", s); err != nil {
6064
return err
6165
}
6266
}
67+
6368
}
6469
return nil
6570
}

pkg/workflow/release.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,12 @@ func (c *release) Run() error {
3434
return c.sender.sendMsgToIssue("permission_error")
3535
}
3636
data := strings.Split(c.Body, " ")
37-
if len(data) == 2 && utils.ValidateVersion(data[1]) {
38-
err := gh.Tag(data[1])
37+
if (2 == len(data) || 3 == len(data)) && utils.ValidateVersion(data[1]) {
38+
var newBranch string
39+
if len(data) == 3 {
40+
newBranch = data[2]
41+
}
42+
err := gh.Tag(data[1], newBranch)
3943
if err != nil {
4044
c.sender.Error = err.Error()
4145
return c.sender.sendMsgToIssue("release_error")
@@ -53,7 +57,7 @@ func (c *release) Run() error {
5357
}
5458
return nil
5559
} else {
56-
logger.Error("command format is error: %s ex. /{prefix}_release {tag}", c.Body)
60+
logger.Error("command format is error: %s ex. /{prefix}_release {tag} {branch}", c.Body)
5761
return c.sender.sendMsgToIssue("format_error")
5862
}
5963
}

0 commit comments

Comments
 (0)