From 601f0260208cad5f7dcc6db811417174125cef4e Mon Sep 17 00:00:00 2001 From: Gergely Brautigam <182850+Skarlso@users.noreply.github.com> Date: Tue, 2 Aug 2022 10:10:55 +0200 Subject: [PATCH] Added github action for checking pull requests --- .github/workflows/lint_and_test.yaml | 61 ++++++++++++++++++++++++++++ hack/check.sh | 8 ++-- 2 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/lint_and_test.yaml diff --git a/.github/workflows/lint_and_test.yaml b/.github/workflows/lint_and_test.yaml new file mode 100644 index 000000000..432c26583 --- /dev/null +++ b/.github/workflows/lint_and_test.yaml @@ -0,0 +1,61 @@ +name: lint-and-test + +on: + pull_request: {} + +jobs: + test: + name: Run tests + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Cache go-build and mod + uses: actions/cache@v3 + with: + path: | + ~/.cache/go-build/ + ~/go/pkg/mod/ + key: go-${{ hashFiles('go.sum') }} + restore-keys: | + go- + - name: Setup Go + uses: actions/setup-go@v3 + with: + go-version: 1.18.x + - name: Unit test + run: | + PATH=$PATH:$(go env GOPATH)/bin make build + PATH=$PATH:$(go env GOPATH)/bin make test + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Cache go-build and mod + uses: actions/cache@v3 + with: + path: | + ~/.cache/go-build/ + ~/go/pkg/mod/ + key: go-${{ hashFiles('go.sum') }} + restore-keys: | + go- + - name: Setup Go + uses: actions/setup-go@v3 + with: + go-version: 1.18.x + - name: Install goimports + run: | + go install golang.org/x/tools/cmd/goimports@latest + - name: Setup lint + run: | + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.47.2 + - name: Lint + run: | + PATH=$PATH:$(go env GOPATH)/bin make check \ No newline at end of file diff --git a/hack/check.sh b/hack/check.sh index 9c8c9975c..6c80d5f28 100755 --- a/hack/check.sh +++ b/hack/check.sh @@ -23,12 +23,14 @@ echo "Executing golangci-lint" echo " golangci-lint run $GOLANGCI_LINT_CONFIG_FILE --timeout 10m $@" golangci-lint run $GOLANGCI_LINT_CONFIG_FILE --timeout 10m $@ -echo "Executing gofmt" +echo "Executing goimports" folders=() for f in $@; do - folders+=( "$(echo $f | sed 's/\(.*\)\/\.\.\./\1/')" ) + folders+=( "$(echo "$f" | sed 's/\(.*\)\/\.\.\./\1/')" ) done -unformatted_files="$(goimports -l -local=github.com/open-component-model/ocm ${folders[*]})" + +GOBIN=$(go env GOPATH) +unformatted_files="$("${GOBIN}/bin"/goimports -l -local=github.com/open-component-model/ocm ${folders[*]})" if [[ "$unformatted_files" ]]; then echo "Unformatted files detected:" echo "$unformatted_files"