Skip to content

Commit e614bc9

Browse files
authored
Update CI, fix wrong argument name (#6)
1 parent 60c0215 commit e614bc9

11 files changed

+222
-46
lines changed

.github/workflows/bench.yml

+67-22
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,98 @@
1+
# This script is provided by github.com/bool64/dev.
12
name: bench
23
on:
3-
push:
4-
tags:
5-
- v*
6-
branches:
7-
- master
8-
- main
94
pull_request:
5+
workflow_dispatch:
6+
inputs:
7+
old:
8+
description: 'Old Ref'
9+
required: false
10+
default: 'master'
11+
new:
12+
description: 'New Ref'
13+
required: true
14+
1015
env:
1116
GO111MODULE: "on"
17+
CACHE_BENCHMARK: "off" # Enables benchmark result reuse between runs, may skew latency results.
18+
RUN_BASE_BENCHMARK: "on" # Runs benchmark for PR base in case benchmark result is missing.
19+
GO_VERSION: 1.17.x
1220
jobs:
1321
bench:
14-
strategy:
15-
matrix:
16-
go-version: [ 1.16.x ]
1722
runs-on: ubuntu-latest
1823
steps:
19-
- name: Install Go
24+
- name: Install Go stable
25+
if: env.GO_VERSION != 'tip'
2026
uses: actions/setup-go@v2
2127
with:
22-
go-version: ${{ matrix.go-version }}
28+
go-version: ${{ env.GO_VERSION }}
29+
- name: Install Go tip
30+
if: env.GO_VERSION == 'tip'
31+
run: |
32+
curl -sL https://storage.googleapis.com/go-build-snap/go/linux-amd64/$(git ls-remote https://github.com/golang/go.git HEAD | awk '{print $1;}').tar.gz -o gotip.tar.gz
33+
ls -lah gotip.tar.gz
34+
mkdir -p ~/sdk/gotip
35+
tar -C ~/sdk/gotip -xzf gotip.tar.gz
36+
~/sdk/gotip/bin/go version
37+
echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV
2338
- name: Checkout code
2439
uses: actions/checkout@v2
25-
- name: Restore vendor
40+
with:
41+
ref: ${{ (github.event.inputs.new != '') && github.event.inputs.new || github.event.ref }}
42+
- name: Go cache
2643
uses: actions/cache@v2
2744
with:
45+
# In order:
46+
# * Module download cache
47+
# * Build cache (Linux)
2848
path: |
29-
vendor
30-
key: ${{ runner.os }}-go${{ matrix.go-version }}-vendor-${{ hashFiles('**/go.mod') }}
31-
- name: Populate dependencies
32-
run: |
33-
(test -d vendor && echo vendor found) || (go mod vendor && du -sh vendor && du -sh ~/go/pkg/mod)
49+
~/go/pkg/mod
50+
~/.cache/go-build
51+
key: ${{ runner.os }}-go-cache-${{ hashFiles('**/go.sum') }}
52+
restore-keys: |
53+
${{ runner.os }}-go-cache
3454
- name: Restore benchstat
3555
uses: actions/cache@v2
3656
with:
3757
path: ~/go/bin/benchstat
3858
key: ${{ runner.os }}-benchstat
3959
- name: Restore base benchmark result
60+
if: env.CACHE_BENCHMARK == 'on'
61+
id: benchmark-base
4062
uses: actions/cache@v2
4163
with:
4264
path: |
4365
bench-master.txt
4466
bench-main.txt
4567
# Use base sha for PR or new commit hash for master/main push in benchmark result key.
4668
key: ${{ runner.os }}-bench-${{ (github.event.pull_request.base.sha != github.event.after) && github.event.pull_request.base.sha || github.event.after }}
69+
- name: Checkout base code
70+
if: env.RUN_BASE_BENCHMARK == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && (github.event.pull_request.base.sha != '' || github.event.inputs.old != '')
71+
uses: actions/checkout@v2
72+
with:
73+
ref: ${{ (github.event.pull_request.base.sha != '' ) && github.event.pull_request.base.sha || github.event.inputs.old }}
74+
path: __base
75+
- name: Run base benchmark
76+
if: env.RUN_BASE_BENCHMARK == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && (github.event.pull_request.base.sha != '' || github.event.inputs.old != '')
77+
run: |
78+
export REF_NAME=master
79+
cd __base
80+
make | grep bench-run && (BENCH_COUNT=5 make bench-run bench-stat && cp bench-master.txt ../bench-master.txt) || echo "No benchmarks in base"
4781
- name: Benchmark
4882
id: bench
4983
run: |
50-
export REF_NAME=${GITHUB_REF##*/}
51-
BENCH_COUNT=5 make bench-run bench-stat
84+
export REF_NAME=new
85+
BENCH_COUNT=5 make bench
86+
OUTPUT=$(make bench-stat-diff)
87+
echo "${OUTPUT}"
88+
OUTPUT="${OUTPUT//$'\n'/%0A}"
89+
echo "::set-output name=diff::$OUTPUT"
5290
OUTPUT=$(make bench-stat)
53-
OUTPUT="${OUTPUT//'%'/'%25'}"
54-
OUTPUT="${OUTPUT//$'\n'/'%0A'}"
55-
OUTPUT="${OUTPUT//$'\r'/'%0D'}"
91+
echo "${OUTPUT}"
92+
OUTPUT="${OUTPUT//$'\n'/%0A}"
5693
echo "::set-output name=result::$OUTPUT"
5794
- name: Comment Benchmark Result
95+
continue-on-error: true
5896
uses: marocchino/sticky-pull-request-comment@v2
5997
with:
6098
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -63,6 +101,13 @@ jobs:
63101
### Benchmark Result
64102
<details><summary>Benchmark diff with base branch</summary>
65103
104+
```
105+
${{ steps.bench.outputs.diff }}
106+
```
107+
</details>
108+
109+
<details><summary>Benchmark result</summary>
110+
66111
```
67112
${{ steps.bench.outputs.result }}
68113
```

.github/workflows/cloc.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This script is provided by github.com/bool64/dev.
2+
name: cloc
3+
on:
4+
pull_request:
5+
jobs:
6+
cloc:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout code
10+
uses: actions/checkout@v2
11+
with:
12+
path: pr
13+
- name: Checkout base code
14+
uses: actions/checkout@v2
15+
with:
16+
ref: ${{ github.event.pull_request.base.sha }}
17+
path: base
18+
- name: Count Lines Of Code
19+
id: loc
20+
run: |
21+
curl -sLO https://github.com/vearutop/sccdiff/releases/download/v1.0.1/linux_amd64.tar.gz && tar xf linux_amd64.tar.gz
22+
OUTPUT=$(cd pr && ../sccdiff -basedir ../base)
23+
echo "${OUTPUT}"
24+
OUTPUT="${OUTPUT//$'\n'/%0A}"
25+
echo "::set-output name=diff::$OUTPUT"
26+
27+
- name: Comment Code Lines
28+
continue-on-error: true
29+
uses: marocchino/sticky-pull-request-comment@v2
30+
with:
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
header: LOC
33+
message: |
34+
### Lines Of Code
35+
36+
${{ steps.loc.outputs.diff }}

.github/workflows/golangci-lint.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# This script is provided by github.com/bool64/dev.
12
name: lint
23
on:
34
push:
@@ -14,10 +15,10 @@ jobs:
1415
steps:
1516
- uses: actions/checkout@v2
1617
- name: golangci-lint
17-
uses: golangci/[email protected].1
18+
uses: golangci/[email protected].2
1819
with:
1920
# 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.37.1
21+
version: v1.43.0
2122

2223
# Optional: working directory, useful for monorepos
2324
# working-directory: somedir

.github/workflows/gorelease.yml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# This script is provided by github.com/bool64/dev.
2+
name: gorelease
3+
on:
4+
pull_request:
5+
env:
6+
GO_VERSION: 1.17.x
7+
jobs:
8+
gorelease:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Install Go stable
12+
if: env.GO_VERSION != 'tip'
13+
uses: actions/setup-go@v2
14+
with:
15+
go-version: ${{ env.GO_VERSION }}
16+
- name: Install Go tip
17+
if: env.GO_VERSION == 'tip'
18+
run: |
19+
curl -sL https://storage.googleapis.com/go-build-snap/go/linux-amd64/$(git ls-remote https://github.com/golang/go.git HEAD | awk '{print $1;}').tar.gz -o gotip.tar.gz
20+
ls -lah gotip.tar.gz
21+
mkdir -p ~/sdk/gotip
22+
tar -C ~/sdk/gotip -xzf gotip.tar.gz
23+
~/sdk/gotip/bin/go version
24+
echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV
25+
- name: Checkout code
26+
uses: actions/checkout@v2
27+
- name: Gorelease cache
28+
uses: actions/cache@v2
29+
with:
30+
path: |
31+
~/go/bin/gorelease
32+
key: ${{ runner.os }}-gorelease
33+
- name: Gorelease
34+
id: gorelease
35+
run: |
36+
test -e ~/go/bin/gorelease || go install golang.org/x/exp/cmd/gorelease@latest
37+
OUTPUT=$(gorelease || exit 0)
38+
echo "${OUTPUT}"
39+
OUTPUT="${OUTPUT//$'\n'/%0A}"
40+
echo "::set-output name=report::$OUTPUT"
41+
- name: Comment Report
42+
continue-on-error: true
43+
uses: marocchino/sticky-pull-request-comment@v2
44+
with:
45+
header: gorelease
46+
message: |
47+
### Go API Changes
48+
49+
<pre>
50+
${{ steps.gorelease.outputs.report }}
51+
</pre>

.github/workflows/test-unit.yml

+44-14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# This script is provided by github.com/bool64/dev.
12
name: test-unit
23
on:
34
push:
@@ -7,52 +8,81 @@ on:
78
pull_request:
89
env:
910
GO111MODULE: "on"
11+
RUN_BASE_COVERAGE: "on" # Runs test for PR base in case base test coverage is missing.
12+
COV_GO_VERSION: 1.17.x # Version of Go to collect coverage
1013
jobs:
1114
test:
1215
strategy:
1316
matrix:
14-
go-version: [ 1.13.x, 1.14.x, 1.15.x, 1.16.x ]
17+
go-version: [ 1.13.x, 1.14.x, 1.15.x, 1.16.x, 1.17.x, tip ]
1518
runs-on: ubuntu-latest
1619
steps:
17-
- name: Install Go
20+
- name: Install Go stable
21+
if: matrix.go-version != 'tip'
1822
uses: actions/setup-go@v2
1923
with:
2024
go-version: ${{ matrix.go-version }}
25+
- name: Install Go tip
26+
if: matrix.go-version == 'tip'
27+
run: |
28+
curl -sL https://storage.googleapis.com/go-build-snap/go/linux-amd64/$(git ls-remote https://github.com/golang/go.git HEAD | awk '{print $1;}').tar.gz -o gotip.tar.gz
29+
ls -lah gotip.tar.gz
30+
mkdir -p ~/sdk/gotip
31+
tar -C ~/sdk/gotip -xzf gotip.tar.gz
32+
~/sdk/gotip/bin/go version
33+
echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV
2134
- name: Checkout code
2235
uses: actions/checkout@v2
36+
- name: Go cache
37+
uses: actions/cache@v2
38+
with:
39+
# In order:
40+
# * Module download cache
41+
# * Build cache (Linux)
42+
path: |
43+
~/go/pkg/mod
44+
~/.cache/go-build
45+
key: ${{ runner.os }}-go-cache-${{ hashFiles('**/go.sum') }}
46+
restore-keys: |
47+
${{ runner.os }}-go-cache
2348
- name: Restore base test coverage
49+
id: base-coverage
50+
if: matrix.go-version == env.COV_GO_VERSION
2451
uses: actions/cache@v2
2552
with:
2653
path: |
2754
unit-base.txt
2855
# Use base sha for PR or new commit hash for master/main push in test result key.
2956
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
57+
- name: Checkout base code
58+
if: matrix.go-version == env.COV_GO_VERSION && env.RUN_BASE_COVERAGE == 'on' && steps.base-coverage.outputs.cache-hit != 'true' && github.event.pull_request.base.sha != ''
59+
uses: actions/checkout@v2
3260
with:
33-
path: |
34-
vendor
35-
key: ${{ runner.os }}-go${{ matrix.go-version }}-vendor-${{ hashFiles('**/go.mod') }}
36-
- name: Populate dependencies
61+
ref: ${{ github.event.pull_request.base.sha }}
62+
path: __base
63+
- name: Run test for base code
64+
if: matrix.go-version == env.COV_GO_VERSION && env.RUN_BASE_COVERAGE == 'on' && steps.base-coverage.outputs.cache-hit != 'true' && github.event.pull_request.base.sha != ''
3765
run: |
38-
(test -d vendor && echo vendor found) || (go mod vendor && du -sh vendor && du -sh ~/go/pkg/mod)
66+
cd __base
67+
make | grep test-unit && (make test-unit && go tool cover -func=./unit.coverprofile | sed -e 's/.go:[0-9]*:\t/.go\t/g' | sed -e 's/\t\t*/\t/g' > ../unit-base.txt) || echo "No test-unit in base"
3968
- name: Test
4069
id: test
4170
run: |
4271
make test-unit
4372
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
4473
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'}"
74+
echo "${OUTPUT}"
75+
OUTPUT="${OUTPUT//$'\n'/%0A}"
4876
TOTAL=$(grep 'total:' unit.txt)
77+
echo "${TOTAL}"
4978
echo "::set-output name=diff::$OUTPUT"
5079
echo "::set-output name=total::$TOTAL"
5180
- name: Store base coverage
5281
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }}
5382
run: cp unit.txt unit-base.txt
5483
- name: Comment Test Coverage
55-
if: matrix.go-version == '1.16.x'
84+
continue-on-error: true
85+
if: matrix.go-version == env.COV_GO_VERSION
5686
uses: marocchino/sticky-pull-request-comment@v2
5787
with:
5888
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -68,7 +98,7 @@ jobs:
6898
</details>
6999
70100
- name: Upload code coverage
71-
if: matrix.go-version == '1.16.x'
101+
if: matrix.go-version == env.COV_GO_VERSION
72102
uses: codecov/codecov-action@v1
73103
with:
74104
file: ./unit.coverprofile

.gitignore

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
/.idea
2-
/bench-*
3-
/unit.coverprofile
2+
/*.coverprofile
3+
/.vscode
4+
/bench-*.txt
5+
/vendor

.golangci.yml

+9
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ linters:
2828
- paralleltest
2929
- forbidigo
3030
- exhaustivestruct
31+
- interfacer # deprecated
32+
- forcetypeassert
33+
- scopelint # deprecated
34+
- ifshort # too many false positives
35+
- golint # deprecated
36+
- varnamelen
37+
- tagliatelle
38+
- errname
39+
- ireturn
3140

3241
issues:
3342
exclude-use-default: false

Makefile

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#GOLANGCI_LINT_VERSION := "v1.37.1" # Optional configuration to pinpoint golangci-lint version.
1+
#GOLANGCI_LINT_VERSION := "v1.43.0" # Optional configuration to pinpoint golangci-lint version.
22

33
# The head of Makefile determines location of dev-go to include standard targets.
44
GO ?= go
@@ -23,7 +23,7 @@ ifeq ($(DEVGO_PATH),)
2323
DEVGO_PATH := $(shell GO111MODULE=on $(GO) list ${modVendor} -f '{{.Dir}}' -m github.com/bool64/dev)
2424
ifeq ($(DEVGO_PATH),)
2525
$(info Module github.com/bool64/dev not found, downloading.)
26-
DEVGO_PATH := $(shell export GO111MODULE=on && $(GO) mod tidy && $(GO) list -f '{{.Dir}}' -m github.com/bool64/dev)
26+
DEVGO_PATH := $(shell export GO111MODULE=on && $(GO) get github.com/bool64/dev && $(GO) list -f '{{.Dir}}' -m github.com/bool64/dev)
2727
endif
2828
endif
2929

@@ -33,5 +33,7 @@ endif
3333
-include $(DEVGO_PATH)/makefiles/bench.mk
3434
-include $(DEVGO_PATH)/makefiles/reset-ci.mk
3535

36+
# Add your custom targets here.
37+
3638
## Run tests
3739
test: test-unit

0 commit comments

Comments
 (0)