Skip to content

Commit eb645f7

Browse files
committed
initial commit
0 parents  commit eb645f7

File tree

16 files changed

+1466
-0
lines changed

16 files changed

+1466
-0
lines changed

.github/workflows/lint.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: lint
2+
on: [push]
3+
jobs:
4+
lint:
5+
name: lint
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: checkout
9+
uses: actions/checkout@v3
10+
- name: setup go
11+
uses: actions/setup-go@v3
12+
with:
13+
go-version-file: go.mod
14+
- name: golangci-lint
15+
uses: golangci/golangci-lint-action@v3
16+
with:
17+
version: v1.51.2
18+
- name: go mod tidy check
19+
uses: katexochen/go-tidy-check@v2

.github/workflows/release.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: release
2+
on:
3+
push:
4+
tags:
5+
- "v[0-9]+\\.[0-9]+\\.[0-9]+"
6+
7+
jobs:
8+
release:
9+
permissions:
10+
contents: write
11+
packages: write
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- uses: actions/setup-go@v3
17+
with:
18+
go-version-file: go.mod
19+
20+
- name: Set RELEASE_VERSION ENV var
21+
run: echo "RELEASE_VERSION=${GITHUB_REF:10}" >> $GITHUB_ENV
22+
23+
- name: Ensure container version is updated to release version
24+
run: |
25+
image=$(yq '.runs.image' action.yml)
26+
echo "Image: $image"
27+
imageVer=${image:(-6)}
28+
echo "Image version: $imageVer, Release version: ${{ env.RELEASE_VERSION }}"
29+
[[ "$imageVer" == "${{ env.RELEASE_VERSION }}" ]]
30+
31+
- name: Install gox
32+
run: go install github.com/mitchellh/gox@v1.0.1
33+
34+
- name: Build cross-platform binaries
35+
env:
36+
PLATFORMS: darwin/amd64 darwin/arm64 windows/amd64 linux/amd64 linux/arm64
37+
OUTPUT_PATH_FORMAT: ./bin/${{ env.RELEASE_VERSION }}/{{.OS}}/{{.Arch}}/go-test-coverage
38+
run: |
39+
gox -osarch="${PLATFORMS}" -ldflags "-X main.Version=${RELEASE_VERSION}" -output "${OUTPUT_PATH_FORMAT}"
40+
41+
- name: Update the major version tag
42+
id: majorver
43+
uses: actions/publish-action@v0.1.0
44+
with:
45+
source-tag: ${{ env.RELEASE_VERSION }}
46+
47+
- name: Setup buildx
48+
uses: docker/setup-buildx-action@v1
49+
50+
- name: Login to GitHub container registry
51+
uses: docker/login-action@v1
52+
with:
53+
registry: ghcr.io
54+
username: ${{ github.repository_owner }}
55+
password: ${{ secrets.GITHUB_TOKEN }}
56+
57+
- name: Build and push
58+
uses: docker/build-push-action@v2
59+
with:
60+
push: true
61+
build-args: |
62+
VERSION=${{ env.RELEASE_VERSION }}
63+
tags: |
64+
ghcr.io/vladopajic/go-test-coverage:${{ env.RELEASE_VERSION }}
65+
ghcr.io/vladopajic/go-test-coverage:${{ steps.majorver.outputs.major-tag }}
66+
ghcr.io/vladopajic/go-test-coverage:latest

.github/workflows/test.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: test
2+
on: [push]
3+
jobs:
4+
test:
5+
name: test
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: checkout
9+
uses: actions/checkout@v3
10+
- name: setup go
11+
uses: actions/setup-go@v3
12+
with:
13+
go-version-file: go.mod
14+
- name: test
15+
run: go test -timeout=30s -race -count=10 -failfast ./...
16+
- name: test (report coverage)
17+
run: go test ./... -coverprofile=./cover.out -covermode=atomic
18+
- name: upload code coverage
19+
uses: codecov/codecov-action@v3.1.0
20+
if: contains(github.ref, 'main')
21+
with:
22+
file: ./cover.out

.golangci.yml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
run:
2+
deadline: 5m
3+
4+
linters:
5+
enable:
6+
# - exhaustivestruct (too exhaustive)
7+
# - gci
8+
# - godot (too nit picking)
9+
# - ireturn (we like when function returns interface)
10+
# - varnamelen (we can handle this in code review step)
11+
- asasalint
12+
- asciicheck
13+
- bidichk
14+
- bodyclose
15+
- containedctx
16+
- contextcheck
17+
- cyclop
18+
- depguard
19+
- dogsled
20+
- dupl
21+
- durationcheck
22+
- errcheck
23+
- errchkjson
24+
- errname
25+
- errorlint
26+
- exhaustive
27+
- exportloopref
28+
- forbidigo
29+
- forcetypeassert
30+
- funlen
31+
- gochecknoglobals
32+
- gochecknoinits
33+
- gocognit
34+
- goconst
35+
- gocritic
36+
- gocyclo
37+
- godox
38+
- goerr113
39+
- gofmt
40+
- gofumpt
41+
- goheader
42+
- goimports
43+
- gomnd
44+
- gomoddirectives
45+
- gomodguard
46+
- goprintffuncname
47+
- gosec
48+
- gosimple
49+
- govet
50+
- importas
51+
- ineffassign
52+
- lll
53+
- maintidx
54+
- makezero
55+
- misspell
56+
- nakedret
57+
- nestif
58+
- nilerr
59+
- nilnil
60+
- nlreturn
61+
- noctx
62+
- nolintlint
63+
- nonamedreturns
64+
- paralleltest
65+
- prealloc
66+
- predeclared
67+
- promlinter
68+
- reassign
69+
- revive
70+
- staticcheck
71+
- stylecheck
72+
- tagliatelle
73+
- tenv
74+
- testpackage
75+
- thelper
76+
- tparallel
77+
- typecheck
78+
- unconvert
79+
- unparam
80+
- unused
81+
- whitespace
82+
- wrapcheck
83+
- wsl
84+
85+
linters-settings:
86+
nolintlint:
87+
require-explanation: true
88+
maintidx:
89+
under: 40
90+
misspell:
91+
locale: US
92+
govet:
93+
check-shadowing: true
94+
enable-all: true
95+
lll:
96+
line-length: 96
97+
tab-width: 1
98+
nlreturn:
99+
block-size: 5
100+
goimports:
101+
local-prefixes: github.com/vladopajic/go-test-coverage
102+
wsl:
103+
enforce-err-cuddling: true
104+
105+
issues:
106+
exclude-rules:
107+
- path: _test\.go
108+
linters:
109+
- funlen ## Function length is okay due to many tests cases
110+
- wrapcheck ## No need to check wrapping errors in tests
111+
- maintidx ## Test are okay to be long
112+
113+
- path: export_test\.go
114+
linters:
115+
- revive ## Disabling linter because we intentionally want to use unexported types in tests

.testcoverage.example.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# (mandatory) Path to coverprofile file (output of `go test -coverprofile` command)
2+
profile: cover.out
3+
4+
# (optional) When specified reported file paths will not contain local prefix in the output
5+
localPrefix: "github.com/org/project"
6+
7+
# Holds coverage thresholds percentages, values should be in range [0-100]
8+
threshold:
9+
# (optional; default 0) The minimum coverage that each file should have
10+
file: 80
11+
12+
# (optional; default 0) The minimum coverage that each package should have
13+
package: 80
14+
15+
# (optional; default 50) The minimum total coverage project should have
16+
total: 95

Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM golang:1.20 as builder
2+
WORKDIR /workspace
3+
4+
COPY go.mod go.mod
5+
COPY go.sum go.sum
6+
7+
RUN go mod download all
8+
9+
COPY ./ ./
10+
11+
ARG VERSION
12+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
13+
go build -ldflags "-X main.Version=${VERSION}" \
14+
-o go-test-coverage .
15+
16+
FROM gcr.io/distroless/base:latest
17+
WORKDIR /
18+
COPY --from=builder /workspace/go-test-coverage .
19+
COPY --from=builder /usr/local/go/bin/go /usr/local/go/bin/go
20+
ENV PATH="${PATH}:/usr/local/go/bin"
21+
ENTRYPOINT ["/go-test-coverage"]

0 commit comments

Comments
 (0)