Skip to content

Commit

Permalink
feature(main): add readme (#24)
Browse files Browse the repository at this point in the history
* feature(main): add readme

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

* feature(main): add readme

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

---------

Signed-off-by: cuisongliu <[email protected]>
  • Loading branch information
cuisongliu authored Jun 8, 2023
1 parent d25d4bc commit c8cc4fb
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 25 deletions.
7 changes: 6 additions & 1 deletion .github/gh-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ version: v1
debug: true
type: action
action:
printConfig: true
printConfig: false
release:
retry: 15s
actionName: Release
allowOps:
- cuisongliu
bot:
prefix: /
spe: _
Expand Down
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ version: v1
debug: true
bot:
prefix: /sealos
action:
printConfig: true
release:
retry: 15s
action: Release
allowOps:
- cuisongliu
spe: _
allowOps:
- sealos-ci-robot
Expand All @@ -22,12 +29,6 @@ repo:
name: labring/sealos
fork: cuisongliu/sealos

release:
retry: 15s
action: Release
allowOps:
- cuisongliu

message:
success: |
🤖 says: The action {{.Body}} finished successfully 🎉
Expand All @@ -44,6 +45,12 @@ message:
- `version` - 版本标识,当前为 v1。
- `debug` - 是否开启调试模式,设置为 true 时开启。
- `action` \- action配置。
- `printConfig` - 是否打印配置信息,设置为 true 时打印。
- `release` \- 发布配置。
- `retry` - 重试间隔,例如:15s。
- `action` - 执行动作,例如:Release。
- `allowOps` - 允许触发发布操作的用户名列表。
- `bot` \- 机器人配置。
- `prefix` - 机器人命令前缀,用于识别命令。默认值 `/`,如果设置为`/` 则 `spe` 失效。命令为`/release`
- `spe` - 机器人命令分隔符,用于识别命令。默认值 `_`
Expand All @@ -54,10 +61,6 @@ message:
- `org` - 是否为组织仓库,设置为 true 时表示是组织仓库。
- `name` - 仓库名称。
- `fork` - fork 的仓库名称。
- `release` \- 发布配置。
- `retry` - 重试间隔,例如:15s。
- `action` - 执行动作,例如:Release。
- `allowOps` - 允许触发发布操作的用户名列表。
- `message` \- 消息配置。
- `success` - 成功消息模板。
- `format_error` - 格式错误消息模板。
Expand Down
2 changes: 1 addition & 1 deletion pkg/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func CommentEngine() error {
for _, t := range cmds {
logger.Debug("cmds: ", strings.TrimSpace(t))
wfs := make([]workflow.Interface, 0)
if types.GlobalsBotConfig.Release != nil {
if types.GlobalsBotConfig.Action.Release != nil {
wfs = append(wfs, workflow.NewRelease(strings.TrimSpace(t)))
}
used := 0
Expand Down
2 changes: 1 addition & 1 deletion pkg/action/action_pr_comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

func GetEnvFromAction(key string) (string, error) {
allKey := strings.ToLower("sealos_" + key)
allKey := strings.ToUpper("sealos_" + key)
val, _ := os.LookupEnv(allKey)
if val == "" {
return "", fmt.Errorf("not found %s", allKey)
Expand Down
4 changes: 2 additions & 2 deletions pkg/gh/check_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type ActionOut struct {
}

func CheckRelease(tagName string) (*ActionOut, error) {
workflowOutput, _ := utils.RunCommandWithOutput(fmt.Sprintf(gitWorkflowCheck, types.GlobalsBotConfig.GetForkName(), types.GlobalsBotConfig.Release.Action, tagName), true)
workflowOutput, _ := utils.RunCommandWithOutput(fmt.Sprintf(gitWorkflowCheck, types.GlobalsBotConfig.GetForkName(), types.GlobalsBotConfig.Action.Release.ActionName, tagName), true)
if workflowOutput == "" || strings.Contains(workflowOutput, "could not find any workflows named") {
time.Sleep(5 * time.Second)
return CheckRelease(tagName)
Expand All @@ -52,7 +52,7 @@ func CheckRelease(tagName string) (*ActionOut, error) {
out.IsSuccess = false
return &out, nil
} else {
tt, err := time.ParseDuration(types.GlobalsBotConfig.Release.Retry)
tt, err := time.ParseDuration(types.GlobalsBotConfig.Action.Release.Retry)
if err != nil {
tt = time.Second * 20
}
Expand Down
11 changes: 5 additions & 6 deletions pkg/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ type Repo struct {
}

type Release struct {
Retry string `json:"retry"`
Action string `json:"action"`
AllowOps []string `json:"allowOps"`
Retry string `json:"retry"`
ActionName string `json:"actionName"`
AllowOps []string `json:"allowOps"`
}

type Type string
Expand All @@ -47,7 +47,8 @@ const (
)

type Action struct {
PrintConfig bool `json:"printConfig"`
PrintConfig bool `json:"printConfig"`
Release *Release `json:"release,omitempty"`
}

type Config struct {
Expand All @@ -59,8 +60,6 @@ type Config struct {
Repo Repo `json:"repo"`
Message map[string]string `json:"message"`
Token string `json:"-"`

Release *Release `json:"release,omitempty"`
}

// GetPrefix returns the prefix for the bot
Expand Down
6 changes: 3 additions & 3 deletions pkg/types/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ func (r *Config) validate() error {
if r.GetForkName() == "" {
return fmt.Errorf("repo fork is required")
}
if r.Release != nil {
if r.Release.Action == "" {
if r.Action.Release != nil {
if r.Action.Release.ActionName == "" {
return fmt.Errorf("release action is required")
}
if r.Release.Retry == "" {
if r.Action.Release.Retry == "" {
return fmt.Errorf("release retry is required")
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/workflow/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type release struct {
}

func (c *release) Run() error {
if checkPermission(types.GlobalsBotConfig.Release.AllowOps) != nil {
if checkPermission(types.GlobalsBotConfig.Action.Release.AllowOps) != nil {
return c.sender.sendMsgToIssue("permission_error")
}
data := strings.Split(c.Body, " ")
Expand Down

0 comments on commit c8cc4fb

Please sign in to comment.