Skip to content

Commit 671a471

Browse files
authored
Improve mock (#3)
1 parent 93fd7dc commit 671a471

File tree

9 files changed

+541
-72
lines changed

9 files changed

+541
-72
lines changed

.github/workflows/bench.yml

+25-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ jobs:
2727
with:
2828
path: |
2929
vendor
30-
key: ${{ runner.os }}-go-vendor-${{ hashFiles('**/go.mod') }}
30+
key: ${{ runner.os }}-go${{ matrix.go-version }}-vendor-${{ hashFiles('**/go.mod') }}
3131
- name: Populate dependencies
3232
run: |
33-
(test -d vendor && echo vendor found) || (go mod vendor)
33+
(test -d vendor && echo vendor found) || (go mod vendor && du -sh vendor && du -sh ~/go/pkg/mod)
3434
- name: Restore benchstat
3535
uses: actions/cache@v2
3636
with:
@@ -42,7 +42,28 @@ jobs:
4242
path: |
4343
bench-master.txt
4444
bench-main.txt
45-
# Using base sha for PR or new commit hash for master/main push in benchmark result key.
45+
# Use base sha for PR or new commit hash for master/main push in benchmark result key.
4646
key: ${{ runner.os }}-bench-${{ (github.event.pull_request.base.sha != github.event.after) && github.event.pull_request.base.sha || github.event.after }}
4747
- name: Benchmark
48-
run: REF_NAME=${GITHUB_REF##*/} make bench
48+
id: bench
49+
run: |
50+
export REF_NAME=${GITHUB_REF##*/}
51+
BENCH_COUNT=5 make bench-run bench-stat
52+
OUTPUT=$(make bench-stat)
53+
OUTPUT="${OUTPUT//'%'/'%25'}"
54+
OUTPUT="${OUTPUT//$'\n'/'%0A'}"
55+
OUTPUT="${OUTPUT//$'\r'/'%0D'}"
56+
echo "::set-output name=result::$OUTPUT"
57+
- name: Comment Benchmark Result
58+
uses: marocchino/sticky-pull-request-comment@v2
59+
with:
60+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
header: bench
62+
message: |
63+
### Benchmark Result
64+
<details><summary>Benchmark diff with base branch</summary>
65+
66+
```
67+
${{ steps.bench.outputs.result }}
68+
```
69+
</details>

.github/workflows/golangci-lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
uses: golangci/[email protected]
1818
with:
1919
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
20-
version: v1.32.2
20+
version: v1.34.1
2121

2222
# Optional: golangci-lint command line arguments.
2323
# args: ./the-only-dir-to-analyze/...

.github/workflows/test-unit.yml

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: test-unit
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- main
7+
pull_request:
8+
env:
9+
GO111MODULE: "on"
10+
jobs:
11+
test:
12+
strategy:
13+
matrix:
14+
go-version: [ 1.13.x, 1.14.x, 1.15.x ]
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Install Go
18+
uses: actions/setup-go@v2
19+
with:
20+
go-version: ${{ matrix.go-version }}
21+
- name: Checkout code
22+
uses: actions/checkout@v2
23+
- name: Restore base test coverage
24+
uses: actions/cache@v2
25+
with:
26+
path: |
27+
unit-base.txt
28+
# Use base sha for PR or new commit hash for master/main push in test result key.
29+
key: ${{ runner.os }}-unit-test-coverage-${{ (github.event.pull_request.base.sha != github.event.after) && github.event.pull_request.base.sha || github.event.after }}
30+
- name: Restore vendor
31+
uses: actions/cache@v2
32+
with:
33+
path: |
34+
vendor
35+
key: ${{ runner.os }}-go${{ matrix.go-version }}-vendor-${{ hashFiles('**/go.mod') }}
36+
- name: Populate dependencies
37+
run: |
38+
(test -d vendor && echo vendor found) || (go mod vendor && du -sh vendor && du -sh ~/go/pkg/mod)
39+
- name: Test
40+
id: test
41+
run: |
42+
make test-unit
43+
go tool cover -func=./unit.coverprofile | sed -e 's/.go:[0-9]*:\t/.go\t/g' | sed -e 's/\t\t*/\t/g' > unit.txt
44+
OUTPUT=$(test -e unit-base.txt && (diff unit-base.txt unit.txt || exit 0) || cat unit.txt)
45+
OUTPUT="${OUTPUT//'%'/'%25'}"
46+
OUTPUT="${OUTPUT//$'\n'/'%0A'}"
47+
OUTPUT="${OUTPUT//$'\r'/'%0D'}"
48+
TOTAL=$(grep 'total:' unit.txt)
49+
echo "::set-output name=diff::$OUTPUT"
50+
echo "::set-output name=total::$TOTAL"
51+
- name: Store base coverage
52+
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }}
53+
run: cp unit.txt unit-base.txt
54+
- name: Comment Test Coverage
55+
if: matrix.go-version == '1.15.x'
56+
uses: marocchino/sticky-pull-request-comment@v2
57+
with:
58+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59+
header: unit-test
60+
message: |
61+
### Unit Test Coverage
62+
${{ steps.test.outputs.total }}
63+
<details><summary>Coverage diff with base branch</summary>
64+
65+
```diff
66+
${{ steps.test.outputs.diff }}
67+
```
68+
</details>
69+
70+
- name: Upload code coverage
71+
if: matrix.go-version == '1.15.x'
72+
uses: codecov/codecov-action@v1
73+
with:
74+
file: ./unit.coverprofile
75+
flags: unittests

.github/workflows/test.yml

-39
This file was deleted.

Makefile

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
GOLANGCI_LINT_VERSION := "v1.32.2"
2-
31
# The head of Makefile determines location of dev-go to include standard targets.
42
GO ?= go
53
export GO111MODULE = on
@@ -29,11 +27,9 @@ endif
2927

3028
-include $(DEVGO_PATH)/makefiles/main.mk
3129
-include $(DEVGO_PATH)/makefiles/test-unit.mk
32-
-include $(DEVGO_PATH)/makefiles/lint.mk
3330
-include $(DEVGO_PATH)/makefiles/bench.mk
31+
-include $(DEVGO_PATH)/makefiles/lint.mk
3432
-include $(DEVGO_PATH)/makefiles/github-actions.mk
3533

3634
## Run tests
3735
test: test-unit
38-
39-

go.mod

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ module github.com/bool64/stats
33
go 1.13
44

55
require (
6-
github.com/bool64/dev v0.1.8
6+
github.com/bool64/dev v0.1.12
77
github.com/kr/pretty v0.2.0 // indirect
8-
github.com/prometheus/client_golang v1.7.1
8+
github.com/prometheus/client_golang v1.9.0
99
github.com/stretchr/testify v1.5.1
10-
gopkg.in/yaml.v2 v2.3.0 // indirect
10+
golang.org/x/sys v0.0.0-20210108172913-0df2131ae363 // indirect
11+
google.golang.org/protobuf v1.25.0 // indirect
1112
)

0 commit comments

Comments
 (0)