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..a29f85c 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 @@ -36,12 +40,20 @@ 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: 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 .