From 6d35468e6ebb969ce67beb67ad69682a17eb33f2 Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Fri, 8 Sep 2023 16:34:47 -0700 Subject: [PATCH 1/5] Swap "path" with "path/filepath" & store filepaths in UNIX format in flow.json --- flowkit/config/json/account.go | 9 +++++++-- flowkit/config/json/contract.go | 8 +++++--- flowkit/project/deployment.go | 3 ++- flowkit/project/deployment_test.go | 8 ++++---- flowkit/project/imports.go | 10 +++++----- flowkit/state.go | 5 ++--- internal/settings/settings.go | 4 ++-- internal/super/files.go | 9 ++++----- internal/super/files_test.go | 10 +++++----- internal/super/setup.go | 3 +-- internal/test/test.go | 8 ++++---- internal/util/prompt.go | 4 ++-- internal/util/util.go | 4 ++-- 13 files changed, 45 insertions(+), 40 deletions(-) diff --git a/flowkit/config/json/account.go b/flowkit/config/json/account.go index 6a6b0d178..21595de54 100644 --- a/flowkit/config/json/account.go +++ b/flowkit/config/json/account.go @@ -22,6 +22,7 @@ import ( "encoding/json" "fmt" "os" + "path/filepath" "regexp" "strings" @@ -224,7 +225,7 @@ func transformAdvancedToConfig(accountName string, a advancedAccount) (*config.A if a.Key.Location == "" { return nil, fmt.Errorf("missing location to a file containing the private key value for the account %s", accountName) } - key.Location = a.Key.Location + key.Location = filepath.ToSlash(a.Key.Location) } return &config.Account{ @@ -326,7 +327,7 @@ func transformAdvancedKeyToJSON(key config.AccountKey) advanceKey { case config.KeyTypeGoogleKMS: advancedKey.ResourceID = key.ResourceID case config.KeyTypeFile: - advancedKey.Location = key.Location + advancedKey.Location = filepath.ToSlash(key.Location) } return advancedKey @@ -446,6 +447,10 @@ func (j *account) UnmarshalJSON(b []byte) error { err = json.Unmarshal(b, &advanced) j.Advanced = advanced } + + if j.Advanced.Key.Type == config.KeyTypeFile { + j.Advanced.Key.Location = filepath.FromSlash(j.Advanced.Key.Location) + } return err } diff --git a/flowkit/config/json/contract.go b/flowkit/config/json/contract.go index 39a400f63..b1a12b6b1 100644 --- a/flowkit/config/json/contract.go +++ b/flowkit/config/json/contract.go @@ -21,6 +21,7 @@ package json import ( "encoding/json" "fmt" + "path/filepath" "github.com/invopop/jsonschema" "github.com/onflow/flow-go-sdk" @@ -70,7 +71,7 @@ func transformContractsToJSON(contracts config.Contracts) jsonContracts { // if simple case if !c.IsAliased() { jsonContracts[c.Name] = jsonContract{ - Simple: c.Location, + Simple: filepath.ToSlash(c.Location), } } else { // if advanced config // check if we already created for this name then add or create @@ -81,7 +82,7 @@ func transformContractsToJSON(contracts config.Contracts) jsonContracts { jsonContracts[c.Name] = jsonContract{ Advanced: jsonContractAdvanced{ - Source: c.Location, + Source: filepath.ToSlash(c.Location), Aliases: aliases, }, } @@ -110,7 +111,7 @@ func (j *jsonContract) UnmarshalJSON(b []byte) error { // simple err := json.Unmarshal(b, &source) if err == nil { - j.Simple = source + j.Simple = filepath.FromSlash(source) return nil } @@ -118,6 +119,7 @@ func (j *jsonContract) UnmarshalJSON(b []byte) error { err = json.Unmarshal(b, &advancedFormat) if err == nil { j.Advanced = advancedFormat + j.Advanced.Source = filepath.FromSlash(j.Advanced.Source) } else { return err } diff --git a/flowkit/project/deployment.go b/flowkit/project/deployment.go index 6f97afd86..f8b4f1431 100644 --- a/flowkit/project/deployment.go +++ b/flowkit/project/deployment.go @@ -20,6 +20,7 @@ package project import ( "fmt" + "path/filepath" "gonum.org/v1/gonum/graph" "gonum.org/v1/gonum/graph/simple" @@ -86,7 +87,7 @@ func (d *Deployment) add(contract *Contract) error { } d.contracts = append(d.contracts, c) - d.contractsByLocation[c.Location()] = c + d.contractsByLocation[filepath.Clean(c.Location())] = c d.contractsByName[c.Name] = c return nil diff --git a/flowkit/project/deployment_test.go b/flowkit/project/deployment_test.go index e22c87c8b..f5916ea7c 100644 --- a/flowkit/project/deployment_test.go +++ b/flowkit/project/deployment_test.go @@ -38,7 +38,7 @@ type testContract struct { var addresses = test.AddressGenerator() var testContractA = testContract{ - location: "ContractA.cdc", + location: "foobar/ContractA.cdc", code: []byte(`pub contract ContractA {}`), accountAddress: addresses.New(), } @@ -50,7 +50,7 @@ var testContractB = testContract{ } var testContractC = testContract{ - location: "ContractC.cdc", + location: "foobar/ContractC.cdc", code: []byte(` import ContractA from "ContractA.cdc" @@ -62,7 +62,7 @@ var testContractC = testContract{ var testContractD = testContract{ location: "ContractD.cdc", code: []byte(` - import ContractC from "ContractC.cdc" + import ContractC from "foobar/ContractC.cdc" pub contract ContractD {} `), @@ -91,7 +91,7 @@ var testContractF = testContract{ var testContractG = testContract{ location: "ContractG.cdc", code: []byte(` - import ContractA from "ContractA.cdc" + import ContractA from "foobar/ContractA.cdc" import ContractB from "ContractB.cdc" pub contract ContractG {} diff --git a/flowkit/project/imports.go b/flowkit/project/imports.go index 07f57206b..268b0e86e 100644 --- a/flowkit/project/imports.go +++ b/flowkit/project/imports.go @@ -20,7 +20,7 @@ package project import ( "fmt" - "path" + "path/filepath" "github.com/onflow/flow-go-sdk" ) @@ -49,7 +49,7 @@ func (i *ImportReplacer) Replace(program *Program) (*Program, error) { for _, imp := range imports { // check if import by path exists (e.g. import X from ["./X.cdc"]) - importLocation := path.Clean(absolutePath(program.Location(), imp)) + importLocation := filepath.Clean(absolutePath(program.Location(), imp)) address, isPath := contractsLocations[importLocation] if isPath { program.replaceImport(imp, address) @@ -72,18 +72,18 @@ func (i *ImportReplacer) Replace(program *Program) (*Program, error) { func (i *ImportReplacer) getContractsLocations() map[string]string { locationAddress := make(map[string]string) for _, contract := range i.contracts { - locationAddress[path.Clean(contract.Location())] = contract.AccountAddress.String() + locationAddress[filepath.Clean(contract.Location())] = contract.AccountAddress.String() // add also by name since we might use the new import schema locationAddress[contract.Name] = contract.AccountAddress.String() } for source, target := range i.aliases { - locationAddress[path.Clean(source)] = flow.HexToAddress(target).String() + locationAddress[filepath.Clean(source)] = flow.HexToAddress(target).String() } return locationAddress } func absolutePath(basePath, relativePath string) string { - return path.Join(path.Dir(basePath), relativePath) + return filepath.Join(filepath.Dir(basePath), relativePath) } diff --git a/flowkit/state.go b/flowkit/state.go index 96d2c8d99..1fc05c517 100644 --- a/flowkit/state.go +++ b/flowkit/state.go @@ -21,7 +21,6 @@ package flowkit import ( "fmt" "os" - "path" "path/filepath" "github.com/onflow/flow-go-sdk/crypto" @@ -173,7 +172,7 @@ func (p *State) DeploymentContractsByNetwork(network config.Network) ([]*project contract := project.NewContract( c.Name, - path.Clean(location), + filepath.Clean(location), code, account.Address, account.Name, @@ -213,7 +212,7 @@ func (p *State) AliasesForNetwork(network config.Network) project.LocationAliase for _, contract := range p.conf.Contracts { if contract.IsAliased() && contract.Aliases.ByNetwork(network.Name) != nil { alias := contract.Aliases.ByNetwork(network.Name).Address.String() - aliases[path.Clean(contract.Location)] = alias // alias for import by file location + aliases[filepath.Clean(contract.Location)] = alias // alias for import by file location aliases[contract.Name] = alias // alias for import by name } } diff --git a/internal/settings/settings.go b/internal/settings/settings.go index 1ccb73536..d611123ac 100644 --- a/internal/settings/settings.go +++ b/internal/settings/settings.go @@ -22,7 +22,7 @@ import ( "errors" "fmt" "os" - "path" + "path/filepath" "github.com/spf13/viper" ) @@ -51,7 +51,7 @@ func FileDir() string { if err != nil { dir = "." } - return path.Join(dir, settingsDir) + return filepath.Join(dir, settingsDir) } // Set updates settings file with new value for provided key diff --git a/internal/super/files.go b/internal/super/files.go index c86437fe6..d1388bfa2 100644 --- a/internal/super/files.go +++ b/internal/super/files.go @@ -22,7 +22,6 @@ import ( "fmt" "io/fs" "os" - "path" "path/filepath" "time" @@ -58,7 +57,7 @@ type contractChange struct { func newProjectFiles(projectPath string) *projectFiles { return &projectFiles{ - cadencePath: path.Join(projectPath, cadenceDir), + cadencePath: filepath.Join(projectPath, cadenceDir), watcher: watcher.New(), } } @@ -121,7 +120,7 @@ func (f *projectFiles) transactions() ([]string, error) { // This function returns two channels, accountChange which reports any changes on the accounts folders and // contractChange which reports any changes to the contract files. func (f *projectFiles) watch() (<-chan accountChange, <-chan contractChange, error) { - err := f.watcher.AddRecursive(path.Join(f.cadencePath, contractDir)) + err := f.watcher.AddRecursive(filepath.Join(f.cadencePath, contractDir)) if err != nil { return nil, nil, errors.Wrap(err, "add recursive files failed") } @@ -193,7 +192,7 @@ func (f *projectFiles) watch() (<-chan accountChange, <-chan contractChange, err // getFilePaths returns a list of only Cadence files that are inside the provided directory. func (f *projectFiles) getCadenceFilepaths(dir string) ([]string, error) { - dir = path.Join(f.cadencePath, dir) + dir = filepath.Join(f.cadencePath, dir) paths := make([]string, 0) err := filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error { if path == dir || d.IsDir() || filepath.Ext(path) != cadenceExt { // we only want to get .cdc files in the dir @@ -218,7 +217,7 @@ func (f *projectFiles) getCadenceFilepaths(dir string) ([]string, error) { // relProjectPath gets a filepath relative to the project directory including the base cadence directory. // eg. a path /Users/Mike/Dev/project/cadence/contracts/foo.cdc will become cadence/contracts/foo.cdc func (f *projectFiles) relProjectPath(file string) (string, error) { - rel, err := filepath.Rel(path.Dir(f.cadencePath), file) + rel, err := filepath.Rel(filepath.Dir(f.cadencePath), file) if err != nil { return "", errors.Wrap(err, "failed getting project relative path") } diff --git a/internal/super/files_test.go b/internal/super/files_test.go index 08358e615..879ad9fb5 100644 --- a/internal/super/files_test.go +++ b/internal/super/files_test.go @@ -20,7 +20,7 @@ package super import ( "fmt" - "path" + "path/filepath" "testing" "github.com/stretchr/testify/assert" @@ -45,10 +45,10 @@ func Test_AccountFromPath(t *testing.T) { func Test_RelativeProjectPath(t *testing.T) { cdcDir := "/Users/Mike/Dev/my-project/cadence" paths := [][]string{ - {path.Join(cdcDir, "/contracts/foo.cdc"), "cadence/contracts/foo.cdc"}, - {path.Join(cdcDir, "/contracts/alice/foo.cdc"), "cadence/contracts/alice/foo.cdc"}, - {path.Join(cdcDir, "/scripts/bar.cdc"), "cadence/scripts/bar.cdc"}, - {path.Join(cdcDir, "/bar.cdc"), "cadence/bar.cdc"}, + {filepath.Join(cdcDir, "/contracts/foo.cdc"), "cadence/contracts/foo.cdc"}, + {filepath.Join(cdcDir, "/contracts/alice/foo.cdc"), "cadence/contracts/alice/foo.cdc"}, + {filepath.Join(cdcDir, "/scripts/bar.cdc"), "cadence/scripts/bar.cdc"}, + {filepath.Join(cdcDir, "/bar.cdc"), "cadence/bar.cdc"}, } f := &projectFiles{ diff --git a/internal/super/setup.go b/internal/super/setup.go index 2b54703bd..96168a7f8 100644 --- a/internal/super/setup.go +++ b/internal/super/setup.go @@ -25,7 +25,6 @@ import ( "io" "net/http" "os" - "path" "path/filepath" "time" @@ -123,7 +122,7 @@ func getTargetDirectory(directory string) (string, error) { return "", err } - target := path.Join(pwd, directory) + target := filepath.Join(pwd, directory) info, err := os.Stat(target) if !os.IsNotExist(err) { if !info.IsDir() { diff --git a/internal/test/test.go b/internal/test/test.go index 12772902b..32098beaa 100644 --- a/internal/test/test.go +++ b/internal/test/test.go @@ -23,7 +23,7 @@ import ( "encoding/json" "fmt" "os" - "path" + "path/filepath" "strings" cdcTests "github.com/onflow/cadence-tools/test" @@ -100,7 +100,7 @@ func run( var file []byte var err error - ext := path.Ext(testFlags.CoverProfile) + ext := filepath.Ext(testFlags.CoverProfile) if ext == ".json" { file, err = json.MarshalIndent(coverageReport, "", " ") } else if ext == ".lcov" { @@ -223,11 +223,11 @@ func fileResolver(scriptPath string, state *flowkit.State) cdcTests.FileResolver } func absolutePath(basePath, filePath string) string { - if path.IsAbs(filePath) { + if filepath.IsAbs(filePath) { return filePath } - return path.Join(path.Dir(basePath), filePath) + return filepath.Join(filepath.Dir(basePath), filePath) } type result struct { diff --git a/internal/util/prompt.go b/internal/util/prompt.go index 5c721ed07..deb194d73 100644 --- a/internal/util/prompt.go +++ b/internal/util/prompt.go @@ -21,7 +21,7 @@ package util import ( "fmt" "os" - "path" + "path/filepath" "strconv" "strings" @@ -685,7 +685,7 @@ func InstallPathPrompt(defaultPath string) string { os.Exit(-1) } - return path.Clean(install) + return filepath.Clean(install) } type ScaffoldItem struct { diff --git a/internal/util/util.go b/internal/util/util.go index c47c62cbd..f928ded19 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -23,7 +23,7 @@ import ( "encoding/hex" "fmt" "os" - "path" + "path/filepath" "strings" "text/tabwriter" @@ -46,7 +46,7 @@ func AddToGitIgnore(filename string, loader flowkit.ReaderWriter) error { if err != nil { return err } - gitIgnorePath := path.Join(currentWd, ".gitignore") + gitIgnorePath := filepath.Join(currentWd, ".gitignore") gitIgnoreFiles := "" filePermissions := os.FileMode(0644) From af9710385bad15776cd95a121754ed3afcdb3f68 Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Tue, 12 Sep 2023 15:25:21 -0700 Subject: [PATCH 2/5] Fix tests --- Makefile | 43 ++++++++++++++-------- flowkit/state_test.go | 17 +++++---- internal/super/files_test.go | 18 ++++----- internal/transactions/transactions_test.go | 10 +++-- 4 files changed, 53 insertions(+), 35 deletions(-) diff --git a/Makefile b/Makefile index bd131835f..a052898a9 100644 --- a/Makefile +++ b/Makefile @@ -8,11 +8,22 @@ VERSION := $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null) COVER_PROFILE := coverage.txt # Disable go sum database lookup for private repos GOPRIVATE := github.com/dapperlabs/* + # Ensure go bin path is in path (Especially for CI) -GOPATH ?= $(HOME)/go -PATH := $(PATH):$(GOPATH)/bin -# OS -UNAME := $(shell uname) +ifeq ($(OS),Windows_NT) + GOPATH ?= $(USERPROFILE)\go + PATH := $(PATH);$(GOPATH)\bin +else + GOPATH ?= $(HOME)/go + PATH := $(PATH):$(GOPATH)/bin +endif + +# Set MKDIR variable based on OS +ifeq ($(OS),Windows_NT) + MKDIR := mkdir +else + MKDIR := mkdir -p +endif MIXPANEL_PROJECT_TOKEN := 3fae49de272be1ceb8cf34119f747073 ACCOUNT_TOKEN := lilico:sF60s3wughJBmNh2 @@ -24,17 +35,20 @@ binary: $(BINARY) .PHONY: install-tools install-tools: - cd ${GOPATH}; \ - mkdir -p ${GOPATH}; \ - GO111MODULE=on go install github.com/axw/gocov/gocov@latest; \ - GO111MODULE=on go install github.com/matm/gocov-html@latest; \ - GO111MODULE=on go install github.com/sanderhahn/gozip/cmd/gozip@latest; \ - GO111MODULE=on go install github.com/vektra/mockery/v2@latest; + $(MKDIR) ${GOPATH} && \ + go env -w GO111MODULE=on && \ + go install github.com/axw/gocov/gocov@latest && \ + go install github.com/matm/gocov-html@latest && \ + go install github.com/sanderhahn/gozip/cmd/gozip@latest && \ + go install github.com/vektra/mockery/v2@latest .PHONY: test test: - GO111MODULE=on go test -coverprofile=$(COVER_PROFILE) $(if $(JSON_OUTPUT),-json,) ./... - cd flowkit; GO111MODULE=on go test -coverprofile=$(COVER_PROFILE) $(if $(JSON_OUTPUT),-json,) ./... + go env -w GO111MODULE=on && \ + go env -w CGO_ENABLED=0 && \ + go test -coverprofile=$(COVER_PROFILE) $(if $(JSON_OUTPUT),-json,) ./... && \ + cd flowkit && \ + go test -coverprofile=$(COVER_PROFILE) $(if $(JSON_OUTPUT),-json,) ./... .PHONY: test-e2e-emulator test-e2e-emulator: @@ -82,7 +96,6 @@ clean: rm ./cmd/flow/flow* .PHONY: install-linter -install-linter: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ${GOPATH}/bin v1.47.2 .PHONY: lint @@ -104,7 +117,7 @@ check-schema: .PHONY: check-tidy check-tidy: go mod tidy - cd flowkit; go mod tidy + cd flowkit && go mod tidy .PHONY: generate-schema generate-schema: @@ -112,5 +125,5 @@ generate-schema: .PHONY: generate generate: install-tools - cd flowkit; \ + cd flowkit && \ go generate ./... \ No newline at end of file diff --git a/flowkit/state_test.go b/flowkit/state_test.go index a7b2a9b6c..e8d73e6d3 100644 --- a/flowkit/state_test.go +++ b/flowkit/state_test.go @@ -21,6 +21,7 @@ package flowkit import ( "fmt" "os" + "path/filepath" "sort" "testing" @@ -343,7 +344,7 @@ func generateAliasesComplexProject() State { func Test_GetContractsByNameSimple(t *testing.T) { p := generateSimpleProject() - path := "../hungry-kitties/cadence/contracts/NonFungibleToken.cdc" + path := filepath.FromSlash("../hungry-kitties/cadence/contracts/NonFungibleToken.cdc") af.WriteFile(path, []byte("pub contract{}"), os.ModePerm) contracts, err := p.DeploymentContractsByNetwork(config.EmulatorNetwork) @@ -423,13 +424,13 @@ func Test_GetContractsByNameComplex(t *testing.T) { assert.Equal(t, contractNames[5], "KittyItemsMarket") assert.Equal(t, contractNames[6], "NonFungibleToken") - assert.Equal(t, sources[0], "../hungry-kitties/cadence/contracts/FungibleToken.cdc") - assert.Equal(t, sources[1], "../hungry-kitties/cadence/contracts/NonFungibleToken.cdc") - assert.Equal(t, sources[2], "cadence/kibble/contracts/Kibble.cdc") - assert.Equal(t, sources[3], "cadence/kittyItems/contracts/KittyItems.cdc") - assert.Equal(t, sources[4], "cadence/kittyItems/contracts/KittyItems.cdc") - assert.Equal(t, sources[5], "cadence/kittyItemsMarket/contracts/KittyItemsMarket.cdc") - assert.Equal(t, sources[6], "cadence/kittyItemsMarket/contracts/KittyItemsMarket.cdc") + assert.Equal(t, sources[0], filepath.FromSlash("../hungry-kitties/cadence/contracts/FungibleToken.cdc")) + assert.Equal(t, sources[1], filepath.FromSlash("../hungry-kitties/cadence/contracts/NonFungibleToken.cdc")) + assert.Equal(t, sources[2], filepath.FromSlash("cadence/kibble/contracts/Kibble.cdc")) + assert.Equal(t, sources[3], filepath.FromSlash("cadence/kittyItems/contracts/KittyItems.cdc")) + assert.Equal(t, sources[4], filepath.FromSlash("cadence/kittyItems/contracts/KittyItems.cdc")) + assert.Equal(t, sources[5], filepath.FromSlash("cadence/kittyItemsMarket/contracts/KittyItemsMarket.cdc")) + assert.Equal(t, sources[6], filepath.FromSlash("cadence/kittyItemsMarket/contracts/KittyItemsMarket.cdc")) assert.Equal(t, targets[0], "f8d6e0586b0a20c1") assert.Equal(t, targets[1], "f8d6e0586b0a20c1") diff --git a/internal/super/files_test.go b/internal/super/files_test.go index 879ad9fb5..85993f026 100644 --- a/internal/super/files_test.go +++ b/internal/super/files_test.go @@ -28,11 +28,11 @@ import ( func Test_AccountFromPath(t *testing.T) { paths := [][]string{ // first is path, second is account name - {"cadence/contracts/alice/foo.cdc", "alice"}, - {"cadence/contracts/alice", "alice"}, - {"cadence/contracts/alice/boo/foo.cdc", ""}, - {"cadence/contracts/foo.cdc", ""}, - {"cadence/contracts/foo/bar/goo/foo", ""}, + {filepath.FromSlash("cadence/contracts/alice/foo.cdc"), "alice"}, + {filepath.FromSlash("cadence/contracts/alice"), "alice"}, + {filepath.FromSlash("cadence/contracts/alice/boo/foo.cdc"), ""}, + {filepath.FromSlash("cadence/contracts/foo.cdc"), ""}, + {filepath.FromSlash("cadence/contracts/foo/bar/goo/foo"), ""}, } for i, test := range paths { @@ -45,10 +45,10 @@ func Test_AccountFromPath(t *testing.T) { func Test_RelativeProjectPath(t *testing.T) { cdcDir := "/Users/Mike/Dev/my-project/cadence" paths := [][]string{ - {filepath.Join(cdcDir, "/contracts/foo.cdc"), "cadence/contracts/foo.cdc"}, - {filepath.Join(cdcDir, "/contracts/alice/foo.cdc"), "cadence/contracts/alice/foo.cdc"}, - {filepath.Join(cdcDir, "/scripts/bar.cdc"), "cadence/scripts/bar.cdc"}, - {filepath.Join(cdcDir, "/bar.cdc"), "cadence/bar.cdc"}, + {filepath.Join(cdcDir, "/contracts/foo.cdc"), filepath.FromSlash("cadence/contracts/foo.cdc")}, + {filepath.Join(cdcDir, "/contracts/alice/foo.cdc"), filepath.FromSlash("cadence/contracts/alice/foo.cdc")}, + {filepath.Join(cdcDir, "/scripts/bar.cdc"), filepath.FromSlash("cadence/scripts/bar.cdc")}, + {filepath.Join(cdcDir, "/bar.cdc"), filepath.FromSlash("cadence/bar.cdc")}, } f := &projectFiles{ diff --git a/internal/transactions/transactions_test.go b/internal/transactions/transactions_test.go index ad9e799c8..ef49d676a 100644 --- a/internal/transactions/transactions_test.go +++ b/internal/transactions/transactions_test.go @@ -20,6 +20,7 @@ package transactions import ( "encoding/json" + "fmt" "strings" "testing" @@ -31,6 +32,7 @@ import ( "github.com/onflow/flow-cli/flowkit" "github.com/onflow/flow-cli/flowkit/accounts" "github.com/onflow/flow-cli/flowkit/config" + "github.com/onflow/flow-cli/flowkit/output" "github.com/onflow/flow-cli/flowkit/tests" "github.com/onflow/flow-cli/flowkit/transactions" "github.com/onflow/flow-cli/internal/command" @@ -344,10 +346,10 @@ Payload (hidden, use --include payload)`, "\n"), result.String()) t.Run("Success with result", func(t *testing.T) { result := transactionResult{tx: tx, result: txResult} - assert.Equal(t, strings.TrimPrefix(` + expectedString := strings.TrimPrefix(fmt.Sprintf(` Block ID 7aa74143741c1c3b837d389fcffa7a5e251b67b4ffef6d6887b40cd9c803f537 Block Height 1 -Status ✅ SEALED +Status %s SEALED ID e913d1f3e431c7df49c99845bea9ebff9db11bbf25d507b9ad0fad45652d515f Payer 0000000000000002 Authorizers [] @@ -372,7 +374,9 @@ Events: Code (hidden, use --include code) -Payload (hidden, use --include payload)`, "\n"), result.String()) +Payload (hidden, use --include payload)`, output.OkEmoji()), "\n") + + assert.Equal(t, expectedString, result.String()) assert.Equal(t, map[string]any{ "authorizers": "[]", From 7ee66b457dcda75e5527475f579413904c228e10 Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Fri, 15 Sep 2023 08:20:58 -0700 Subject: [PATCH 3/5] Fix makefile and tests --- .github/workflows/ci.yml | 6 +--- Makefile | 51 +++++++++++++++------------- flowkit/config/json/account.go | 6 +--- flowkit/config/json/account_test.go | 3 +- flowkit/config/json/contract_test.go | 15 ++++---- flowkit/config/loader_test.go | 3 +- flowkit/state_test.go | 33 +++++++++--------- internal/super/files_test.go | 24 ++++++------- 8 files changed, 71 insertions(+), 70 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dda7bdd81..a20d3d51d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,11 +28,7 @@ jobs: restore-keys: | ${{ runner.os }}-go- - name: Run tests - run: | - make ci - make check-tidy - make check-headers - make check-schema + run: make ci && make check-tidy && make check-headers && make check-schema - name: Upload coverage report uses: codecov/codecov-action@v1 with: diff --git a/Makefile b/Makefile index a052898a9..9724014fd 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,22 @@ +# Set OS-related environment variables +ifeq ($(OS),Windows_NT) + SHELL := cmd.exe + GOPATH ?= $(USERPROFILE)\go + PATH := $(PATH);$(GOPATH)\bin + MKDIR_GOPATH := if not exist "$(GOPATH)" md "$(GOPATH)" + SET_GOPATH := go env -w GOPATH="$(GOPATH)" + SET_GO111MODULE := go env -w GO111MODULE=on + SET_CGO_DISABLED := go env -w CGO_ENABLED=0 +else + SHELL := /bin/bash + GOPATH ?= $(HOME)/go + PATH := $(PATH):$(GOPATH)/bin + MKDIR_GOPATH := mkdir -p "$(GOPATH)" + SET_GOPATH := export GOPATH="$(GOPATH)" + SET_GO111MODULE := export GO111MODULE=on + SET_CGO_DISABLED := export CGO_ENABLED=0 +endif + # The short Git commit hash SHORT_COMMIT := $(shell git rev-parse --short HEAD) # The Git commit hash @@ -9,22 +28,6 @@ COVER_PROFILE := coverage.txt # Disable go sum database lookup for private repos GOPRIVATE := github.com/dapperlabs/* -# Ensure go bin path is in path (Especially for CI) -ifeq ($(OS),Windows_NT) - GOPATH ?= $(USERPROFILE)\go - PATH := $(PATH);$(GOPATH)\bin -else - GOPATH ?= $(HOME)/go - PATH := $(PATH):$(GOPATH)/bin -endif - -# Set MKDIR variable based on OS -ifeq ($(OS),Windows_NT) - MKDIR := mkdir -else - MKDIR := mkdir -p -endif - MIXPANEL_PROJECT_TOKEN := 3fae49de272be1ceb8cf34119f747073 ACCOUNT_TOKEN := lilico:sF60s3wughJBmNh2 @@ -35,17 +38,18 @@ binary: $(BINARY) .PHONY: install-tools install-tools: - $(MKDIR) ${GOPATH} && \ - go env -w GO111MODULE=on && \ + $(MKDIR_GOPATH) && \ + $(SET_GOPATH) && \ + $(SET_GO111MODULE) && \ go install github.com/axw/gocov/gocov@latest && \ - go install github.com/matm/gocov-html@latest && \ + go install github.com/matm/gocov-html/cmd/gocov-html@latest && \ go install github.com/sanderhahn/gozip/cmd/gozip@latest && \ go install github.com/vektra/mockery/v2@latest .PHONY: test test: - go env -w GO111MODULE=on && \ - go env -w CGO_ENABLED=0 && \ + $(SET_GO111MODULE) && \ + $(SET_CGO_DISABLED) && \ go test -coverprofile=$(COVER_PROFILE) $(if $(JSON_OUTPUT),-json,) ./... && \ cd flowkit && \ go test -coverprofile=$(COVER_PROFILE) $(if $(JSON_OUTPUT),-json,) ./... @@ -62,7 +66,7 @@ ifeq ($(COVER), true) ./cover-summary.sh gocov-html cover.json > index.html # coverage.zip will automatically be picked up by teamcity - gozip -c coverage.zip index.html + gozip -c coverage.zip index.html endif .PHONY: ci @@ -121,9 +125,10 @@ check-tidy: .PHONY: generate-schema generate-schema: - cd flowkit && go run ./cmd/flow-schema/flow-schema.go ./schema.json + echo %PATH% && dir $(GOPATH) && cd flowkit && go run ./cmd/flow-schema/flow-schema.go ./schema.json .PHONY: generate generate: install-tools + echo %PATH% && dir $(GOPATH) && \ cd flowkit && \ go generate ./... \ No newline at end of file diff --git a/flowkit/config/json/account.go b/flowkit/config/json/account.go index 21595de54..7708ee35a 100644 --- a/flowkit/config/json/account.go +++ b/flowkit/config/json/account.go @@ -225,7 +225,7 @@ func transformAdvancedToConfig(accountName string, a advancedAccount) (*config.A if a.Key.Location == "" { return nil, fmt.Errorf("missing location to a file containing the private key value for the account %s", accountName) } - key.Location = filepath.ToSlash(a.Key.Location) + key.Location = filepath.FromSlash(a.Key.Location) } return &config.Account{ @@ -447,10 +447,6 @@ func (j *account) UnmarshalJSON(b []byte) error { err = json.Unmarshal(b, &advanced) j.Advanced = advanced } - - if j.Advanced.Key.Type == config.KeyTypeFile { - j.Advanced.Key.Location = filepath.FromSlash(j.Advanced.Key.Location) - } return err } diff --git a/flowkit/config/json/account_test.go b/flowkit/config/json/account_test.go index 21eb6a1ef..0cb836828 100644 --- a/flowkit/config/json/account_test.go +++ b/flowkit/config/json/account_test.go @@ -21,6 +21,7 @@ import ( "encoding/json" "fmt" "os" + "path/filepath" "testing" "github.com/onflow/flow-go-sdk" @@ -114,7 +115,7 @@ func Test_ConfigAccountKeysAdvancedFile(t *testing.T) { assert.Equal(t, "f8d6e0586b0a20c7", account.Address.String()) assert.Equal(t, "SHA3_256", key.HashAlgo.String()) assert.Equal(t, "ECDSA_P256", key.SigAlgo.String()) - assert.Equal(t, "./test.pkey", key.Location) + assert.Equal(t, filepath.FromSlash("./test.pkey"), key.Location) assert.Equal(t, "", key.ResourceID) jsonAccs := transformAccountsToJSON(accounts) diff --git a/flowkit/config/json/contract_test.go b/flowkit/config/json/contract_test.go index 0ddb2d28a..bd9ab0800 100644 --- a/flowkit/config/json/contract_test.go +++ b/flowkit/config/json/contract_test.go @@ -19,6 +19,7 @@ package json import ( "encoding/json" + "path/filepath" "testing" "github.com/stretchr/testify/assert" @@ -43,8 +44,8 @@ func Test_ConfigContractsSimple(t *testing.T) { marketContract, _ := contracts.ByName("KittyItemsMarket") assert.NotNil(t, marketContract) - assert.Equal(t, "./cadence/kittyItems/contracts/KittyItems.cdc", contract.Location) - assert.Equal(t, "./cadence/kittyItems/contracts/KittyItemsMarket.cdc", marketContract.Location) + assert.Equal(t, filepath.FromSlash("./cadence/kittyItems/contracts/KittyItems.cdc"), contract.Location) + assert.Equal(t, filepath.FromSlash("./cadence/kittyItems/contracts/KittyItemsMarket.cdc"), marketContract.Location) } func Test_ConfigContractsComplex(t *testing.T) { @@ -73,8 +74,8 @@ func Test_ConfigContractsComplex(t *testing.T) { kittyItemsMarket, _ := contracts.ByName("KittyItemsMarket") assert.NotNil(t, kittyItemsMarket) - assert.Equal(t, "./cadence/kittyItems/contracts/KittyItems.cdc", kittyItems.Location) - assert.Equal(t, "./cadence/kittyItemsMarket/contracts/KittyItemsMarket.cdc", kittyItemsMarket.Location) + assert.Equal(t, filepath.FromSlash("./cadence/kittyItems/contracts/KittyItems.cdc"), kittyItems.Location) + assert.Equal(t, filepath.FromSlash("./cadence/kittyItemsMarket/contracts/KittyItemsMarket.cdc"), kittyItemsMarket.Location) assert.True(t, kittyItemsMarket.Aliases.ByNetwork("emulator") == nil) @@ -115,19 +116,19 @@ func Test_ConfigContractsAliases(t *testing.T) { assert.NotNil(t, fungibleToken) assert.True(t, fungibleToken.IsAliased()) assert.Equal(t, "e5a8b7f23e8b548f", fungibleToken.Aliases.ByNetwork("emulator").Address.String()) - assert.Equal(t, "../hungry-kitties/cadence/contracts/FungibleToken.cdc", fungibleToken.Location) + assert.Equal(t, filepath.FromSlash("../hungry-kitties/cadence/contracts/FungibleToken.cdc"), fungibleToken.Location) kibble, _ := contracts.ByName("Kibble") assert.NotNil(t, kibble) assert.True(t, kibble.IsAliased()) - assert.Equal(t, "../hungry-kitties/cadence/contracts/Kibble.cdc", kibble.Location) + assert.Equal(t, filepath.FromSlash("../hungry-kitties/cadence/contracts/Kibble.cdc"), kibble.Location) assert.Equal(t, "ead892083b3e2c6c", kibble.Aliases.ByNetwork("testnet").Address.String()) assert.Equal(t, "f8d6e0586b0a20c7", kibble.Aliases.ByNetwork("emulator").Address.String()) nft, _ := contracts.ByName("NonFungibleToken") assert.NotNil(t, nft) assert.False(t, nft.IsAliased()) - assert.Equal(t, nft.Location, "../hungry-kitties/cadence/contracts/NonFungibleToken.cdc") + assert.Equal(t, nft.Location, filepath.FromSlash("../hungry-kitties/cadence/contracts/NonFungibleToken.cdc")) } func Test_TransformContractToJSON(t *testing.T) { diff --git a/flowkit/config/loader_test.go b/flowkit/config/loader_test.go index 85a36b8b9..d77a74e54 100644 --- a/flowkit/config/loader_test.go +++ b/flowkit/config/loader_test.go @@ -20,6 +20,7 @@ package config_test import ( "fmt" "os" + "path/filepath" "testing" "github.com/onflow/flow-cli/flowkit/config" @@ -459,5 +460,5 @@ func Test_LoadAccountFileType(t *testing.T) { assert.NoError(t, err) assert.Len(t, conf.Accounts, 1) - assert.Equal(t, "./test.pkey", acc.Key.Location) + assert.Equal(t, filepath.FromSlash("./test.pkey"), acc.Key.Location) } diff --git a/flowkit/state_test.go b/flowkit/state_test.go index e8d73e6d3..af39e923b 100644 --- a/flowkit/state_test.go +++ b/flowkit/state_test.go @@ -400,21 +400,22 @@ func Test_GetContractsByNameComplex(t *testing.T) { require.NoError(t, err) require.Equal(t, 7, len(contracts)) - //sort names so tests are deterministic + //sort contracts by name so tests are deterministic + sort.Slice(contracts, func(i, j int) bool { + return contracts[i].Name < contracts[j].Name + }) + contractNames := funk.Map(contracts, func(c *project.Contract) string { return c.Name }).([]string) - sort.Strings(contractNames) sources := funk.Map(contracts, func(c *project.Contract) string { return c.Location() }).([]string) - sort.Strings(sources) targets := funk.Map(contracts, func(c *project.Contract) string { return c.AccountAddress.String() }).([]string) - sort.Strings(targets) assert.Equal(t, contractNames[0], "FungibleToken") assert.Equal(t, contractNames[1], "Kibble") @@ -425,20 +426,20 @@ func Test_GetContractsByNameComplex(t *testing.T) { assert.Equal(t, contractNames[6], "NonFungibleToken") assert.Equal(t, sources[0], filepath.FromSlash("../hungry-kitties/cadence/contracts/FungibleToken.cdc")) - assert.Equal(t, sources[1], filepath.FromSlash("../hungry-kitties/cadence/contracts/NonFungibleToken.cdc")) - assert.Equal(t, sources[2], filepath.FromSlash("cadence/kibble/contracts/Kibble.cdc")) + assert.Equal(t, sources[1], filepath.FromSlash("cadence/kibble/contracts/Kibble.cdc")) + assert.Equal(t, sources[2], filepath.FromSlash("cadence/kittyItems/contracts/KittyItems.cdc")) assert.Equal(t, sources[3], filepath.FromSlash("cadence/kittyItems/contracts/KittyItems.cdc")) - assert.Equal(t, sources[4], filepath.FromSlash("cadence/kittyItems/contracts/KittyItems.cdc")) + assert.Equal(t, sources[4], filepath.FromSlash("cadence/kittyItemsMarket/contracts/KittyItemsMarket.cdc")) assert.Equal(t, sources[5], filepath.FromSlash("cadence/kittyItemsMarket/contracts/KittyItemsMarket.cdc")) - assert.Equal(t, sources[6], filepath.FromSlash("cadence/kittyItemsMarket/contracts/KittyItemsMarket.cdc")) + assert.Equal(t, sources[6], filepath.FromSlash("../hungry-kitties/cadence/contracts/NonFungibleToken.cdc")) assert.Equal(t, targets[0], "f8d6e0586b0a20c1") assert.Equal(t, targets[1], "f8d6e0586b0a20c1") - assert.Equal(t, targets[2], "f8d6e0586b0a20c1") + assert.Equal(t, targets[2], "f8d6e0586b0a20c7") assert.Equal(t, targets[3], "f8d6e0586b0a20c1") - assert.Equal(t, targets[4], "f8d6e0586b0a20c1") - assert.Equal(t, targets[5], "f8d6e0586b0a20c7") - assert.Equal(t, targets[6], "f8d6e0586b0a20c7") + assert.Equal(t, targets[4], "f8d6e0586b0a20c7") + assert.Equal(t, targets[5], "f8d6e0586b0a20c1") + assert.Equal(t, targets[6], "f8d6e0586b0a20c1") } func Test_EmulatorConfigComplex(t *testing.T) { @@ -486,7 +487,7 @@ func Test_GetAliases(t *testing.T) { contracts, _ := p.DeploymentContractsByNetwork(config.EmulatorNetwork) assert.Len(t, aliases, 2) - assert.Equal(t, aliases["../hungry-kitties/cadence/contracts/FungibleToken.cdc"], "ee82856bf20e2aa6") + assert.Equal(t, aliases[filepath.FromSlash("../hungry-kitties/cadence/contracts/FungibleToken.cdc")], "ee82856bf20e2aa6") assert.Len(t, contracts, 1) assert.Equal(t, contracts[0].Name, "NonFungibleToken") } @@ -504,11 +505,11 @@ func Test_GetAliasesComplex(t *testing.T) { assert.Equal(t, cEmulator[0].Name, "NonFungibleToken") assert.Len(t, aEmulator, 4) - assert.Equal(t, aEmulator["../hungry-kitties/cadence/contracts/FungibleToken.cdc"], "ee82856bf20e2aa6") - assert.Equal(t, aEmulator["../hungry-kitties/cadence/contracts/Kibble.cdc"], "ee82856bf20e2aa6") + assert.Equal(t, aEmulator[filepath.FromSlash("../hungry-kitties/cadence/contracts/FungibleToken.cdc")], "ee82856bf20e2aa6") + assert.Equal(t, aEmulator[filepath.FromSlash("../hungry-kitties/cadence/contracts/Kibble.cdc")], "ee82856bf20e2aa6") assert.Len(t, aTestnet, 2) - assert.Equal(t, aTestnet["../hungry-kitties/cadence/contracts/Kibble.cdc"], "ee82856bf20e2aa6") + assert.Equal(t, aTestnet[filepath.FromSlash("../hungry-kitties/cadence/contracts/Kibble.cdc")], "ee82856bf20e2aa6") assert.Len(t, cTestnet, 2) assert.Equal(t, cTestnet[0].Name, "NonFungibleToken") diff --git a/internal/super/files_test.go b/internal/super/files_test.go index 85993f026..9f9888017 100644 --- a/internal/super/files_test.go +++ b/internal/super/files_test.go @@ -28,15 +28,15 @@ import ( func Test_AccountFromPath(t *testing.T) { paths := [][]string{ // first is path, second is account name - {filepath.FromSlash("cadence/contracts/alice/foo.cdc"), "alice"}, - {filepath.FromSlash("cadence/contracts/alice"), "alice"}, - {filepath.FromSlash("cadence/contracts/alice/boo/foo.cdc"), ""}, - {filepath.FromSlash("cadence/contracts/foo.cdc"), ""}, - {filepath.FromSlash("cadence/contracts/foo/bar/goo/foo"), ""}, + {"cadence/contracts/alice/foo.cdc", "alice"}, + {"cadence/contracts/alice", "alice"}, + {"cadence/contracts/alice/boo/foo.cdc", ""}, + {"cadence/contracts/foo.cdc", ""}, + {"cadence/contracts/foo/bar/goo/foo", ""}, } for i, test := range paths { - name, ok := accountFromPath(test[0]) + name, ok := accountFromPath(filepath.FromSlash(test[0])) assert.Equal(t, test[1] != "", ok) // if we don't provide a name we mean it shouldn't be returned assert.Equal(t, test[1], name, fmt.Sprintf("failed test %d", i)) } @@ -45,10 +45,10 @@ func Test_AccountFromPath(t *testing.T) { func Test_RelativeProjectPath(t *testing.T) { cdcDir := "/Users/Mike/Dev/my-project/cadence" paths := [][]string{ - {filepath.Join(cdcDir, "/contracts/foo.cdc"), filepath.FromSlash("cadence/contracts/foo.cdc")}, - {filepath.Join(cdcDir, "/contracts/alice/foo.cdc"), filepath.FromSlash("cadence/contracts/alice/foo.cdc")}, - {filepath.Join(cdcDir, "/scripts/bar.cdc"), filepath.FromSlash("cadence/scripts/bar.cdc")}, - {filepath.Join(cdcDir, "/bar.cdc"), filepath.FromSlash("cadence/bar.cdc")}, + {filepath.Join(cdcDir, "/contracts/foo.cdc"), "cadence/contracts/foo.cdc"}, + {filepath.Join(cdcDir, "/contracts/alice/foo.cdc"), "cadence/contracts/alice/foo.cdc"}, + {filepath.Join(cdcDir, "/scripts/bar.cdc"), "cadence/scripts/bar.cdc"}, + {filepath.Join(cdcDir, "/bar.cdc"), "cadence/bar.cdc"}, } f := &projectFiles{ @@ -56,8 +56,8 @@ func Test_RelativeProjectPath(t *testing.T) { } for i, test := range paths { - rel, err := f.relProjectPath(test[0]) + rel, err := f.relProjectPath(filepath.FromSlash(test[0])) assert.NoError(t, err) - assert.Equal(t, test[1], rel, fmt.Sprintf("test %d failed", i)) + assert.Equal(t, filepath.FromSlash(test[1]), rel, fmt.Sprintf("test %d failed", i)) } } From b997277e6a70991499d953db224a20c4d08da01f Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Fri, 15 Sep 2023 08:31:07 -0700 Subject: [PATCH 4/5] upgrade setup-go --- .github/workflows/ci.yml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a20d3d51d..32e42bbfa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,18 +18,13 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 - - uses: actions/setup-go@v1 + - uses: actions/setup-go@v4 with: go-version: "1.19" - - uses: actions/cache@v1 - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - name: Run tests run: make ci && make check-tidy && make check-headers && make check-schema - name: Upload coverage report + if: matrix.os == 'ubuntu-latest' uses: codecov/codecov-action@v1 with: file: ./coverage.txt From 819981cb32873e485481b32794933f2f21fa8254 Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Fri, 15 Sep 2023 09:23:32 -0700 Subject: [PATCH 5/5] Revert CI changes --- .github/workflows/ci.yml | 15 ++++++++--- Makefile | 54 ++++++++++++++-------------------------- 2 files changed, 30 insertions(+), 39 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 32e42bbfa..dda7bdd81 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,13 +18,22 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 - - uses: actions/setup-go@v4 + - uses: actions/setup-go@v1 with: go-version: "1.19" + - uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- - name: Run tests - run: make ci && make check-tidy && make check-headers && make check-schema + run: | + make ci + make check-tidy + make check-headers + make check-schema - name: Upload coverage report - if: matrix.os == 'ubuntu-latest' uses: codecov/codecov-action@v1 with: file: ./coverage.txt diff --git a/Makefile b/Makefile index 9724014fd..bd131835f 100644 --- a/Makefile +++ b/Makefile @@ -1,22 +1,3 @@ -# Set OS-related environment variables -ifeq ($(OS),Windows_NT) - SHELL := cmd.exe - GOPATH ?= $(USERPROFILE)\go - PATH := $(PATH);$(GOPATH)\bin - MKDIR_GOPATH := if not exist "$(GOPATH)" md "$(GOPATH)" - SET_GOPATH := go env -w GOPATH="$(GOPATH)" - SET_GO111MODULE := go env -w GO111MODULE=on - SET_CGO_DISABLED := go env -w CGO_ENABLED=0 -else - SHELL := /bin/bash - GOPATH ?= $(HOME)/go - PATH := $(PATH):$(GOPATH)/bin - MKDIR_GOPATH := mkdir -p "$(GOPATH)" - SET_GOPATH := export GOPATH="$(GOPATH)" - SET_GO111MODULE := export GO111MODULE=on - SET_CGO_DISABLED := export CGO_ENABLED=0 -endif - # The short Git commit hash SHORT_COMMIT := $(shell git rev-parse --short HEAD) # The Git commit hash @@ -27,6 +8,11 @@ VERSION := $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null) COVER_PROFILE := coverage.txt # Disable go sum database lookup for private repos GOPRIVATE := github.com/dapperlabs/* +# Ensure go bin path is in path (Especially for CI) +GOPATH ?= $(HOME)/go +PATH := $(PATH):$(GOPATH)/bin +# OS +UNAME := $(shell uname) MIXPANEL_PROJECT_TOKEN := 3fae49de272be1ceb8cf34119f747073 ACCOUNT_TOKEN := lilico:sF60s3wughJBmNh2 @@ -38,21 +24,17 @@ binary: $(BINARY) .PHONY: install-tools install-tools: - $(MKDIR_GOPATH) && \ - $(SET_GOPATH) && \ - $(SET_GO111MODULE) && \ - go install github.com/axw/gocov/gocov@latest && \ - go install github.com/matm/gocov-html/cmd/gocov-html@latest && \ - go install github.com/sanderhahn/gozip/cmd/gozip@latest && \ - go install github.com/vektra/mockery/v2@latest + cd ${GOPATH}; \ + mkdir -p ${GOPATH}; \ + GO111MODULE=on go install github.com/axw/gocov/gocov@latest; \ + GO111MODULE=on go install github.com/matm/gocov-html@latest; \ + GO111MODULE=on go install github.com/sanderhahn/gozip/cmd/gozip@latest; \ + GO111MODULE=on go install github.com/vektra/mockery/v2@latest; .PHONY: test test: - $(SET_GO111MODULE) && \ - $(SET_CGO_DISABLED) && \ - go test -coverprofile=$(COVER_PROFILE) $(if $(JSON_OUTPUT),-json,) ./... && \ - cd flowkit && \ - go test -coverprofile=$(COVER_PROFILE) $(if $(JSON_OUTPUT),-json,) ./... + GO111MODULE=on go test -coverprofile=$(COVER_PROFILE) $(if $(JSON_OUTPUT),-json,) ./... + cd flowkit; GO111MODULE=on go test -coverprofile=$(COVER_PROFILE) $(if $(JSON_OUTPUT),-json,) ./... .PHONY: test-e2e-emulator test-e2e-emulator: @@ -66,7 +48,7 @@ ifeq ($(COVER), true) ./cover-summary.sh gocov-html cover.json > index.html # coverage.zip will automatically be picked up by teamcity - gozip -c coverage.zip index.html + gozip -c coverage.zip index.html endif .PHONY: ci @@ -100,6 +82,7 @@ clean: rm ./cmd/flow/flow* .PHONY: install-linter +install-linter: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ${GOPATH}/bin v1.47.2 .PHONY: lint @@ -121,14 +104,13 @@ check-schema: .PHONY: check-tidy check-tidy: go mod tidy - cd flowkit && go mod tidy + cd flowkit; go mod tidy .PHONY: generate-schema generate-schema: - echo %PATH% && dir $(GOPATH) && cd flowkit && go run ./cmd/flow-schema/flow-schema.go ./schema.json + cd flowkit && go run ./cmd/flow-schema/flow-schema.go ./schema.json .PHONY: generate generate: install-tools - echo %PATH% && dir $(GOPATH) && \ - cd flowkit && \ + cd flowkit; \ go generate ./... \ No newline at end of file