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

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 450b368 commit 886ad91
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/gh-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repo:
fork: cuisongliu/sealos

changelog:
script: scripts/changelog.sh
script: scripts/changelog.sh {{.Repo.Fork}}
allowOps:
- cuisongliu
reviewers:
Expand Down
4 changes: 3 additions & 1 deletion pkg/gh/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"github.com/cuisongliu/logger"
"github.com/labring-actions/gh-rebot/pkg/config"
"github.com/labring-actions/gh-rebot/pkg/template"
"github.com/labring-actions/gh-rebot/pkg/utils"
"k8s.io/client-go/util/retry"
"strings"
Expand Down Expand Up @@ -81,9 +82,10 @@ func Changelog(reviews []string) error {
if err := setPreGithub(); err != nil {
return err
}

shells := []any{
fmt.Sprintf(newBranch, branchName),
fmt.Sprintf(generateChangelog, config.GlobalsConfig.GetChangelogScript()),
fmt.Sprintf(generateChangelog, template.TryParseString(config.GlobalsConfig.GetChangelogScript(), config.GlobalsConfig)),
}
if err := execFn(shells); err != nil {
return err
Expand Down
10 changes: 10 additions & 0 deletions pkg/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ func TryParse(text string) (*template.Template, bool, error) {
return tmp, !isFailed, err
}

func TryParseString(text string, data any) string {
v, b, _ := TryParse(text)
if b {
out := bytes.NewBuffer(nil)
_ = v.Execute(out, data)
text = out.String()
}
return text
}

func ParseFiles(filenames ...string) (*template.Template, error) {
return defaultTpl.ParseFiles(filenames...)
}
Expand Down
13 changes: 5 additions & 8 deletions pkg/template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,24 @@ package template
import (
"bytes"
"fmt"
"github.com/labring-actions/gh-rebot/pkg/config"
"testing"
)

func TestTemplateSemverCompare(t *testing.T) {
v, b, e := TryParse(`
version: {{if (semverCompare "^1.26.0" (default "" .ENV)) }}v1{{ else }}v1alpha2{{ end }}
scripts/changelog.sh {{.Repo.Fork}}
`)
if e != nil {
t.Errorf("parse err: %v", e)
}
if !b {
t.Errorf("parse failed: %v", b)
}

config.GlobalsConfig = new(config.Config)
config.GlobalsConfig.Repo.Fork = "cuisongliu/sealos"
out := bytes.NewBuffer(nil)
execErr := v.Execute(out, map[string]interface{}{
// comment out this to test true return
// "ENV": "v1.26.1",
// comment out this to test false return
"ENV": "v1.25.10",
})
execErr := v.Execute(out, config.GlobalsConfig)
if execErr != nil {
t.Errorf("template exec err: %v", execErr)
}
Expand Down

0 comments on commit 886ad91

Please sign in to comment.