Skip to content

Commit

Permalink
add test for Go to CI
Browse files Browse the repository at this point in the history
Signed-off-by: tenzen-y <yuki.iwai.tz@gmail.com>
  • Loading branch information
tenzen-y committed Oct 7, 2021
1 parent abfecef commit ed99fe8
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 112 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/test-go.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Go Test

on:
- push
- pull_request

jobs:
test:
name: Test
runs-on: ubuntu-latest
env:
GOPATH: ${{ github.workspace }}/go
defaults:
run:
working-directory: ${{ env.GOPATH }}/src/github.com/kubeflow/training-operator

steps:
- name: Check out code
uses: actions/checkout@v2
with:
path: ${{ env.GOPATH }}/src/github.com/kubeflow/training-operator

- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.14

- name: Check Go modules
run: |
go mod tidy && git add go.*
git diff --cached --exit-code || (echo "Please run "go mod tidy" to sync Go modules" && exit1);
- name: Check manifests
run: |
make manifests && git add manifests/base/crds
git diff --cached --exit-code || (echo "Please run "make manifests" to generate manifests" && exit1);
- name: Check auto-generated codes
run: |
make generate && git add pkg/apis
git diff --cached --exit-code || (echo "Please run "make generate" to generate Go codes" && exit1);
- name: Verify gofmt
run: |
make fmt && git add pkg cmd
git diff --cached --exit-code || (echo "Please run "make fmt" to verify gofmt" && exit1);
- name: Verify govet
run: |
make vet && git add pkg cmd
git diff --cached --exit-code || (echo "Please run "make vet" to verify govet" && exit1);
- name: Run Go test
run: make test
- name: Coveralls report
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: coverage.out
working-directory: ${{ env.GOPATH }}/src/github.com/kubeflow/training-operator
31 changes: 0 additions & 31 deletions .travis.yml

This file was deleted.

10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,16 @@ fmt: ## Run go fmt against code.
vet: ## Run go vet against code.
go vet ./...

GOLANGCI_LINT=$(shell which golangci-lint)
golangci-lint:
ifeq ($(GOLANGCI_LINT),)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.42.1
$(info golangci-lint has been installed)
endif
golangci-lint run --timeout 5m ./...

ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
test: manifests generate fmt vet ## Run tests.
test: manifests generate fmt vet golangci-lint ## Run tests.
mkdir -p ${ENVTEST_ASSETS_DIR}
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.2/hack/setup-envtest.sh
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ require (
github.com/go-logr/logr v0.3.0
github.com/go-openapi/spec v0.20.3
github.com/kubeflow/common v0.3.7
github.com/onrik/logrus v0.2.2-0.20181225141908-a09d5cdcdc62
github.com/onsi/ginkgo v1.14.1
github.com/onsi/gomega v1.10.2
github.com/prometheus/client_golang v1.10.0
github.com/sirupsen/logrus v1.6.0
k8s.io/api v0.19.9
k8s.io/apiextensions-apiserver v0.19.9
k8s.io/apiextensions-apiserver v0.19.9 // indirect
k8s.io/apimachinery v0.19.9
k8s.io/client-go v0.19.9
k8s.io/code-generator v0.19.9
Expand Down
Loading

0 comments on commit ed99fe8

Please sign in to comment.