Skip to content

Commit

Permalink
Added github action for checking pull requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Skarlso committed Aug 2, 2022
1 parent de90dcf commit 601f026
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/lint_and_test.yaml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 5 additions & 3 deletions hack/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 601f026

Please sign in to comment.