Skip to content

Commit

Permalink
add pipeline for release
Browse files Browse the repository at this point in the history
  • Loading branch information
cuisongliu committed Apr 18, 2023
1 parent c931a2c commit da11486
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
31 changes: 16 additions & 15 deletions pkg/gh/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
)

type RetryShell string
type RetrySecretShell string
type SecretShell string

var execFn = func(shells []any) error {
for _, sh := range shells {
Expand All @@ -35,6 +37,16 @@ var execFn = func(shells []any) error {
return utils.RunCommand("bash", "-c", string(s))
})
}
if s, ok := sh.(RetrySecretShell); ok {
return retry.RetryOnConflict(retry.DefaultRetry, func() error {
return utils.RunCommandInSecret(string(s), config.GlobalsConfig.GetToken())
})
}
if s, ok := sh.(SecretShell); ok {
if err := utils.RunCommandInSecret(string(s), config.GlobalsConfig.GetToken()); err != nil {
return err
}
}
if s, ok := sh.(string); ok {
logger.Debug("once shell: %s", s)
if err := utils.RunCommand("bash", "-c", s); err != nil {
Expand All @@ -50,28 +62,17 @@ func setPreGithub(postHooks ...any) error {
authStatus,
disablePrompt,
fmt.Sprintf(forkRepo, config.GlobalsConfig.GetRepoName(), config.GlobalsConfig.GetForkName(), config.GlobalsConfig.GetOrgCommand()),
RetryShell(fmt.Sprintf(cloneRepo, config.GlobalsConfig.GetRepoName())),
RetrySecretShell(fmt.Sprintf(cloneRepo, config.GlobalsConfig.GetUsername(), config.GlobalsConfig.GetToken(), config.GlobalsConfig.GetRepoName())),
fmt.Sprintf(configEmail, config.GlobalsConfig.GetEmail()),
fmt.Sprintf(configUser, config.GlobalsConfig.GetUsername()),
SecretShell(fmt.Sprintf(setToken, config.GlobalsConfig.GetUsername(), config.GlobalsConfig.GetToken(), config.GlobalsConfig.GetRepoName())),
SecretShell(fmt.Sprintf(gitAddRemote, config.GlobalsConfig.GetUsername(), config.GlobalsConfig.GetToken(), config.GlobalsConfig.GetForkName())),
fmt.Sprintf(syncRepo),
}
shells = append(shells, postHooks...)
if err := execFn(shells); err != nil {
return err
}
setTokenShell := fmt.Sprintf(setToken, config.GlobalsConfig.GetUsername(), config.GlobalsConfig.GetToken(), config.GlobalsConfig.GetRepoName())
setRemoteShell := fmt.Sprintf(gitAddRemote, config.GlobalsConfig.GetUsername(), config.GlobalsConfig.GetToken(), config.GlobalsConfig.GetForkName())
for _, sh := range []string{setTokenShell, setRemoteShell} {
if err := utils.RunCommandInSecret(sh, config.GlobalsConfig.GetToken()); err != nil {
return err
}
}

finalShell := []any{
fmt.Sprintf(syncRepo),
}
if err := execFn(finalShell); err != nil {
return err
}
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/gh/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const (
configUser = "cd /tmp/fork-sealos-repo && git config user.name %s"
forkRepo = "gh repo view %s >/dev/null 2>&1 || (echo '仓库不存在,正在fork仓库...' && gh repo fork %s %s)"
syncRepo = "cd /tmp/fork-sealos-repo && git fetch fork && git rebase fork/main && git push -f origin main && git fetch --tags fork && git push -f --tags origin"
cloneRepo = "rm -rf /tmp/fork-sealos-repo && git clone https://github.com/%s.git /tmp/fork-sealos-repo"
cloneRepo = "rm -rf /tmp/fork-sealos-repo && git clone https://%s:%s@github.com/%s.git /tmp/fork-sealos-repo"
setToken = "cd /tmp/fork-sealos-repo && git remote set-url origin https://%s:%s@github.com/%s.git"
newBranch = "cd /tmp/fork-sealos-repo && git checkout -b %s"
generateChangelog = "cd /tmp/fork-sealos-repo && bash %s"
Expand Down

0 comments on commit da11486

Please sign in to comment.