From eaa806f1d8eed261ddd1435059638605530b3049 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Mon, 9 Oct 2023 14:38:25 +0200 Subject: [PATCH 1/3] fix: gitlab plugins build Signed-off-by: Valery Piashchynski --- github/modinfo.go | 33 --------------------------------- github/parse_test.go | 3 ++- github/pool.go | 2 +- gitlab/repo.go | 18 ++++++++++++++++-- modulesInfo.go | 32 ++++++++++++++++++++++++++++++++ velox_rr_v2023.toml | 28 ++++++++++++++-------------- 6 files changed, 65 insertions(+), 51 deletions(-) delete mode 100644 github/modinfo.go diff --git a/github/modinfo.go b/github/modinfo.go deleted file mode 100644 index caddae4..0000000 --- a/github/modinfo.go +++ /dev/null @@ -1,33 +0,0 @@ -package github - -import ( - "fmt" - "regexp" - "strconv" - "time" - - m "golang.org/x/mod/module" -) - -var vr = regexp.MustCompile("/v(\\d+)$") //nolint:gosimple - -// here we accept a module name and return the version -// e.g.: github.com/roadrunner-server/logger/v2 => v2 -func parseModuleInfo(module string, t time.Time, rev string) string { - match := vr.FindStringSubmatch(module) - var version string - if len(match) > 1 { - if !IsDigit(match[1]) { - return m.PseudoVersion("", "", t, rev) - } - - version = fmt.Sprintf("v%s", match[1]) - } - - return m.PseudoVersion(version, "", t, rev) -} - -func IsDigit(num string) bool { - _, err := strconv.ParseInt(num, 10, 64) - return err == nil -} diff --git a/github/parse_test.go b/github/parse_test.go index 18297cd..e7d978d 100644 --- a/github/parse_test.go +++ b/github/parse_test.go @@ -4,6 +4,7 @@ import ( "testing" "time" + "github.com/roadrunner-server/velox" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -56,7 +57,7 @@ func TestParse(t *testing.T) { } for _, tt := range tests { - out := parseModuleInfo(tt.module, tt.tm, tt.sha) + out := velox.ParseModuleInfo(tt.module, tt.tm, tt.sha) assert.Equal(t, tt.expect, out) } } diff --git a/github/pool.go b/github/pool.go index 3116c82..ec8c9bb 100644 --- a/github/pool.go +++ b/github/pool.go @@ -151,7 +151,7 @@ func (p *processor) run() { } modInfo.Version = commits[0].GetSHA()[:12] - modInfo.PseudoVersion = parseModuleInfo(modInfo.ModuleName, at.Time, commits[0].GetSHA()[:12]) + modInfo.PseudoVersion = velox.ParseModuleInfo(modInfo.ModuleName, at.Time, commits[0].GetSHA()[:12]) if v.pluginCfg.Replace != "" { p.log.Debug("[REPLACE REQUESTED]", zap.String("plugin", v.name), zap.String("path", v.pluginCfg.Replace)) diff --git a/gitlab/repo.go b/gitlab/repo.go index e246b9b..82a1e75 100644 --- a/gitlab/repo.go +++ b/gitlab/repo.go @@ -102,11 +102,25 @@ func (r *GLRepo) GetPluginsModData() ([]*velox.ModulesInfo, error) { return nil, fmt.Errorf("bad response status: %d", rsp.StatusCode) } - if len(commits) == 0 { - return nil, errors.New("no commits in the repository") + // should be only one commit + if len(commits) == 0 || len(commits) > 1 { + return nil, errors.New("no commits/more than 1 commit selected") } modInfo.Version = commits[0].ID + if len(commits[0].ID) < 12 { + return nil, errors.New("commit SHA is too short") + } + + // [:12] because of go.mod pseudo format specs + modInfo.Version = commits[0].ID[:12] + + at := commits[0].CommittedDate + if at == nil { + return nil, errors.New("commit date is nil") + } + + modInfo.PseudoVersion = velox.ParseModuleInfo(modInfo.ModuleName, *at, modInfo.Version) if v.Replace != "" { r.log.Debug("[REPLACE REQUESTED]", zap.String("plugin", k), zap.String("path", v.Replace)) diff --git a/modulesInfo.go b/modulesInfo.go index fe25361..24bf6a9 100644 --- a/modulesInfo.go +++ b/modulesInfo.go @@ -1,5 +1,14 @@ package velox +import ( + "fmt" + "regexp" + "strconv" + "time" + + m "golang.org/x/mod/module" +) + // ModulesInfo represents single go module type ModulesInfo struct { // Version - commit sha or tag @@ -11,3 +20,26 @@ type ModulesInfo struct { // Replace (for the local dev) Replace string } + +var vr = regexp.MustCompile("/v(\\d+)$") //nolint:gosimple + +// ParseModuleInfo here we accept a module name and return the version +// e.g.: github.com/roadrunner-server/logger/v2 => v2 +func ParseModuleInfo(module string, t time.Time, rev string) string { + match := vr.FindStringSubmatch(module) + var version string + if len(match) > 1 { + if !IsDigit(match[1]) { + return m.PseudoVersion("", "", t, rev) + } + + version = fmt.Sprintf("v%s", match[1]) + } + + return m.PseudoVersion(version, "", t, rev) +} + +func IsDigit(num string) bool { + _, err := strconv.ParseInt(num, 10, 64) + return err == nil +} diff --git a/velox_rr_v2023.toml b/velox_rr_v2023.toml index 85372fa..c83b221 100644 --- a/velox_rr_v2023.toml +++ b/velox_rr_v2023.toml @@ -20,7 +20,7 @@ ref = "v2023.3.0" lock = { ref = "v4.5.2", owner = "roadrunner-server", repository = "lock" } # CENTRIFUGE BROADCASTING PLATFORM - centrifuge = { ref = "v4.4.2", owner = "roadrunner-server", repository = "centrifuge" } + centrifuge = { ref = "v4.5.0", owner = "roadrunner-server", repository = "centrifuge" } # WORKFLOWS ENGINE temporal = { ref = "v4.5.0", owner = "temporalio", repository = "roadrunner-temporal" } @@ -72,19 +72,19 @@ ref = "v2023.3.0" # TCP for the RAW TCP PAYLOADS tcp = { ref = "v4.3.2", owner = "roadrunner-server", repository = "tcp" } -#[gitlab] -# [gitlab.token] -# # api, read-api, read-repo -# token = "${GL_TOKEN}" -# -# [gitlab.endpoint] -# endpoint = "https://gitlab.com" -# -# [gitlab.plugins] -# # ref -> master, commit or tag -# test_plugin_1 = { ref = "main", owner = "rustatian", repository = "36405203" } -# test_plugin_2 = { ref = "main", owner = "rustatian", repository = "36405235" } -# +[gitlab] + [gitlab.token] + # api, read-api, read-repo + token = "${GL_TOKEN}" + + [gitlab.endpoint] + endpoint = "https://gitlab.com" + + [gitlab.plugins] + # ref -> master, commit or tag + test_plugin_1 = { ref = "main", owner = "rustatian", repository = "36405203" } + test_plugin_2 = { ref = "main", owner = "rustatian", repository = "36405235" } + [log] level = "debug" mode = "development" From 6826609630cf9eca75606f05dd773c8950fba385 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Mon, 9 Oct 2023 14:40:41 +0200 Subject: [PATCH 2/3] chore: ci, update push targets Signed-off-by: Valery Piashchynski --- .github/workflows/linux.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 45a4d80..bc3b0ce 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -4,8 +4,10 @@ on: push: branches: - master - tags-ignore: - - "**" + pull_request: + branches: + - master + jobs: golang: name: Build (Go ${{ matrix.go }}, OS ${{matrix.os}}) From 4388e5fc87d21eedf95532b76bedbc01dc1cb5af Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Mon, 9 Oct 2023 14:42:49 +0200 Subject: [PATCH 3/3] fix: code review Signed-off-by: Valery Piashchynski --- modulesInfo.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modulesInfo.go b/modulesInfo.go index 24bf6a9..911f015 100644 --- a/modulesInfo.go +++ b/modulesInfo.go @@ -40,6 +40,9 @@ func ParseModuleInfo(module string, t time.Time, rev string) string { } func IsDigit(num string) bool { + if num == "" { + return false + } _, err := strconv.ParseInt(num, 10, 64) return err == nil }