Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: gitlab plugins build #115

Merged
merged 3 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 0 additions & 33 deletions github/modinfo.go

This file was deleted.

3 changes: 2 additions & 1 deletion github/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"
"time"

"github.com/roadrunner-server/velox"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion github/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
rustatian marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
18 changes: 16 additions & 2 deletions gitlab/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
32 changes: 32 additions & 0 deletions modulesInfo.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,3 +20,26 @@ type ModulesInfo struct {
// Replace (for the local dev)
Replace string
}

var vr = regexp.MustCompile("/v(\\d+)$") //nolint:gosimple

rustatian marked this conversation as resolved.
Show resolved Hide resolved
// 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)
}
rustatian marked this conversation as resolved.
Show resolved Hide resolved

func IsDigit(num string) bool {
_, err := strconv.ParseInt(num, 10, 64)
return err == nil
}
rustatian marked this conversation as resolved.
Show resolved Hide resolved
28 changes: 14 additions & 14 deletions velox_rr_v2023.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down Expand Up @@ -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"
Loading