From 66d151989267e2d052c44bd9a16e112e713aa581 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Mon, 13 Jun 2022 23:38:52 +0200 Subject: [PATCH 1/3] container based dev flow --- .github/workflows/test.yml | 36 +++++++++++++-------------- Dockerfile | 51 ++++++++++++++++++++++++++++++++++++++ docker-bake.hcl | 41 ++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 18 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-bake.hcl diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2146023..3deceb7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,14 +9,24 @@ on: pull_request: jobs: + validate: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v3 + - + name: Run + uses: docker/bake-action@v2 + with: + targets: validate + test: runs-on: ubuntu-latest - env: - GO111MODULE: on strategy: fail-fast: false matrix: - go: + go_version: - 1.13 - 1.14 - 1.15 @@ -27,23 +37,13 @@ jobs: - name: Checkout uses: actions/checkout@v3 - - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version: ${{ matrix.go }} - - - name: Cache Go modules - uses: actions/cache@v3 - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go-${{ matrix.go }}- - name: Test - run: | - go test -coverprofile=coverage.txt -covermode=atomic ./... + uses: docker/bake-action@v2 + with: + targets: test + env: + GO_VERSION: ${{ matrix.go_version }} - name: Upload coverage uses: codecov/codecov-action@v3 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..da064b1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,51 @@ +# syntax=docker/dockerfile:1 + +ARG GO_VERSION="1.18" +ARG GOLANGCI_LINT_VERSION="v1.45" + +FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS golangci-lint + +FROM golang:${GO_VERSION}-alpine AS base +RUN apk add --no-cache gcc git linux-headers musl-dev +ENV CGO_ENABLED=0 +ENV GO111MODULE=on +WORKDIR /src + +FROM base AS vendored +RUN --mount=type=bind,target=.,rw \ + --mount=type=cache,target=/go/pkg/mod \ + go mod tidy && go mod download && \ + mkdir /out && cp go.mod go.sum /out + +FROM scratch AS vendor-update +COPY --from=vendored /out / + +FROM vendored AS vendor-validate +RUN --mount=type=bind,target=.,rw <&2 'ERROR: Vendor result differs. Please vendor your package with "docker buildx bake vendor"' + echo "$diff" + exit 1 +fi +EOT + +FROM base AS lint +RUN --mount=type=bind,target=. \ + --mount=type=cache,target=/root/.cache \ + --mount=from=golangci-lint,source=/usr/bin/golangci-lint,target=/usr/bin/golangci-lint \ + golangci-lint run ./... + +FROM vendored AS test +ENV CGO_ENABLED=1 +RUN --mount=type=bind,target=. \ + --mount=type=cache,target=/root/.cache \ + --mount=type=cache,target=/go/pkg/mod \ + go test -v -coverprofile=/tmp/coverage.txt -covermode=atomic -race ./... && \ + go tool cover -func=/tmp/coverage.txt + +FROM scratch AS test-coverage +COPY --from=test /tmp/coverage.txt /coverage.txt diff --git a/docker-bake.hcl b/docker-bake.hcl new file mode 100644 index 0000000..3e1c4ed --- /dev/null +++ b/docker-bake.hcl @@ -0,0 +1,41 @@ +variable "GO_VERSION" { + default = "1.18" +} + +target "_common" { + args = { + GO_VERSION = GO_VERSION + } +} + +group "default" { + targets = ["test"] +} + +group "validate" { + targets = ["lint", "vendor-validate"] +} + +target "lint" { + inherits = ["_common"] + target = "lint" + output = ["type=cacheonly"] +} + +target "vendor-validate" { + inherits = ["_common"] + target = "vendor-validate" + output = ["type=cacheonly"] +} + +target "vendor-update" { + inherits = ["_common"] + target = "vendor-update" + output = ["."] +} + +target "test" { + inherits = ["_common"] + target = "test-coverage" + output = ["."] +} From b9dd88a09195177050f19670ad15cff19244c3b6 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Mon, 13 Jun 2022 23:41:47 +0200 Subject: [PATCH 2/3] fix lint --- loader_flag.go | 1 + 1 file changed, 1 insertion(+) diff --git a/loader_flag.go b/loader_flag.go index 1a7b6f6..6761503 100644 --- a/loader_flag.go +++ b/loader_flag.go @@ -7,6 +7,7 @@ import ( // FlagLoader is the structure representring a flag loader. type FlagLoader struct { + //nolint:structcheck,unused filename string cfg FlagLoaderConfig } From 25700dce17a61d9d087fca07c3eb7508bfa9535a Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Mon, 13 Jun 2022 23:43:32 +0200 Subject: [PATCH 3/3] remove go 1.13 and 1.14 support --- .github/workflows/test.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3deceb7..da25bd2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,8 +27,6 @@ jobs: fail-fast: false matrix: go_version: - - 1.13 - - 1.14 - 1.15 - 1.16 - 1.17