diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 37d69a3ac..9b44cc6f3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,6 +12,13 @@ on: - master - 'feature/**' +# We need to set this explicitly to make sure the CI works on Windows +# Default shell does not terminate on error in GitHub Actions +# https://github.com/actions/runner-images/issues/6668 +defaults: + run: + shell: bash + jobs: test: strategy: @@ -22,7 +29,7 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 - - uses: actions/setup-go@v4 + - uses: actions/setup-go@v5 with: go-version: "1.20" - name: Run tests @@ -35,12 +42,14 @@ jobs: with: file: ./coverage.txt flags: unittests + token: ${{ secrets.CODECOV_TOKEN }} + if: matrix.os == 'ubuntu-latest' lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: actions/setup-go@v4 + - uses: actions/setup-go@v5 with: go-version: "1.20" - name: generate diff --git a/Makefile b/Makefile index 2b51cd907..9708ecac8 100644 --- a/Makefile +++ b/Makefile @@ -28,8 +28,8 @@ binary: $(BINARY) .PHONY: install-tools install-tools: - cd ${GOPATH}; \ - mkdir -p ${GOPATH}; \ + cd '${GOPATH}'; \ + mkdir -p '${GOPATH}'; \ GO111MODULE=on go install github.com/axw/gocov/gocov@latest; \ GO111MODULE=on go install github.com/matm/gocov-html/cmd/gocov-html@latest; \ GO111MODULE=on go install github.com/sanderhahn/gozip/cmd/gozip@latest; \ @@ -86,10 +86,6 @@ publish: 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 lint: generate golangci-lint run -v ./... diff --git a/internal/super/generate_test.go b/internal/super/generate_test.go index 8a7a37b12..5400edbda 100644 --- a/internal/super/generate_test.go +++ b/internal/super/generate_test.go @@ -19,6 +19,8 @@ package super import ( + "fmt" + "path/filepath" "testing" "github.com/onflow/flow-cli/internal/util" @@ -64,13 +66,14 @@ access(all) fun testContract() { Test.expect(err, Test.beNil()) }` - assert.Equal(t, expectedContent, string(fileContent)) - assert.Equal(t, expectedTestContent, string(testContent)) + assert.Equal(t, expectedContent, util.NormalizeLineEndings(string(fileContent))) + assert.Equal(t, expectedTestContent, util.NormalizeLineEndings(string(testContent))) // Test file already exists scenario _, err = generateNew([]string{"TestContract"}, "contract", logger, state) assert.Error(t, err) - assert.Equal(t, "file already exists: cadence/contracts/TestContract.cdc", err.Error()) + expectedError := fmt.Sprintf("file already exists: %s", filepath.FromSlash("cadence/contracts/TestContract.cdc")) + assert.Equal(t, expectedError, err.Error()) } func TestGenerateNewContractSkipTests(t *testing.T) { @@ -129,7 +132,8 @@ func TestGenerateNewContractFileAlreadyExists(t *testing.T) { // Test file already exists scenario _, err = generateNew([]string{"TestContract"}, "contract", logger, state) assert.Error(t, err) - assert.Equal(t, "file already exists: cadence/contracts/TestContract.cdc", err.Error()) + expectedError := fmt.Sprintf("file already exists: %s", filepath.FromSlash("cadence/contracts/TestContract.cdc")) + assert.Equal(t, expectedError, err.Error()) } func TestGenerateNewContractWithFileExtension(t *testing.T) { @@ -160,7 +164,7 @@ func TestGenerateNewScript(t *testing.T) { fun main() { // Script details here }` - assert.Equal(t, expectedContent, string(content)) + assert.Equal(t, expectedContent, util.NormalizeLineEndings(string(content))) } func TestGenerateNewTransaction(t *testing.T) { @@ -179,7 +183,7 @@ func TestGenerateNewTransaction(t *testing.T) { execute {} }` - assert.Equal(t, expectedContent, string(content)) + assert.Equal(t, expectedContent, util.NormalizeLineEndings(string(content))) } func TestGenerateNewWithDirFlag(t *testing.T) { @@ -200,5 +204,5 @@ func TestGenerateNewWithDirFlag(t *testing.T) { contract TestContract { init() {} }` - assert.Equal(t, expectedContent, string(content)) + assert.Equal(t, expectedContent, util.NormalizeLineEndings(string(content))) } diff --git a/internal/transactions/transactions_test.go b/internal/transactions/transactions_test.go index 3f45b9425..e8831d027 100644 --- a/internal/transactions/transactions_test.go +++ b/internal/transactions/transactions_test.go @@ -447,10 +447,10 @@ Fee Events (hidden, use --include fee-events)`, output.OkEmoji()), "\n") t.Run("Result without fee events", func(t *testing.T) { result := transactionResult{tx: tx, result: txResultFeeEvents} - assert.Equal(t, strings.TrimPrefix(` + assert.Equal(t, strings.TrimPrefix(fmt.Sprintf(` Block ID 7aa74143741c1c3b837d389fcffa7a5e251b67b4ffef6d6887b40cd9c803f537 Block Height 1 -Status ✅ SEALED +Status %s SEALED ID e913d1f3e431c7df49c99845bea9ebff9db11bbf25d507b9ad0fad45652d515f Payer 0000000000000002 Authorizers [] @@ -477,15 +477,15 @@ Code (hidden, use --include code) Payload (hidden, use --include payload) -Fee Events (hidden, use --include fee-events)`, "\n"), result.String()) +Fee Events (hidden, use --include fee-events)`, output.OkEmoji()), "\n"), result.String()) }) t.Run("Result with fee events", func(t *testing.T) { result := transactionResult{tx: tx, result: txResultFeeEvents, include: []string{"fee-events"}} - assert.Equal(t, strings.TrimPrefix(` + assert.Equal(t, strings.TrimPrefix(fmt.Sprintf(` Block ID 7aa74143741c1c3b837d389fcffa7a5e251b67b4ffef6d6887b40cd9c803f537 Block Height 1 -Status ✅ SEALED +Status %s SEALED ID e913d1f3e431c7df49c99845bea9ebff9db11bbf25d507b9ad0fad45652d515f Payer 0000000000000002 Authorizers [] @@ -528,6 +528,6 @@ Events: Code (hidden, use --include code) -Payload (hidden, use --include payload)`, "\n"), result.String()) +Payload (hidden, use --include payload)`, output.OkEmoji()), "\n"), result.String()) }) } diff --git a/internal/util/util.go b/internal/util/util.go index beec1a411..845673d9c 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -111,3 +111,7 @@ func removeFromStringArray(s []string, el string) []string { return s } + +func NormalizeLineEndings(s string) string { + return strings.ReplaceAll(s, "\r\n", "\n") +}