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

Commit

Permalink
feature(main): add release for branch (#33)
Browse files Browse the repository at this point in the history
* feature(main):  add release for branch

Signed-off-by: cuisongliu <[email protected]>

* feature(main):  add release for branch

Signed-off-by: cuisongliu <[email protected]>

---------

Signed-off-by: cuisongliu <[email protected]>
  • Loading branch information
cuisongliu authored Jun 15, 2023
1 parent c9bf839 commit 3b9b56c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,12 @@ message:

- [x] 支持release
`SEALOS_TYPE: "/comment"` # 评论触发

example:
```markdown
/release v1.2.1
/release v1.2.3 release-v1.2
```
> 目标分支为`release-v1.2`,如果没有则默认为`main`分支,该功能v0.0.7-rc1支持
- [x] 支持PR文本替换回复
- `SEALOS_TYPE: "pr_comment"` # PR文本替换回复
- `SEALOS_filename: "README.md"` # PR文本替换回复文件位置
Expand Down
1 change: 1 addition & 0 deletions pkg/gh/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const (
gitCommit = "cd /tmp/fork-sealos-repo && git commit -am '%s' -s"
gitRelease = "cd /tmp/fork-sealos-repo && git describe --abbrev=0 --tags"
gitTag = "cd /tmp/fork-sealos-repo && git fetch --tags && git tag -l"
gitCheck = "cd /tmp/fork-sealos-repo && git checkout fork/%s"
gitNewTag = "cd /tmp/fork-sealos-repo && git tag %s"
gitAddRemote = "cd /tmp/fork-sealos-repo && git remote add fork https://%s:%[email protected]/%s.git"
gitPushRemote = "cd /tmp/fork-sealos-repo && git push -f fork %s"
Expand Down
9 changes: 8 additions & 1 deletion pkg/gh/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,22 @@ import (
"github.com/pkg/errors"
)

func Tag(tag string) error {
func Tag(tag, branch string) error {
if err := setPreGithub(); err != nil {
return err
}
var firstShell any
if branch == "" {
firstShell = utils.SkipShell("")
} else {
firstShell = fmt.Sprintf(gitCheck, branch)
}
if ok, err := checkRemoteTagExists(tag); err != nil {
return err
} else {
if !ok {
shells := []any{
firstShell,
fmt.Sprintf(gitNewTag, tag),
fmt.Sprintf(gitPushRemote, tag),
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/utils/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
type RetryShell string
type RetrySecretShell string
type SecretShell string
type SkipShell string

func ExecShellForAny(secrets ...string) func(shells []any) error {
return func(shells []any) error {
Expand All @@ -55,11 +56,15 @@ func ExecShellForAny(secrets ...string) func(shells []any) error {
return err
}
}
if _, ok := sh.(SkipShell); ok {
continue
}
if s, ok := sh.(string); ok {
if err := RunCommand("bash", "-c", s); err != nil {
return err
}
}

}
return nil
}
Expand Down
10 changes: 7 additions & 3 deletions pkg/workflow/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ func (c *release) Run() error {
return c.sender.sendMsgToIssue("permission_error")
}
data := strings.Split(c.Body, " ")
if len(data) == 2 && utils.ValidateVersion(data[1]) {
err := gh.Tag(data[1])
if (2 == len(data) || 3 == len(data)) && utils.ValidateVersion(data[1]) {
var newBranch string
if len(data) == 3 {
newBranch = data[2]
}
err := gh.Tag(data[1], newBranch)
if err != nil {
c.sender.Error = err.Error()
return c.sender.sendMsgToIssue("release_error")
Expand All @@ -53,7 +57,7 @@ func (c *release) Run() error {
}
return nil
} else {
logger.Error("command format is error: %s ex. /{prefix}_release {tag}", c.Body)
logger.Error("command format is error: %s ex. /{prefix}_release {tag} {branch}", c.Body)
return c.sender.sendMsgToIssue("format_error")
}
}
Expand Down

0 comments on commit 3b9b56c

Please sign in to comment.