From 6a0bae85f31749e4f9d6c8887b0b6dfc81ab3a40 Mon Sep 17 00:00:00 2001 From: Jerad C Date: Thu, 7 Apr 2022 11:12:42 -0500 Subject: [PATCH 1/2] add workflow to run test suite * add ginkgo to toolchain --- .github/workflows/ci.yml | 252 ------------------------------------ .github/workflows/tests.yml | 40 ++++++ src/Makefile | 8 +- src/scripts/toolchain.sh | 1 + 4 files changed, 46 insertions(+), 255 deletions(-) delete mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index efeb8370..00000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,252 +0,0 @@ -name: NTH Continuous Integration and Release - -on: - pull_request: - branches: - - main - push: - branches: - - main - workflow_dispatch: - -env: - DEFAULT_GO_VERSION: ^1.16 - GITHUB_USERNAME: ${{ secrets.EC2_BOT_GITHUB_USERNAME }} - GITHUB_TOKEN: ${{ secrets.EC2_BOT_GITHUB_TOKEN }} - WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }} - -jobs: - - fastTests: - name: Fast Tests and Lints - runs-on: ubuntu-20.04 - if: ${{ !contains(github.ref, 'refs/tags/') }} - steps: - - name: Set up Go 1.x - uses: actions/setup-go@v2 - with: - go-version: ${{ env.DEFAULT_GO_VERSION }} - - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - - name: Restore go mod cache - uses: actions/cache@v2 - with: - path: | - ~/.cache/go-build - ~/go/pkg/mod - ~/go/bin/ - key: gocache - - - name: Unit Tests - run: make unit-test - - - name: Lints - run: make spellcheck shellcheck helm-lint - - - name: License Check - run: make license-test - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Run golangci-lint - uses: golangci/golangci-lint-action@v2.5.2 - - - name: Generate K8s YAML - run: make generate-k8s-yaml - - buildLinux: - name: Build Linux Binaries - runs-on: ubuntu-20.04 - if: ${{ !contains(github.ref, 'refs/tags/') }} - steps: - - name: Set up Go 1.x - uses: actions/setup-go@v2 - with: - go-version: ${{ env.DEFAULT_GO_VERSION }} - - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - - name: Restore go mod cache - uses: actions/cache@v2 - with: - path: | - ~/.cache/go-build - ~/go/pkg/mod - ~/go/bin/ - key: gocache - - - name: Build Linux Binaries - run: make build-binaries - - buildLinuxDocker: - name: Build Linux Docker Images - runs-on: ubuntu-20.04 - if: ${{ !contains(github.ref, 'refs/tags/') }} - steps: - - name: Set up Go 1.x - uses: actions/setup-go@v2 - with: - go-version: ${{ env.DEFAULT_GO_VERSION }} - - - name: Restore go mod cache - uses: actions/cache@v2 - with: - path: | - ~/.cache/go-build - ~/go/pkg/mod - ~/go/bin/ - key: gocache - - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - - name: Build Linux Docker Images - run: make build-docker-images - - buildWindows: - name: Build Windows Binaries - runs-on: windows-2019 - if: ${{ !contains(github.ref, 'refs/tags/') }} - steps: - - name: Set up Go 1.x - uses: actions/setup-go@v2 - with: - go-version: ${{ env.DEFAULT_GO_VERSION }} - - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - - name: Restore go mod cache - uses: actions/cache@v2 - with: - path: | - ~/.cache/go-build - ~/go/pkg/mod - ~/go/bin/ - key: gocache - - - name: Build Windows Binaries - run: choco install make && choco install zip && RefreshEnv.cmd && make build-binaries-windows - - buildWindowsDocker: - name: Build Windows Docker Images - runs-on: windows-2019 - if: ${{ !contains(github.ref, 'refs/tags/') }} - steps: - - name: Set up Go 1.x - uses: actions/setup-go@v2 - with: - go-version: ${{ env.DEFAULT_GO_VERSION }} - - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - - name: Restore go mod cache - uses: actions/cache@v2 - with: - path: | - ~/.cache/go-build - ~/go/pkg/mod - ~/go/bin/ - key: gocache - - - name: Build Windows Docker Images - run: choco install make && RefreshEnv.cmd && make build-docker-images-windows - - e2e: - name: E2E Tests - runs-on: ubuntu-20.04 - if: ${{ !contains(github.ref, 'refs/tags/') }} - strategy: - matrix: - k8sVersion: ["1.17", "1.18", "1.19", "1.20", "1.21", "1.22"] - steps: - - name: Set up Go 1.x - uses: actions/setup-go@v2 - with: - go-version: ${{ env.DEFAULT_GO_VERSION }} - - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - - name: Restore go mod cache - uses: actions/cache@v2 - with: - path: | - ~/.cache/go-build - ~/go/pkg/mod - ~/go/bin/ - key: gocache - - - name: E2E Tests - run: test/k8s-local-cluster-test/run-test -v ${{ matrix.k8sVersion }} - - releaseLinux: - name: Release Linux - runs-on: ubuntu-20.04 - if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') - steps: - - name: Set up Go 1.x - uses: actions/setup-go@v2 - with: - go-version: ${{ env.DEFAULT_GO_VERSION }} - - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - - name: Release Linux Assets - run: make release - env: - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - AWS_SESSION_TOKEN: ${{ secrets.AWS_SESSION_TOKEN }} - - releaseWindows: - name: Release Windows - runs-on: windows-2019 - if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') - steps: - - name: Set up Go 1.x - uses: actions/setup-go@v2 - with: - go-version: ${{ env.DEFAULT_GO_VERSION }} - - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - - name: Release Windows Assets - run: choco install make && choco install zip && RefreshEnv.cmd && make release-windows - env: - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - AWS_SESSION_TOKEN: ${{ secrets.AWS_SESSION_TOKEN }} - - release: - name: Release - runs-on: ubuntu-20.04 - needs: [releaseLinux, releaseWindows] - if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') - steps: - - name: Set up Go 1.x - uses: actions/setup-go@v2 - with: - go-version: ${{ env.DEFAULT_GO_VERSION }} - - - name: Check out code into the Go module directory - uses: actions/checkout@v2 - - - name: Create eks-charts PR - run: make ekscharts-sync-release - - - name: Sync Readme to ECR Public - run: make sync-readme-to-ecr-public - env: - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - AWS_SESSION_TOKEN: ${{ secrets.AWS_SESSION_TOKEN }} - - - name: Create NTH README Update PR - run: make create-release-prep-pr-readme diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..d29f80ac --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,40 @@ +name: Tests + +on: + pull_request: + branches: + - v2 + push: + branches: + - v2 + workflow_dispatch: + +jobs: + + runMakeTest: + name: Run 'make test' + runs-on: ubuntu-20.04 + steps: + - name: Set up Go 1.17.x + uses: actions/setup-go@v3 + with: + go-version: "1.17.x" + - run: go version + + - name: Check out code into the Go module directory + uses: actions/checkout@v3 + with: + ref: v2 + + - name: Restore go mod cache + uses: actions/cache@v3 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + ~/go/bin/ + key: gocache + + - name: make test + run: make test + working-directory: ./src diff --git a/src/Makefile b/src/Makefile index 3d2abb79..ac41dde3 100644 --- a/src/Makefile +++ b/src/Makefile @@ -2,10 +2,12 @@ PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) CONTROLLER_GEN = $(PROJECT_DIR)/bin/controller-gen KO = $(PROJECT_DIR)/bin/ko ENVTEST = $(PROJECT_DIR)/bin/setup-envtest +GINKGO = $(PROJECT_DIR)/bin/ginkgo TOOLCHAIN = \ $(CONTROLLER_GEN) \ $(KO) \ - $(ENVTEST) + $(ENVTEST) \ + $(GINKGO) HELM_BASE_OPTS ?= --set serviceAccount.annotations.eks\\.amazonaws\\.com/role-arn=${NTHV2_IAM_ROLE_ARN} GINKGO_BASE_OPTS ?= --coverpkg $(shell head -n 1 $(PROJECT_DIR)/go.mod | cut -s -d ' ' -f 2)/pkg/... KODATA = \ @@ -64,9 +66,9 @@ verify: ## Run go fmt and go vet against code. go vet $(PROJECT_DIR)/... .PHONY: test -test: ## Run tests. +test: $(GINKGO) ## Run tests. go vet $(PROJECT_DIR)/... - ginkgo run $(GINKGO_BASE_OPTS) $(GINKGO_OPTS) $(PROJECT_DIR)/test/ + $(GINKGO) run $(GINKGO_BASE_OPTS) $(GINKGO_OPTS) $(PROJECT_DIR)/test/ ##@ Build diff --git a/src/scripts/toolchain.sh b/src/scripts/toolchain.sh index 7466439d..85265c1f 100755 --- a/src/scripts/toolchain.sh +++ b/src/scripts/toolchain.sh @@ -23,6 +23,7 @@ tools=( # setup-envtest version specifiers: # https://pkg.go.dev/sigs.k8s.io/controller-runtime/tools/setup-envtest/versions?tab=versions "sigs.k8s.io/controller-runtime/tools/setup-envtest@v0.0.0-20220217150738-f62a0f579d73" + "github.com/onsi/ginkgo/v2/ginkgo@v2.1.3" ) bin_dir="" From 7d74b5e6ac3c18720e40f84d4375d3ade819d772 Mon Sep 17 00:00:00 2001 From: Jerad C Date: Fri, 15 Apr 2022 13:56:31 -0500 Subject: [PATCH 2/2] remove checkout branch reference --- .github/workflows/tests.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d29f80ac..0f122d75 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -23,8 +23,6 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@v3 - with: - ref: v2 - name: Restore go mod cache uses: actions/cache@v3