Skip to content

Commit eaa806f

Browse files
committed
fix: gitlab plugins build
Signed-off-by: Valery Piashchynski <[email protected]>
1 parent 47d520f commit eaa806f

File tree

6 files changed

+65
-51
lines changed

6 files changed

+65
-51
lines changed

github/modinfo.go

-33
This file was deleted.

github/parse_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"testing"
55
"time"
66

7+
"github.com/roadrunner-server/velox"
78
"github.com/stretchr/testify/assert"
89
"github.com/stretchr/testify/require"
910
)
@@ -56,7 +57,7 @@ func TestParse(t *testing.T) {
5657
}
5758

5859
for _, tt := range tests {
59-
out := parseModuleInfo(tt.module, tt.tm, tt.sha)
60+
out := velox.ParseModuleInfo(tt.module, tt.tm, tt.sha)
6061
assert.Equal(t, tt.expect, out)
6162
}
6263
}

github/pool.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (p *processor) run() {
151151
}
152152

153153
modInfo.Version = commits[0].GetSHA()[:12]
154-
modInfo.PseudoVersion = parseModuleInfo(modInfo.ModuleName, at.Time, commits[0].GetSHA()[:12])
154+
modInfo.PseudoVersion = velox.ParseModuleInfo(modInfo.ModuleName, at.Time, commits[0].GetSHA()[:12])
155155

156156
if v.pluginCfg.Replace != "" {
157157
p.log.Debug("[REPLACE REQUESTED]", zap.String("plugin", v.name), zap.String("path", v.pluginCfg.Replace))

gitlab/repo.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,25 @@ func (r *GLRepo) GetPluginsModData() ([]*velox.ModulesInfo, error) {
102102
return nil, fmt.Errorf("bad response status: %d", rsp.StatusCode)
103103
}
104104

105-
if len(commits) == 0 {
106-
return nil, errors.New("no commits in the repository")
105+
// should be only one commit
106+
if len(commits) == 0 || len(commits) > 1 {
107+
return nil, errors.New("no commits/more than 1 commit selected")
107108
}
108109

109110
modInfo.Version = commits[0].ID
111+
if len(commits[0].ID) < 12 {
112+
return nil, errors.New("commit SHA is too short")
113+
}
114+
115+
// [:12] because of go.mod pseudo format specs
116+
modInfo.Version = commits[0].ID[:12]
117+
118+
at := commits[0].CommittedDate
119+
if at == nil {
120+
return nil, errors.New("commit date is nil")
121+
}
122+
123+
modInfo.PseudoVersion = velox.ParseModuleInfo(modInfo.ModuleName, *at, modInfo.Version)
110124

111125
if v.Replace != "" {
112126
r.log.Debug("[REPLACE REQUESTED]", zap.String("plugin", k), zap.String("path", v.Replace))

modulesInfo.go

+32
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
package velox
22

3+
import (
4+
"fmt"
5+
"regexp"
6+
"strconv"
7+
"time"
8+
9+
m "golang.org/x/mod/module"
10+
)
11+
312
// ModulesInfo represents single go module
413
type ModulesInfo struct {
514
// Version - commit sha or tag
@@ -11,3 +20,26 @@ type ModulesInfo struct {
1120
// Replace (for the local dev)
1221
Replace string
1322
}
23+
24+
var vr = regexp.MustCompile("/v(\\d+)$") //nolint:gosimple
25+
26+
// ParseModuleInfo here we accept a module name and return the version
27+
// e.g.: github.com/roadrunner-server/logger/v2 => v2
28+
func ParseModuleInfo(module string, t time.Time, rev string) string {
29+
match := vr.FindStringSubmatch(module)
30+
var version string
31+
if len(match) > 1 {
32+
if !IsDigit(match[1]) {
33+
return m.PseudoVersion("", "", t, rev)
34+
}
35+
36+
version = fmt.Sprintf("v%s", match[1])
37+
}
38+
39+
return m.PseudoVersion(version, "", t, rev)
40+
}
41+
42+
func IsDigit(num string) bool {
43+
_, err := strconv.ParseInt(num, 10, 64)
44+
return err == nil
45+
}

velox_rr_v2023.toml

+14-14
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ref = "v2023.3.0"
2020
lock = { ref = "v4.5.2", owner = "roadrunner-server", repository = "lock" }
2121

2222
# CENTRIFUGE BROADCASTING PLATFORM
23-
centrifuge = { ref = "v4.4.2", owner = "roadrunner-server", repository = "centrifuge" }
23+
centrifuge = { ref = "v4.5.0", owner = "roadrunner-server", repository = "centrifuge" }
2424

2525
# WORKFLOWS ENGINE
2626
temporal = { ref = "v4.5.0", owner = "temporalio", repository = "roadrunner-temporal" }
@@ -72,19 +72,19 @@ ref = "v2023.3.0"
7272
# TCP for the RAW TCP PAYLOADS
7373
tcp = { ref = "v4.3.2", owner = "roadrunner-server", repository = "tcp" }
7474

75-
#[gitlab]
76-
# [gitlab.token]
77-
# # api, read-api, read-repo
78-
# token = "${GL_TOKEN}"
79-
#
80-
# [gitlab.endpoint]
81-
# endpoint = "https://gitlab.com"
82-
#
83-
# [gitlab.plugins]
84-
# # ref -> master, commit or tag
85-
# test_plugin_1 = { ref = "main", owner = "rustatian", repository = "36405203" }
86-
# test_plugin_2 = { ref = "main", owner = "rustatian", repository = "36405235" }
87-
#
75+
[gitlab]
76+
[gitlab.token]
77+
# api, read-api, read-repo
78+
token = "${GL_TOKEN}"
79+
80+
[gitlab.endpoint]
81+
endpoint = "https://gitlab.com"
82+
83+
[gitlab.plugins]
84+
# ref -> master, commit or tag
85+
test_plugin_1 = { ref = "main", owner = "rustatian", repository = "36405203" }
86+
test_plugin_2 = { ref = "main", owner = "rustatian", repository = "36405235" }
87+
8888
[log]
8989
level = "debug"
9090
mode = "development"

0 commit comments

Comments
 (0)