From 101e2c554b3d83776428e81822dc4446902cc349 Mon Sep 17 00:00:00 2001 From: Kwitsch Date: Tue, 7 Feb 2023 14:00:53 +0100 Subject: [PATCH] Workflow changes (#857) * fix linter errors * fix for flaky redis unit test * timeout adjustment * e2e-test -> ci-build * setup docker buildx * added concurrency cancelation * changed job name * Test comment out problematic eventually * added comment * workflow file rename * workflow name changed * skip go generate * added make generate * removed unused go generate * setup golang with caches if needed * matrix revamp * activate gofor e2e * fix matrix * test * eventually timing * removed linter workflow in favor of make matrix * expect -> Eventually * renamed workflow --- .github/workflows/ci-build.yml | 35 -------------- .github/workflows/e2e-tests.yml | 27 ----------- .github/workflows/golangci-lint.yml | 20 -------- .github/workflows/makefile.yml | 73 +++++++++++++++++++++++++++++ Makefile | 9 ++-- e2e/blocking_test.go | 2 +- e2e/metrics_test.go | 3 +- e2e/redis_test.go | 10 ++-- redis/redis_test.go | 3 ++ resolver/resolver.go | 1 - 10 files changed, 89 insertions(+), 94 deletions(-) delete mode 100644 .github/workflows/ci-build.yml delete mode 100644 .github/workflows/e2e-tests.yml delete mode 100644 .github/workflows/golangci-lint.yml create mode 100644 .github/workflows/makefile.yml diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml deleted file mode 100644 index 85967e21e..000000000 --- a/.github/workflows/ci-build.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: CI Build -on: [push, pull_request] -jobs: - make: - name: Test - runs-on: ubuntu-latest - strategy: - matrix: - make: [build, test, race, docker-build, goreleaser] - steps: - - name: Check out code into the Go module directory - uses: actions/checkout@v3 - - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version-file: go.mod - id: go - - - name: Get dependencies - run: go mod download - - - name: make ${{ matrix.make }} - run: make ${{ matrix.make }} - if: matrix.make != 'goreleaser' - - - name: Upload results to codecov - uses: codecov/codecov-action@v3 - if: matrix.make == 'test' - - - name: Check GoReleaser configuration - uses: goreleaser/goreleaser-action@v4 - if: matrix.make == 'goreleaser' - with: - args: check diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml deleted file mode 100644 index c9aaab025..000000000 --- a/.github/workflows/e2e-tests.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Run e2e tests - -on: - push: - pull_request: - -jobs: - e2e-test: - name: Build Docker image - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version-file: go.mod - id: go - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Run e2e - run: make e2e-test \ No newline at end of file diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml deleted file mode 100644 index a67e7304c..000000000 --- a/.github/workflows/golangci-lint.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: golangci-lint -on: - push: - pull_request: -permissions: - contents: read -jobs: - golangci: - name: lint - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - uses: actions/setup-go@v3 - with: - go-version-file: go.mod - - uses: actions/checkout@v3 - - - name: golangci-lint - run: make lint \ No newline at end of file diff --git a/.github/workflows/makefile.yml b/.github/workflows/makefile.yml new file mode 100644 index 000000000..4dc076da0 --- /dev/null +++ b/.github/workflows/makefile.yml @@ -0,0 +1,73 @@ +name: Makefile + +on: + push: + pull_request: + +permissions: + security-events: write + actions: read + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + make: + name: make + runs-on: ubuntu-latest + strategy: + matrix: + include: + - make: build + go: true + docker: false + - make: test + go: true + docker: false + - make: race + go: true + docker: false + - make: docker-build + go: false + docker: true + - make: e2e-test + go: true + docker: true + - make: goreleaser + go: false + docker: false + - make: lint + go: true + docker: false + + steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v3 + + - name: Setup Golang with cache + uses: magnetikonline/action-golang-cache@v3 + if: matrix.go == true + with: + go-version-file: go.mod + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + if: matrix.docker == true + + - name: make ${{ matrix.make }} + run: make ${{ matrix.make }} + if: matrix.make != 'goreleaser' + env: + GO_SKIP_GENERATE: 1 + + - name: Upload results to codecov + uses: codecov/codecov-action@v3 + if: matrix.make == 'test' + + - name: Check GoReleaser configuration + uses: goreleaser/goreleaser-action@v4 + if: matrix.make == 'goreleaser' + with: + args: check diff --git a/Makefile b/Makefile index 0442e93c2..05ef7d257 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: all clean build swagger test e2e-test lint run fmt docker-build help +.PHONY: all clean generate build swagger test e2e-test lint run fmt docker-build help .DEFAULT_GOAL:=help VERSION?=$(shell git describe --always --tags) @@ -41,12 +41,14 @@ serve_docs: ## serves online docs pip install mkdocs-material mkdocs serve -build: ## Build binary +generate: ## Go generate ifdef GO_SKIP_GENERATE $(info skipping go generate) else go generate ./... endif + +build: generate ## Build binary go build $(GO_BUILD_FLAGS) -ldflags="$(GO_BUILD_LD_FLAGS)" -o $(GO_BUILD_OUTPUT) ifdef BIN_USER $(info setting owner of $(GO_BUILD_OUTPUT) to $(BIN_USER)) @@ -82,8 +84,7 @@ fmt: ## gofmt and goimports all go files go run mvdan.cc/gofumpt -l -w -extra . find . -name '*.go' -exec goimports -w {} + -docker-build: ## Build docker image - go generate ./... +docker-build: generate ## Build docker image docker buildx build \ --build-arg VERSION=${VERSION} \ --build-arg BUILD_TIME=${BUILD_TIME} \ diff --git a/e2e/blocking_test.go b/e2e/blocking_test.go index e1e7e8949..f710fc663 100644 --- a/e2e/blocking_test.go +++ b/e2e/blocking_test.go @@ -77,7 +77,7 @@ var _ = Describe("External lists and query blocking", func() { }) It("should fail to start", func() { - Eventually(blocky.IsRunning, "30s").Should(BeFalse()) + Eventually(blocky.IsRunning, "5s", "2ms").Should(BeFalse()) Expect(getContainerLogs(blocky)). Should(ContainElement(ContainSubstring("Error: can't start server: 1 error occurred"))) diff --git a/e2e/metrics_test.go b/e2e/metrics_test.go index 79b185a7c..a5f2631ae 100644 --- a/e2e/metrics_test.go +++ b/e2e/metrics_test.go @@ -67,7 +67,8 @@ var _ = Describe("Metrics functional tests", func() { }) It("Should provide 'blocky_blocking_enabled' prometheus metrics", func() { - Eventually(fetchBlockyMetrics).WithArguments(metricsURL).Should(ContainElement("blocky_blocking_enabled 1")) + Eventually(fetchBlockyMetrics, "30s", "2ms").WithArguments(metricsURL). + Should(ContainElement("blocky_blocking_enabled 1")) }) }) diff --git a/e2e/redis_test.go b/e2e/redis_test.go index 81b59b27f..0aaa58f38 100644 --- a/e2e/redis_test.go +++ b/e2e/redis_test.go @@ -72,7 +72,7 @@ var _ = Describe("Redis configuration tests", func() { It("2nd instance of blocky should use cache from redis", func() { msg := util.NewMsgWithQuestion("google.de.", A) By("Query first blocky instance, should store cache in redis", func() { - Expect(doDNSRequest(blocky1, msg)). + Eventually(doDNSRequest, "5s", "2ms").WithArguments(blocky1, msg). Should( SatisfyAll( BeDNSRecord("google.de.", A, "1.2.3.4"), @@ -81,7 +81,7 @@ var _ = Describe("Redis configuration tests", func() { }) By("Check redis, must contain one cache entry", func() { - Eventually(dbSize).WithArguments(redisClient).Should(BeNumerically("==", 1)) + Eventually(dbSize, "5s", "2ms").WithArguments(redisClient).Should(BeNumerically("==", 1)) }) By("Shutdown the upstream DNS server", func() { @@ -89,7 +89,7 @@ var _ = Describe("Redis configuration tests", func() { }) By("Query second blocky instance, should use cache from redis", func() { - Expect(doDNSRequest(blocky2, msg)). + Eventually(doDNSRequest, "5s", "2ms").WithArguments(blocky2, msg). Should( SatisfyAll( BeDNSRecord("google.de.", A, "1.2.3.4"), @@ -124,7 +124,7 @@ var _ = Describe("Redis configuration tests", func() { It("should load cache from redis after start", func() { msg := util.NewMsgWithQuestion("google.de.", A) By("Query first blocky instance, should store cache in redis\"", func() { - Expect(doDNSRequest(blocky1, msg)). + Eventually(doDNSRequest, "5s", "2ms").WithArguments(blocky1, msg). Should( SatisfyAll( BeDNSRecord("google.de.", A, "1.2.3.4"), @@ -156,7 +156,7 @@ var _ = Describe("Redis configuration tests", func() { }) By("Query second blocky instance", func() { - Expect(doDNSRequest(blocky2, msg)). + Eventually(doDNSRequest, "5s", "2ms").WithArguments(blocky2, msg). Should( SatisfyAll( BeDNSRecord("google.de.", A, "1.2.3.4"), diff --git a/redis/redis_test.go b/redis/redis_test.go index 7d054c623..9ddf6185d 100644 --- a/redis/redis_test.go +++ b/redis/redis_test.go @@ -2,6 +2,7 @@ package redis import ( "encoding/json" + "time" "github.com/0xERR0R/blocky/config" "github.com/0xERR0R/blocky/util" @@ -255,6 +256,8 @@ var _ = Describe("Redis client", func() { rec := redisServer.Publish(SyncChannelName, string(binMsg)) Expect(rec).Should(Equal(1)) + time.Sleep(2 * time.Second) + Eventually(func() chan *EnabledMessage { return redisClient.EnabledChannel }).Should(HaveLen(lenE)) diff --git a/resolver/resolver.go b/resolver/resolver.go index f3f58cb8f..786e472f4 100644 --- a/resolver/resolver.go +++ b/resolver/resolver.go @@ -1,4 +1,3 @@ -//go:generate go run github.com/abice/go-enum -f=$GOFILE --marshal --names package resolver import (