diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 36ad7b47f..8773306ad 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -5,7 +5,71 @@ on: [pull_request] jobs: - build: + cover: + runs-on: ubuntu-latest + steps: + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.17 + + # Get values for cache paths to be used in later steps + - id: go-cache-paths + run: | + echo "::set-output name=go-build::$(go env GOCACHE)" + echo "::set-output name=go-mod::$(go env GOMODCACHE)" + + - name: Checkout + uses: actions/checkout@v2 + + # Cache go build cache, used to speedup go test + - name: Go Build Cache + uses: actions/cache@v2 + with: + path: ${{ steps.go-cache-paths.outputs.go-build }} + key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} + + # Cache go mod cache, used to speedup builds + - name: Go Mod Cache + uses: actions/cache@v2 + with: + path: ${{ steps.go-cache-paths.outputs.go-mod }} + key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }} + + - name: Go Lint Cache + uses: actions/cache@v2 + with: + path: | + ~/.cache/golangci-lint + key: ${{ runner.os }}-go-lint-${{ hashFiles('**/go.sum') }} + + - name: Generate + run: make generate + + - name: Fmt + run: make fmt + + - name: Vet + run: make vet + + - name: Cover + run: go test -coverprofile coverage.out -covermode=atomic ./... -v + + - name: Convert cover report + run: | + go tool cover -o coverage.html -html=coverage.out + sed -i 's/black/whitesmoke/g' coverage.html + + - name: Upload a Build Artifact + uses: actions/upload-artifact@v3.0.0 + with: + # Artifact name + name: coverage.html # optional, default is artifact + # A file, directory or wildcard pattern that describes what to upload + path: coverage.html + retention-days: 5 + + craned: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -15,5 +79,111 @@ jobs: with: go-version: 1.17 - - name: Build - run: make all \ No newline at end of file + # Get values for cache paths to be used in later steps + - id: go-cache-paths + run: | + echo "::set-output name=go-build::$(go env GOCACHE)" + echo "::set-output name=go-mod::$(go env GOMODCACHE)" + + # Cache go build cache, used to speedup go test + - name: Go Build Cache + uses: actions/cache@v2 + with: + path: ${{ steps.go-cache-paths.outputs.go-build }} + key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} + + # Cache go mod cache, used to speedup builds + - name: Go Mod Cache + uses: actions/cache@v2 + with: + path: ${{ steps.go-cache-paths.outputs.go-mod }} + key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }} + + - name: Build Craned + run: make craned + + crane-agent: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.17 + + # Get values for cache paths to be used in later steps + - id: go-cache-paths + run: | + echo "::set-output name=go-build::$(go env GOCACHE)" + echo "::set-output name=go-mod::$(go env GOMODCACHE)" + + # Cache go build cache, used to speedup go test + - name: Go Build Cache + uses: actions/cache@v2 + with: + path: ${{ steps.go-cache-paths.outputs.go-build }} + key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} + + # Cache go mod cache, used to speedup builds + - name: Go Mod Cache + uses: actions/cache@v2 + with: + path: ${{ steps.go-cache-paths.outputs.go-mod }} + key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }} + + - name: Build Crane Agent + run: make crane-agent + + metric-adapter: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.17 + + # Get values for cache paths to be used in later steps + - id: go-cache-paths + run: | + echo "::set-output name=go-build::$(go env GOCACHE)" + echo "::set-output name=go-mod::$(go env GOMODCACHE)" + + # Cache go build cache, used to speedup go test + - name: Go Build Cache + uses: actions/cache@v2 + with: + path: ${{ steps.go-cache-paths.outputs.go-build }} + key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} + + # Cache go mod cache, used to speedup builds + - name: Go Mod Cache + uses: actions/cache@v2 + with: + path: ${{ steps.go-cache-paths.outputs.go-mod }} + key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }} + + - name: Build Metric Adapter + run: make metric-adapter + + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup Go environment + uses: actions/setup-go@v3.0.0 + with: + # The Go version to download (if necessary) and use. Supports semver spec and ranges. + go-version: 1.17 # optional + + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version + version: v1.45.2 + + # Optional: golangci-lint command line arguments. + args: --timeout 30m --disable-all -E deadcode -E unused -E varcheck -E ineffassign -E goimports -E gofmt -E misspell -E unparam -E unconvert -E govet -E errcheck -E structcheck