Skip to content

Commit

Permalink
feat: default release-x.y.z branch for enterprise-plugin in hotfix (#71)
Browse files Browse the repository at this point in the history
# Why:
- for hotfix verison v6.1.2-20240125-5de58f5, we need use
enterprise-plugin branch release-6.1.2
- but for devbuild, release-6.1.2 may not created when PR, so just keep
using branch. Anyway, user can explicit decide to use which verison

---------

Signed-off-by: lijie <[email protected]>
  • Loading branch information
lijie authored Jan 26, 2024
1 parent db82d5d commit d3934f2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
13 changes: 9 additions & 4 deletions tibuild/pkg/rest/service/dev_build_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,14 @@ func fillWithDefaults(req *DevBuild) {
func guessEnterprisePluginRef(spec *DevBuildSpec) {
if spec.Product == ProductTidb && spec.Edition == EnterpriseEdition && spec.PluginGitRef == "" {
groups := versionValidator.FindStringSubmatch(spec.Version)
if len(groups) == 2 {
major := groups[1]
spec.PluginGitRef = fmt.Sprintf("release-%s", major)
if len(groups) == 3 {
major_sub := groups[1]
if spec.IsHotfix {
patch := groups[2]
spec.PluginGitRef = fmt.Sprintf("release-%s%s", major_sub, patch)
} else {
spec.PluginGitRef = fmt.Sprintf("release-%s", major_sub)
}
}
}
}
Expand Down Expand Up @@ -295,7 +300,7 @@ type DevBuildRepository interface {

var _ DevBuildService = DevbuildServer{}

var versionValidator *regexp.Regexp = regexp.MustCompile(`^v(\d+\.\d+)\.\d+.*$`)
var versionValidator *regexp.Regexp = regexp.MustCompile(`^v(\d+\.\d+)(\.\d+).*$`)
var hotfixVersionValidator *regexp.Regexp = regexp.MustCompile(`^v(\d+\.\d+)\.\d+-\d{8,}.*$`)
var gitRefValidator *regexp.Regexp = regexp.MustCompile(`^((v\d.*)|(pull/\d+)|([0-9a-fA-F]{40})|(release-.*)|master|main|(tag/.+)|(branch/.+))$`)
var githubRepoValidator *regexp.Regexp = regexp.MustCompile(`^([\w_-]+/[\w_-]+)$`)
9 changes: 8 additions & 1 deletion tibuild/pkg/rest/service/dev_build_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,20 @@ func TestDevBuildCreate(t *testing.T) {
time.Sleep(time.Millisecond)
require.Equal(t, int64(2), mockedRepo.saved.Status.PipelineBuildID)
})
t.Run("auto fill plugin", func(t *testing.T) {
t.Run("auto fill plugin for devbuild", func(t *testing.T) {
entity, err := server.Create(context.TODO(),
DevBuild{Spec: DevBuildSpec{Product: ProductTidb, Version: "v6.1.2", Edition: EnterpriseEdition, GitRef: "pull/23"}},
DevBuildSaveOption{})
require.NoError(t, err)
require.Equal(t, "release-6.1", entity.Spec.PluginGitRef)
})
t.Run("auto fill plugin for hotfix", func(t *testing.T) {
entity, err := server.Create(context.TODO(),
DevBuild{Spec: DevBuildSpec{Product: ProductTidb, Version: "v6.1.2-20240125-5de58f5", Edition: EnterpriseEdition, GitRef: "pull/23", IsHotfix: true}},
DevBuildSaveOption{})
require.NoError(t, err)
require.Equal(t, "release-6.1.2", entity.Spec.PluginGitRef)
})
t.Run("auto fill fips", func(t *testing.T) {
entity, err := server.Create(context.TODO(),
DevBuild{Spec: DevBuildSpec{Product: ProductTikv, Version: "v6.1.2", Edition: EnterpriseEdition, GitRef: "pull/23", Features: "fips"}},
Expand Down

0 comments on commit d3934f2

Please sign in to comment.