diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index db4600b..453c846 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -7,10 +7,13 @@ jobs: name: lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: stable - name: golangci-lint - uses: golangci/golangci-lint-action@v2 + uses: golangci/golangci-lint-action@v6 with: # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version - version: v1.29 - skip-go-installation: true + version: v1.61 + skip-cache: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d943850..501a222 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,20 +10,20 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v5 with: - go-version: 1.18 + go-version: 1.22 - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v2 + uses: goreleaser/goreleaser-action@v6 with: distribution: goreleaser - version: latest - args: release --rm-dist + version: '~> v2' + args: release --clean env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b510a27..4903ca5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,7 +4,7 @@ jobs: test: strategy: matrix: - go-version: [1.18.x] + go-version: [1.22.x] os: [ubuntu-latest] runs-on: ${{ matrix.os }} steps: @@ -12,10 +12,10 @@ jobs: run: | echo "CGO_ENABLED=0" >> $GITHUB_ENV - name: Install Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v5 with: go-version: ${{ matrix.go-version }} - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Test run: go test ./... diff --git a/go.mod b/go.mod index 7151562..c4edb49 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,8 @@ module entrypoint -go 1.16 +go 1.22.0 + +toolchain go1.23.4 require ( github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 @@ -10,3 +12,13 @@ require ( github.com/stretchr/testify v1.3.0 gopkg.in/ini.v1 v1.51.0 ) + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/inconshreveable/mousetrap v1.0.0 // indirect + github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect + golang.org/x/mod v0.22.0 // indirect + golang.org/x/sys v0.12.0 // indirect +) diff --git a/go.sum b/go.sum index 2356583..a28e0a2 100644 --- a/go.sum +++ b/go.sum @@ -205,6 +205,8 @@ golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= +golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4= +golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -241,8 +243,9 @@ golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo= golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= diff --git a/utils/odoo.go b/utils/odoo.go index dfa7150..49682bd 100644 --- a/utils/odoo.go +++ b/utils/odoo.go @@ -2,12 +2,14 @@ package utils import ( "fmt" - log "github.com/sirupsen/logrus" - "gopkg.in/ini.v1" "os" "path/filepath" "strconv" "strings" + + log "github.com/sirupsen/logrus" + "golang.org/x/mod/semver" + "gopkg.in/ini.v1" ) type envConverter func([]string) map[string]string @@ -177,7 +179,7 @@ func UpdateFromVars(config *ini.File, odooVars map[string]string, appendNew bool // - Won't allow admin as default super user password, a random string is generated // - Won't allow to change the default ports because inside the container is not needed and will mess with the external // - Disable logrotate since supervisor will handle that -func SetDefaults(config *ini.File) { +func SetDefaults(config *ini.File, version string) { config.Section("options").Key("xmlrpc_port").SetValue("8069") config.Section("options").Key("longpolling_port").SetValue("8072") config.Section("options").Key("logrorate").SetValue("False") @@ -185,6 +187,12 @@ func SetDefaults(config *ini.File) { config.Section("options").Key("admin_passwd").Value() == "" { config.Section("options").Key("admin_passwd").SetValue(RandStringRunes(64)) } + if semver.Compare(version, "v16.0") != -1 { + config.Section("options").DeleteKey("longpolling_port") + config.Section("options").DeleteKey("xmlrpc_port") + config.Section("options").Key("gevent_port").SetValue("8072") + config.Section("options").Key("http_port").SetValue("8069") + } } // Odoo this func coordinates all the odoo configuration loading the config file, calling all the methods needed to @@ -214,7 +222,7 @@ func Odoo() error { } log.Debugf("Instance type: %s", instanceType) UpdateSentry(odooCfg, instanceType) - SetDefaults(odooCfg) + SetDefaults(odooCfg, parseVersion(os.Getenv("VERSION"))) autostart := true if os.Getenv("AUTOSTART") != "" { autostart, err = strconv.ParseBool(os.Getenv("AUTOSTART")) @@ -275,3 +283,14 @@ func prepareFiles() error { } return nil } + +func parseVersion(v string) string { + wV := strings.ToLower(v) + if strings.Contains(wV, "saas") { + parts := strings.SplitN(v, "-", 2) + if len(parts) == 2 { + return "v" + parts[1] + } + } + return "v" + v +} diff --git a/utils/odoo_test.go b/utils/odoo_test.go index 79aecf0..0730768 100644 --- a/utils/odoo_test.go +++ b/utils/odoo_test.go @@ -103,6 +103,30 @@ func TestGetInstanceType(t *testing.T) { assert.Errorf(t, err, "cannot determine the instance type, env vars INSTANCE_TYPE and ODOO_STAGE 'must' match") } +func TestParseVersion(t *testing.T) { + test := []struct { + given string + want string + }{ + { + given: "17.0", + want: "v17.0", + }, + { + given: "saas-8", + want: "v8", + }, + { + given: "saas-17.4", + want: "v17.4", + }, + } + + for _, c := range test { + assert.Equal(t, c.want, parseVersion(c.given)) + } +} + //func TestUpdateSentry(t *testing.T) { // values := []struct{ // input map[string]string