From 886ad9146da5d683dabf628aebff959898aca352 Mon Sep 17 00:00:00 2001 From: cuisongliu Date: Wed, 19 Apr 2023 01:23:39 +0800 Subject: [PATCH] add pipeline for release --- .github/gh-bot.yml | 2 +- pkg/gh/changelog.go | 4 +++- pkg/template/template.go | 10 ++++++++++ pkg/template/template_test.go | 13 +++++-------- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/.github/gh-bot.yml b/.github/gh-bot.yml index 1bcb76f..89fc848 100644 --- a/.github/gh-bot.yml +++ b/.github/gh-bot.yml @@ -13,7 +13,7 @@ repo: fork: cuisongliu/sealos changelog: - script: scripts/changelog.sh + script: scripts/changelog.sh {{.Repo.Fork}} allowOps: - cuisongliu reviewers: diff --git a/pkg/gh/changelog.go b/pkg/gh/changelog.go index acc6c0f..6cc44a6 100644 --- a/pkg/gh/changelog.go +++ b/pkg/gh/changelog.go @@ -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" @@ -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 diff --git a/pkg/template/template.go b/pkg/template/template.go index 7f819e4..27a9877 100644 --- a/pkg/template/template.go +++ b/pkg/template/template.go @@ -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...) } diff --git a/pkg/template/template_test.go b/pkg/template/template_test.go index f898596..a2af5e2 100644 --- a/pkg/template/template_test.go +++ b/pkg/template/template_test.go @@ -17,12 +17,13 @@ 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) @@ -30,14 +31,10 @@ version: {{if (semverCompare "^1.26.0" (default "" .ENV)) }}v1{{ else }}v1alpha2 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) }