From 53b0c0f7ab0d4b22e69b21a9765ecc7ab75a5078 Mon Sep 17 00:00:00 2001 From: Victor Farazdagi Date: Thu, 4 Jun 2020 19:16:45 +0300 Subject: [PATCH] Adds gofmt checker action to GitHub workflow (#6132) * adds gofmt checker action to GitHub workflow * gofmt applied --- .github/actions/gofmt/Dockerfile | 5 +++++ .github/actions/gofmt/action.yml | 12 ++++++++++++ .github/actions/gofmt/entrypoint.sh | 15 +++++++++++++++ .github/workflows/go.yml | 14 +++++++++++++- beacon-chain/powchain/service_test.go | 2 +- 5 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 .github/actions/gofmt/Dockerfile create mode 100644 .github/actions/gofmt/action.yml create mode 100755 .github/actions/gofmt/entrypoint.sh diff --git a/.github/actions/gofmt/Dockerfile b/.github/actions/gofmt/Dockerfile new file mode 100644 index 00000000000..19341e58714 --- /dev/null +++ b/.github/actions/gofmt/Dockerfile @@ -0,0 +1,5 @@ +FROM cytopia/gofmt + +COPY entrypoint.sh /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/.github/actions/gofmt/action.yml b/.github/actions/gofmt/action.yml new file mode 100644 index 00000000000..be7dad6cc49 --- /dev/null +++ b/.github/actions/gofmt/action.yml @@ -0,0 +1,12 @@ +name: 'Gofmt checker' +description: 'Checks that all project files have been properly formatted.' +inputs: + path: + description: 'Path to check' + required: true + default: './' +runs: + using: 'docker' + image: 'Dockerfile' + args: + - ${{ inputs.path }} \ No newline at end of file diff --git a/.github/actions/gofmt/entrypoint.sh b/.github/actions/gofmt/entrypoint.sh new file mode 100755 index 00000000000..3c72d3330cf --- /dev/null +++ b/.github/actions/gofmt/entrypoint.sh @@ -0,0 +1,15 @@ +#!/bin/sh -l +set -e + +cd $GITHUB_WORKSPACE + +# Check if any files are not formatted. +nonformatted="$(gofmt -l $1 2>&1)" + +# Return if `go fmt` passes. +[ -z "$nonformatted" ] && exit 0 + +# Notify of issues with formatting. +echo "Following files need to be properly formatted:" +echo "$nonformatted" +exit 1 diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 84c8bacb987..3d66357bf37 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -8,11 +8,23 @@ on: jobs: + check: + name: Check + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v1 + + - name: Gofmt checker + id: gofmt + uses: ./.github/actions/gofmt + with: + path: ./ + build: name: Build runs-on: ubuntu-latest steps: - - name: Set up Go 1.x uses: actions/setup-go@v2 with: diff --git a/beacon-chain/powchain/service_test.go b/beacon-chain/powchain/service_test.go index 14a72b91443..ad6b343f922 100644 --- a/beacon-chain/powchain/service_test.go +++ b/beacon-chain/powchain/service_test.go @@ -14,13 +14,13 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind/backends" "github.com/ethereum/go-ethereum/common" gethTypes "github.com/ethereum/go-ethereum/core/types" - logTest "github.com/sirupsen/logrus/hooks/test" dbutil "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" mockPOW "github.com/prysmaticlabs/prysm/beacon-chain/powchain/testing" contracts "github.com/prysmaticlabs/prysm/contracts/deposit-contract" protodb "github.com/prysmaticlabs/prysm/proto/beacon/db" "github.com/prysmaticlabs/prysm/shared/event" "github.com/prysmaticlabs/prysm/shared/testutil" + logTest "github.com/sirupsen/logrus/hooks/test" ) var _ = ChainStartFetcher(&Service{})