From ae44bceb4a63bcd635897a63ee289dc27227bd0e Mon Sep 17 00:00:00 2001 From: secustor Date: Wed, 16 Jun 2021 18:05:53 +0200 Subject: [PATCH 1/2] ci: add tests on all branches and release workflow --- .github/workflows/go.yml | 40 ++++++++++++++++++++++++++++ .github/workflows/release.yml | 49 +++++++++++++++++++++++++++++++++++ .releaserc.yml | 7 +++++ Makefile | 14 +++++++++- 4 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/go.yml create mode 100644 .github/workflows/release.yml create mode 100644 .releaserc.yml diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..1c44413 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,40 @@ +name: Go + +on: + push: + branches: + - '**' + - '!master' + pull_request: + branches: [ master ] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: ^1.16 + id: go + - name: Get dependencies + run: make get-dependencies + + - name: Ensure that all files are properly formatted + run: | + FILES=$(gofmt -s -l .) + if [ -n "${FILES}" ]; then + printf "Following files are not formatted: \n%s" "$FILES" + exit 1 + fi + + - name: GO vet + run: make vet + + - name: Test + run: make unit-test + + - name: Test building + run: make build diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..15b80cb --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,49 @@ +name: Release + +on: workflow_dispatch + +jobs: + release: + name: 'Release to GitHub' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 +# Go setup + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: ^1.16 + id: go + + - name: Get dependencies + run: make get-dependencies + +# Go test + - name: Ensure that all files are properly formatted + run: | + FILES=$(gofmt -s -l .) + if [ -n "${FILES}" ]; then + printf "Following files are not formatted: \n%s" "$FILES" + exit 1 + fi + + - name: GO vet + run: make vet + + - name: Test + run: make test + + - name: Test building + run: make build + +# Prepare release + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: 13 + - name: Add execution plugin + run: npm install @semantic-release/exec + - name: Release to GitHub + env: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} + run: npx semantic-release diff --git a/.releaserc.yml b/.releaserc.yml new file mode 100644 index 0000000..ae7fab1 --- /dev/null +++ b/.releaserc.yml @@ -0,0 +1,7 @@ +--- +branches: + - master +plugins: + - "@semantic-release/commit-analyzer" + - "@semantic-release/release-notes-generator" + - - "@semantic-release/github" diff --git a/Makefile b/Makefile index db90b60..64766b2 100644 --- a/Makefile +++ b/Makefile @@ -22,9 +22,13 @@ KUBEBUILDER_VERSION=2.3.1 TEST_ZONE_NAME ?= example.com. # Run tests -test: tests/kubebuilder +test: unit-test tests/kubebuilder TEST_ZONE_NAME=$(TEST_ZONE_NAME) go test -v ./... -coverprofile cover.out +.PHONY: unit-test +unit-test: + go test -v -race ./pkg/... + tests/kubebuilder: curl -fsSL https://github.com/kubernetes-sigs/kubebuilder/releases/download/v$(KUBEBUILDER_VERSION)/kubebuilder_$(KUBEBUILDER_VERSION)_$(OS)_$(ARCH).tar.gz -o kubebuilder-tools.tar.gz mkdir tests/kubebuilder @@ -42,6 +46,14 @@ compile: docker-build: docker build . --platform=$(OS)/$(ARCH) -t $(FULL_IMAGE):$(IMAGE_TAG)-$(ARCH) +.PHONY: get-dependencies +get-dependencies: + go get -v -t -d ./... + +.PHONY: vet +vet: + go vet ./... + .PHONY: fmt-fix fmt-fix: gofmt -s -w . From 991ed2d040e3852cf411eefc33b6230f9dd7c2b5 Mon Sep 17 00:00:00 2001 From: secustor Date: Thu, 17 Jun 2021 09:41:44 +0200 Subject: [PATCH 2/2] ci: rename make compile to make build --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 64766b2..a29f85c 100644 --- a/Makefile +++ b/Makefile @@ -40,7 +40,7 @@ tests/kubebuilder: clean-kubebuilder: rm -Rf tests/kubebuilder -compile: +build: CGO_ENABLED=0 go build -v -o target/cert-manager-webhook-pinto main.go docker-build: