diff --git a/.github/workflows/golangcli-lint.yml b/.github/workflows/golangcli-lint.yml new file mode 100644 index 0000000..d361946 --- /dev/null +++ b/.github/workflows/golangcli-lint.yml @@ -0,0 +1,74 @@ +name: Linter + +# Run on every main merge and on PRs. +on: + push: + branches: ["main"] + paths: ["**.go", "**.proto", "go.mod", "go.sum", "**go.mod", "**go.sum"] + pull_request: + paths: ["**.go", "**.proto", "go.mod", "go.sum", "**go.mod", "**go.sum"] + +# Allow concurrent runs on main/release branches but isolates other branches +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref }} + cancel-in-progress: ${{ ! (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/')) }} + +permissions: + contents: read + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version: 1.21 + cache: false # the golangci-lint action already caches for us (https://github.com/golangci/golangci-lint-action#performance) + + # Use GitHub actions output paramters to get go paths. For more info, see + # https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions + - name: "Set output variables for go cache" + id: go-cache-paths + run: | + echo "go-build-cache=$(go env GOCACHE)" >> $GITHUB_OUTPUT + echo "go-mod-cache=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT + + - name: "Go build cache" + uses: actions/cache@v4 + with: + path: ${{ steps.go-cache-paths.outputs.go-build-cache }} + key: go-build-cache-${{ hashFiles('**/go.sum') }} + + - name: "Go mod cache" + uses: actions/cache@v4 + with: + path: ${{ steps.go-cache-paths.outputs.go-mod-cache }} + key: go-mod-cache-${{ hashFiles('**/go.sum') }} + + - name: golangci-lint + 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.54.2 + + # Optional: working directory, useful for monorepos + # working-directory: somedir + + # Optional: golangci-lint command line arguments. + args: --fix=false --timeout=5m + + # Optional: show only new issues if it's a pull request. The default value is `false`. + # only-new-issues: true + + # Optional: if set to true then the all caching functionality will be complete disabled, + # takes precedence over all other caching options. + # skip-cache: true + + # Optional: if set to true then the action don't cache or restore ~/go/pkg. + # skip-pkg-cache: true + + # Optional: if set to true then the action don't cache or restore ~/.cache/go-build. + # skip-build-cache: true diff --git a/.github/workflows/pr-tittle-lint.yml b/.github/workflows/pr-tittle-lint.yml new file mode 100644 index 0000000..a3c6bed --- /dev/null +++ b/.github/workflows/pr-tittle-lint.yml @@ -0,0 +1,18 @@ +name: PR lint + +on: + pull_request: + types: [opened, reopened, synchronize, edited] + +jobs: + pr-lint: + runs-on: ubuntu-latest + steps: + - uses: seferov/pr-lint-action@v1.2.0 + with: + # taken from https://gist.github.com/marcojahn/482410b728c31b221b70ea6d2c433f0c + title-regex: '^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test){1}(\([\w\-\.]+\))?(!)?: ([\w ])+([\s\S]*)' + # title-regex-flags (Optional) + title-regex-flags: "g" + # error-message (Optional) + error-message: "Please follow conventional commit style: https://www.conventionalcommits.org/en/v1.0.0/" diff --git a/.github/workflows/skip-golangci-lint.yml b/.github/workflows/skip-golangci-lint.yml new file mode 100644 index 0000000..9f384e9 --- /dev/null +++ b/.github/workflows/skip-golangci-lint.yml @@ -0,0 +1,17 @@ +name: Linter + +on: + pull_request: + # paths-ignore makes the action run when the given paths are unchanged + # See "Handling skipped but required checks" in + # https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/defining-the-mergeability-of-pull-requests/troubleshooting-required-status-checks#handling-skipped-but-required-checks + paths-ignore: ["**.go", "**.proto", "go.mod", "go.sum"] + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - name: skip-golangci + run: | + echo "job: golangci was skipped since Golang files were not changed." \ No newline at end of file diff --git a/feeder/eventstream/stream.go b/feeder/eventstream/stream.go index c3c2e00..6c0bb4f 100644 --- a/feeder/eventstream/stream.go +++ b/feeder/eventstream/stream.go @@ -12,6 +12,7 @@ import ( "github.com/rs/zerolog" "google.golang.org/grpc" "google.golang.org/grpc/credentials" + "google.golang.org/grpc/credentials/insecure" ) var _ types.EventStream = (*Stream)(nil) @@ -24,7 +25,7 @@ type wsI interface { // Dial opens two connections to the given endpoint, one for the websocket and one for the oracle grpc. func Dial(tendermintRPCEndpoint string, grpcEndpoint string, enableTLS bool, logger zerolog.Logger) *Stream { - transportDialOpt := grpc.WithInsecure() + var transportDialOpt grpc.DialOption if enableTLS { transportDialOpt = grpc.WithTransportCredentials( @@ -34,6 +35,10 @@ func Dial(tendermintRPCEndpoint string, grpcEndpoint string, enableTLS bool, log }, ), ) + } else { + transportDialOpt = grpc.WithTransportCredentials( + insecure.NewCredentials(), + ) } conn, err := grpc.Dial(grpcEndpoint, transportDialOpt) diff --git a/feeder/eventstream/stream_test.go b/feeder/eventstream/stream_test.go index 52d799f..b84eabd 100644 --- a/feeder/eventstream/stream_test.go +++ b/feeder/eventstream/stream_test.go @@ -14,6 +14,7 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" ) type IntegrationTestSuite struct { @@ -57,7 +58,7 @@ func (s *IntegrationTestSuite) SetupSuite() { enableTLS, zerolog.New(s.logs)) - conn, err := grpc.Dial(grpcEndpoint, grpc.WithInsecure()) + conn, err := grpc.Dial(grpcEndpoint, grpc.WithTransportCredentials(insecure.NewCredentials())) require.NoError(s.T(), err) s.oracleClient = oracletypes.NewQueryClient(conn) } diff --git a/feeder/priceposter/client.go b/feeder/priceposter/client.go index b412c76..1f5357b 100644 --- a/feeder/priceposter/client.go +++ b/feeder/priceposter/client.go @@ -20,6 +20,7 @@ import ( "github.com/rs/zerolog" "google.golang.org/grpc" "google.golang.org/grpc/credentials" + "google.golang.org/grpc/credentials/insecure" ) var _ types.PricePoster = (*Client)(nil) @@ -55,7 +56,7 @@ func Dial( feeder sdk.AccAddress, logger zerolog.Logger, ) *Client { - transportDialOpt := grpc.WithInsecure() + var transportDialOpt grpc.DialOption if enableTLS { transportDialOpt = grpc.WithTransportCredentials( @@ -65,6 +66,10 @@ func Dial( }, ), ) + } else { + transportDialOpt = grpc.WithTransportCredentials( + insecure.NewCredentials(), + ) } conn, err := grpc.Dial(grpcEndpoint, transportDialOpt) diff --git a/feeder/priceprovider/sources/coingecko_test.go b/feeder/priceprovider/sources/coingecko_test.go index 7773859..ea2b41b 100644 --- a/feeder/priceprovider/sources/coingecko_test.go +++ b/feeder/priceprovider/sources/coingecko_test.go @@ -17,6 +17,7 @@ func TestCoingeckoPriceUpdate(t *testing.T) { defer httpmock.DeactivateAndReset() t.Run("success", func(t *testing.T) { + httpmock.Reset() httpmock.RegisterResponder( "GET", FreeLink+"simple/price?ids=bitcoin%2Cethereum&vs_currencies=usd", httpmock.NewStringResponder(200, "{\"bitcoin\":{\"usd\":23829},\"ethereum\":{\"usd\":1676.85}}"), @@ -41,6 +42,7 @@ func TestCoingeckoWithConfig(t *testing.T) { defer httpmock.DeactivateAndReset() t.Run("providing valid config", func(t *testing.T) { + httpmock.Reset() httpmock.RegisterResponder( "GET", PaidLink+"simple/price?ids=bitcoin%2Cethereum&vs_currencies=usd&"+ApiKeyParam+"=1234567890", httpmock.NewStringResponder(200, "{\"bitcoin\":{\"usd\":23829},\"ethereum\":{\"usd\":1676.85}}"), @@ -72,6 +74,7 @@ func TestCoingeckoWithConfig(t *testing.T) { }) t.Run("providing config without api_key ignores and calls free endpoint", func(t *testing.T) { + httpmock.Reset() httpmock.RegisterResponder( "GET", FreeLink+"simple/price?ids=bitcoin%2Cethereum&vs_currencies=usd", httpmock.NewStringResponder(200, "{\"bitcoin\":{\"usd\":23829},\"ethereum\":{\"usd\":1676.85}}"), diff --git a/feeder/priceprovider/sources/coinmarketcap_test.go b/feeder/priceprovider/sources/coinmarketcap_test.go index c8ee795..ecec280 100644 --- a/feeder/priceprovider/sources/coinmarketcap_test.go +++ b/feeder/priceprovider/sources/coinmarketcap_test.go @@ -17,6 +17,7 @@ func TestCoinmarketcapPriceUpdate(t *testing.T) { defer httpmock.DeactivateAndReset() t.Run("success", func(t *testing.T) { + httpmock.Reset() httpmock.RegisterResponder( "GET", link+"?slug=bitcoin%2Cethereum", httpmock.NewStringResponder(200, "{\"status\": {\"error_code\":0},\"data\":{\"1\":{\"slug\":\"bitcoin\",\"quote\":{\"USD\":{\"price\":23829}}}, \"100\":{\"slug\":\"ethereum\",\"quote\":{\"USD\":{\"price\":1676.85}}}}}"),