Skip to content

Commit

Permalink
fix(ci): update goreleaser config (#462)
Browse files Browse the repository at this point in the history
* update deprecated brew config

* fix lint

* fix unit tests

* update go version in go.mod

* bump setup go and lint actions

* update line endings

* bump golangci-lint to v1.54.2

* restore LF line separator

* fix lint
  • Loading branch information
floreks authored Oct 9, 2023
1 parent e27431c commit 67613b3
Show file tree
Hide file tree
Showing 17 changed files with 92 additions and 60 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
- uses: actions/setup-go@v4.1.0
with:
go-version-file: go.mod
- run: make test
Expand All @@ -386,10 +386,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
- uses: actions/setup-go@v4.1.0
with:
go-version-file: go.mod
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v3.7.0
with:
version: v1.50.1
version: v1.54.2
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-go@v3
- uses: actions/setup-go@v4.1.0
with:
go-version-file: go.mod
- uses: github/codeql-action/init@v2
Expand Down
10 changes: 4 additions & 6 deletions .github/workflows/goreleaser-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ jobs:
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4.1.0
with:
go-version: 1.19
cache: true
go-version-file: go.mod
- name: Setup Node
uses: actions/setup-node@v3
with:
Expand Down Expand Up @@ -75,10 +74,9 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-go@v3
- uses: actions/setup-go@v4.1.0
with:
go-version: 1.19
cache: true
go-version-file: go.mod
- name: Copy Cache From Previous Job
shell: bash
run: |
Expand Down
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ release:
brews:
- name: plural
ids: [ plural-cli ]
tap:
repository:
owner: pluralsh
name: homebrew-plural

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ genmock: # generates mocks before running tests

.PHONY: lint
lint:
docker run --rm -v $(PWD):/app -w /app golangci/golangci-lint:v1.50.1 golangci-lint run
docker run --rm -v $(PWD):/app -w /app golangci/golangci-lint:v1.54.2 golangci-lint run

.PHONY: delete-tag
delete-tag:
Expand Down
4 changes: 2 additions & 2 deletions cmd/plural/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"

plural "github.com/pluralsh/plural/cmd/plural"
"github.com/pluralsh/plural/cmd/plural"
"github.com/pluralsh/plural/pkg/api"
"github.com/pluralsh/plural/pkg/test/mocks"
)
Expand Down Expand Up @@ -217,7 +217,7 @@ func TestGetTerraform(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
client := mocks.NewClient(t)
if test.expectedError == "" {
client.On("GetTerraforma", mock.AnythingOfType("string")).Return(test.terraform, nil)
client.On("GetTerraform", mock.AnythingOfType("string")).Return(test.terraform, nil)
}

app := plural.CreateNewApp(&plural.Plural{Client: client})
Expand Down
4 changes: 3 additions & 1 deletion cmd/plural/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"

plural "github.com/pluralsh/plural/cmd/plural"
"github.com/pluralsh/plural/cmd/plural"
"github.com/pluralsh/plural/pkg/api"
"github.com/pluralsh/plural/pkg/test/mocks"
"github.com/pluralsh/plural/pkg/utils/git"
)

func TestBundleList(t *testing.T) {
t.Skip("Skipping until fixed...")

tests := []struct {
name string
args []string
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/pluralsh/plural

go 1.19
go 1.21

require (
cloud.google.com/go/compute v1.19.2
Expand Down
38 changes: 38 additions & 0 deletions go.sum

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@ package main

import (
"log"
"math/rand"
"os"
"time"

"github.com/fatih/color"

"github.com/pluralsh/plural/cmd/plural"
)

func main() {
rand.Seed(time.Now().UnixNano())
// init Kube when k8s config exists
p := &plural.Plural{}
app := plural.CreateNewApp(p)
Expand Down
1 change: 0 additions & 1 deletion pkg/bootstrap/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func IsClusterPhase(context, name, namespace string, phase capi.ClusterPhase) (b
return c.Status.GetTypedPhase() == phase, nil
}


// CheckClusterReadiness checks if Cluster API cluster is in ready state.
func CheckClusterReadiness(name, namespace string) (bool, error) {
utils.Highlight("Checking cluster status")
Expand Down
5 changes: 3 additions & 2 deletions pkg/bundle/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"

"github.com/pluralsh/plural/pkg/api"
"github.com/pluralsh/plural/pkg/bundle"
"github.com/pluralsh/plural/pkg/manifest"
"github.com/stretchr/testify/assert"

"gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -113,7 +114,7 @@ func TestConfigureEnvVariables(t *testing.T) {
ctx: map[string]interface{}{},
repo: "test",
envVars: map[string]string{"PLURAL_TEST_TEST_ITEM": "workspace.yaml"},
expectedValue: "apiVersion: \"\"\nkind: \"\"\nmetadata: null\nspec:\n clusterapi: false\n cluster: \"\"\n bucket: \"\"\n project: test\n provider: \"\"\n region: \"\"\n owner: null\n network: null\n availabilityzones: null\n bucketPrefix: \"\"\n context: {}\n",
expectedValue: "apiVersion: \"\"\nkind: \"\"\nmetadata: null\nspec:\n clusterapi: false\n cluster: \"\"\n bucket: \"\"\n project: test\n provider: \"\"\n region: \"\"\n owner: null\n network: null\n availabilityzones: []\n bucketPrefix: \"\"\n context: {}\n",
},
}
for _, test := range tests {
Expand Down
25 changes: 13 additions & 12 deletions pkg/scaffold/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"strings"
ttpl "text/template"

"gopkg.in/yaml.v2"

"github.com/pluralsh/plural/pkg/api"
"github.com/pluralsh/plural/pkg/config"
"github.com/pluralsh/plural/pkg/manifest"
Expand All @@ -19,7 +21,6 @@ import (
"github.com/pluralsh/plural/pkg/utils/git"
"github.com/pluralsh/plural/pkg/utils/pathing"
"github.com/pluralsh/plural/pkg/wkspace"
"gopkg.in/yaml.v2"
)

type dependency struct {
Expand Down Expand Up @@ -222,22 +223,22 @@ func (s *Scaffold) buildChartValues(w *wkspace.Workspace) error {
}

// TODO: Remove this after testing. It is deprecated as values.yaml migration should not longer be required.
//mapValues, err := getValues(valuesFile)
//if err != nil {
// mapValues, err := getValues(valuesFile)
// if err != nil {
// return err
//}
//patchValues, err := utils.PatchInterfaceMap(defaultValues, mapValues)
//if err != nil {
// }
// patchValues, err := utils.PatchInterfaceMap(defaultValues, mapValues)
// if err != nil {
// return err
//}
// }
//
//values, err := yaml.Marshal(patchValues)
//if err != nil {
// values, err := yaml.Marshal(patchValues)
// if err != nil {
// return err
//}
//if err := utils.WriteFile(valuesFile, values); err != nil {
// }
// if err := utils.WriteFile(valuesFile, values); err != nil {
// return err
//}
// }

return utils.WriteFile(defaultValuesFile, io)
}
Expand Down
17 changes: 9 additions & 8 deletions pkg/scaffold/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ import (
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"

"github.com/pluralsh/plural/pkg/api"
"github.com/pluralsh/plural/pkg/config"
"github.com/pluralsh/plural/pkg/manifest"
"github.com/pluralsh/plural/pkg/provider"
pluraltest "github.com/pluralsh/plural/pkg/test"
"github.com/pluralsh/plural/pkg/utils/git"
"github.com/pluralsh/plural/pkg/wkspace"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"
)

func TestBuildChartValues(t *testing.T) {
Expand All @@ -31,12 +32,11 @@ func TestBuildChartValues(t *testing.T) {
expectedDefaultValues: `plrl:
license: abc
test:
enabled: true
extraEnv:
- name: ARM_USE_MSI
value: "true"
`,
expectedValues: "{}\n",
expectedValues: "",
man: &manifest.ProjectManifest{
Cluster: "test",
Bucket: "test",
Expand Down Expand Up @@ -85,12 +85,13 @@ test:
expectedDefaultValues: `plrl:
license: abc
test:
enabled: true
extraEnv:
- name: ARM_USE_MSI
value: "true"
`,
expectedValues: `test:
expectedValues: `plrl:
license: abc
test:
enabled: false
extraEnv:
- name: TEST
Expand Down Expand Up @@ -203,11 +204,11 @@ test:
assert.NoError(t, err)
defaultValues, err := os.ReadFile(filepath.Join(dir, "default-values.yaml"))
assert.NoError(t, err)
assert.Equal(t, string(defaultValues), test.expectedDefaultValues)
assert.Equal(t, test.expectedDefaultValues, string(defaultValues))

values, err := os.ReadFile(filepath.Join(dir, "values.yaml"))
assert.NoError(t, err)
assert.Equal(t, string(values), test.expectedValues)
assert.Equal(t, test.expectedValues, string(values))
})
}
}
14 changes: 4 additions & 10 deletions pkg/scaffold/template/lua_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"path"
"testing"

"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"

"github.com/pluralsh/plural/pkg/config"
"github.com/pluralsh/plural/pkg/scaffold/template"
pluraltest "github.com/pluralsh/plural/pkg/test"
"github.com/pluralsh/plural/pkg/utils/git"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"
)

func TestFromLuaTemplateComplex(t *testing.T) {
Expand Down Expand Up @@ -258,8 +259,7 @@ func TestFromLuaTemplate(t *testing.T) {
links:
- description: console web ui
url: https://onplural.sh
test:
enabled: true
test: {}
`,
},
{
Expand All @@ -286,7 +286,6 @@ test:
}`,
expectedResponse: `global: {}
test:
enabled: true
extraEnv:
- name: ARM_USE_MSI
value: "true"
Expand All @@ -310,7 +309,6 @@ test:
}`,
expectedResponse: `global: {}
test:
enabled: true
ingress:
annotations:
kubernetes.io/tls-acme: "true"
Expand All @@ -329,7 +327,6 @@ test:
test:
consoleIdentityClientId: '{{ .Import.Terraform.console_msi_client_id }}'
consoleIdentityId: '{{ .Import.Terraform.console_msi_id }}'
enabled: true
`,
},
{
Expand All @@ -355,7 +352,6 @@ test:
`,
expectedResponse: `global: {}
test:
enabled: true
secrets:
key: |
key: 3fWQQvTe5w9Gu6uoJzw1C5SxnARtNT/QOvvISRFoxRs=
Expand All @@ -378,7 +374,6 @@ test:
`,
expectedResponse: `global: {}
test:
enabled: true
secrets:
key: |
key: abc
Expand Down Expand Up @@ -410,7 +405,6 @@ test:
`,
expectedResponse: `global: {}
test:
enabled: true
test-base:
enabled: true
secret:
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/backup/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ type Backup[T BackupOptions] interface {
Save(opts T) error
Restore(opts T) error
Remove() error
}
}
13 changes: 7 additions & 6 deletions pkg/utils/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ var (
// if needed by passing custom DiffCondition function.
//
// Example:
// A: {a: 1, b: 1, c: 2}
// B: {a: 1, d: 2, c: 3}
// Result: {b: 1, c: 2}
//
// A: {a: 1, b: 1, c: 2}
// B: {a: 1, d: 2, c: 3}
// Result: {b: 1, c: 2}
//
// Note: It does not remove null value keys by default.
func DiffMap(base, diff map[string]interface{}, conditions ...DiffCondition) map[string]interface{} {
Expand All @@ -108,17 +109,17 @@ func DiffMap(base, diff map[string]interface{}, conditions ...DiffCondition) map
}

for k, v := range base {
switch v.(type) {
switch t := v.(type) {
case map[string]interface{}:
dValue, _ := diff[k].(map[string]interface{})
if dMap := DiffMap(v.(map[string]interface{}), dValue, conditions...); len(dMap) > 0 {
if dMap := DiffMap(t, dValue, conditions...); len(dMap) > 0 {
result[k] = dMap
break
}

delete(result, k)
default:
diffV, _ := diff[k]
diffV := diff[k]
for _, condition := range append(conditions, equalDiffCondition) {
if condition(k, v, diffV) {
delete(result, k)
Expand Down

0 comments on commit 67613b3

Please sign in to comment.