Skip to content

Commit

Permalink
Merge pull request #37 from gardener/github_actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Skarlso authored Aug 8, 2022
2 parents da17a48 + 601f026 commit 9811bac
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 9811bac

Please sign in to comment.