Skip to content

Commit

Permalink
[#115]: fix: GitLab plugins build
Browse files Browse the repository at this point in the history
  • Loading branch information
rustatian authored Oct 9, 2023
2 parents 47d520f + 4388e5f commit e947ded
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 53 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ on:
push:
branches:
- master
tags-ignore:
- "**"
pull_request:
branches:
- master

jobs:
golang:
name: Build (Go ${{ matrix.go }}, OS ${{matrix.os}})
Expand Down
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))
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
35 changes: 35 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,29 @@ 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 {
if num == "" {
return false
}
_, err := strconv.ParseInt(num, 10, 64)
return err == nil
}
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"

0 comments on commit e947ded

Please sign in to comment.