Skip to content

Commit 6bca742

Browse files
authored
Allow walking untagged top level fields (#3)
1 parent 898d468 commit 6bca742

13 files changed

Lines changed: 258 additions & 43 deletions

File tree

.github/workflows/bench.yml

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
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.
1219
jobs:
1320
bench:
1421
strategy:
1522
matrix:
16-
go-version: [ 1.15.x ]
23+
go-version: [ 1.17.x ]
1724
runs-on: ubuntu-latest
1825
steps:
1926
- name: Install Go
@@ -22,33 +29,57 @@ jobs:
2229
go-version: ${{ matrix.go-version }}
2330
- name: Checkout code
2431
uses: actions/checkout@v2
25-
- name: Restore vendor
32+
with:
33+
ref: ${{ (github.event.inputs.new != '') && github.event.inputs.new || github.event.ref }}
34+
- name: Go cache
2635
uses: actions/cache@v2
2736
with:
37+
# In order:
38+
# * Module download cache
39+
# * Build cache (Linux)
2840
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)
41+
~/go/pkg/mod
42+
~/.cache/go-build
43+
key: ${{ runner.os }}-go-cache-${{ hashFiles('**/go.sum') }}
44+
restore-keys: |
45+
${{ runner.os }}-go-cache
3446
- name: Restore benchstat
3547
uses: actions/cache@v2
3648
with:
3749
path: ~/go/bin/benchstat
3850
key: ${{ runner.os }}-benchstat
3951
- name: Restore base benchmark result
52+
if: env.CACHE_BENCHMARK == 'on'
53+
id: benchmark-base
4054
uses: actions/cache@v2
4155
with:
4256
path: |
4357
bench-master.txt
4458
bench-main.txt
4559
# Use base sha for PR or new commit hash for master/main push in benchmark result key.
4660
key: ${{ runner.os }}-bench-${{ (github.event.pull_request.base.sha != github.event.after) && github.event.pull_request.base.sha || github.event.after }}
61+
- name: Checkout base code
62+
if: env.RUN_BASE_BENCHMARK == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && (github.event.pull_request.base.sha != '' || github.event.inputs.old != '')
63+
uses: actions/checkout@v2
64+
with:
65+
ref: ${{ (github.event.pull_request.base.sha != '' ) && github.event.pull_request.base.sha || github.event.inputs.old }}
66+
path: __base
67+
- name: Run base benchmark
68+
if: env.RUN_BASE_BENCHMARK == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && (github.event.pull_request.base.sha != '' || github.event.inputs.old != '')
69+
run: |
70+
export REF_NAME=master
71+
cd __base
72+
make | grep bench-run && (BENCH_COUNT=5 make bench-run bench-stat && cp bench-master.txt ../bench-master.txt) || echo "No benchmarks in base"
4773
- name: Benchmark
4874
id: bench
4975
run: |
50-
export REF_NAME=${GITHUB_REF##*/}
51-
BENCH_COUNT=5 make bench-run bench-stat
76+
export REF_NAME=new
77+
BENCH_COUNT=5 make bench
78+
OUTPUT=$(make bench-stat-diff)
79+
OUTPUT="${OUTPUT//'%'/'%25'}"
80+
OUTPUT="${OUTPUT//$'\n'/'%0A'}"
81+
OUTPUT="${OUTPUT//$'\r'/'%0D'}"
82+
echo "::set-output name=diff::$OUTPUT"
5283
OUTPUT=$(make bench-stat)
5384
OUTPUT="${OUTPUT//'%'/'%25'}"
5485
OUTPUT="${OUTPUT//$'\n'/'%0A'}"
@@ -63,6 +94,13 @@ jobs:
6394
### Benchmark Result
6495
<details><summary>Benchmark diff with base branch</summary>
6596
97+
```
98+
${{ steps.bench.outputs.diff }}
99+
```
100+
</details>
101+
102+
<details><summary>Benchmark result</summary>
103+
66104
```
67105
${{ steps.bench.outputs.result }}
68106
```

.github/workflows/cloc.yml

Lines changed: 36 additions & 0 deletions
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 -OL 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+
OUTPUT="${OUTPUT//'%'/'%25'}"
24+
OUTPUT="${OUTPUT//$'\n'/'%0A'}"
25+
OUTPUT="${OUTPUT//$'\r'/'%0D'}"
26+
echo "::set-output name=diff::$OUTPUT"
27+
28+
- name: Comment Code Lines
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

Lines changed: 18 additions & 8 deletions
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,16 +15,25 @@ jobs:
1415
steps:
1516
- uses: actions/checkout@v2
1617
- name: golangci-lint
17-
uses: golangci/golangci-lint-action@v2.3.0
18+
uses: golangci/golangci-lint-action@v2.5.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.36.0
21+
version: v1.41.1
22+
23+
# Optional: working directory, useful for monorepos
24+
# working-directory: somedir
2125

2226
# Optional: golangci-lint command line arguments.
23-
# args: ./the-only-dir-to-analyze/...
27+
# args: --issues-exit-code=0
28+
29+
# Optional: show only new issues if it's a pull request. The default value is `false`.
30+
# only-new-issues: true
31+
32+
# Optional: if set to true then the action will use pre-installed Go.
33+
# skip-go-installation: true
34+
35+
# Optional: if set to true then the action don't cache or restore ~/go/pkg.
36+
# skip-pkg-cache: true
2437

25-
# Required: the token is used for fetching a list of releases of golangci-lint.
26-
# The secret `GITHUB_TOKEN` is automatically created by GitHub,
27-
# no need to create it manually.
28-
# https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token#about-the-github_token-secret
29-
github-token: ${{ secrets.GITHUB_TOKEN }}
38+
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
39+
# skip-build-cache: true

.github/workflows/gorelease.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# This script is provided by github.com/bool64/dev.
2+
name: gorelease
3+
on:
4+
pull_request:
5+
env:
6+
GO111MODULE: "on"
7+
jobs:
8+
gorelease:
9+
strategy:
10+
matrix:
11+
go-version: [ 1.17.x ]
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Install Go
15+
uses: actions/setup-go@v2
16+
with:
17+
go-version: ${{ matrix.go-version }}
18+
- name: Checkout code
19+
uses: actions/checkout@v2
20+
- name: Gorelease cache
21+
uses: actions/cache@v2
22+
with:
23+
path: |
24+
~/go/bin/gorelease
25+
key: ${{ runner.os }}-gorelease
26+
- name: Gorelease
27+
id: gorelease
28+
run: |
29+
test -e ~/go/bin/gorelease || go install golang.org/x/exp/cmd/gorelease@latest
30+
OUTPUT=$(gorelease || exit 0)
31+
OUTPUT="${OUTPUT//'%'/'%25'}"
32+
OUTPUT="${OUTPUT//$'\n'/'%0A'}"
33+
OUTPUT="${OUTPUT//$'\r'/'%0D'}"
34+
echo "::set-output name=report::$OUTPUT"
35+
- name: Comment Report
36+
uses: marocchino/sticky-pull-request-comment@v2
37+
with:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+
header: gorelease
40+
message: |
41+
### API Changes
42+
43+
<pre>
44+
${{ steps.gorelease.outputs.report }}
45+
</pre>

.github/workflows/test-unit.yml

Lines changed: 27 additions & 10 deletions
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,11 +8,12 @@ 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.
1012
jobs:
1113
test:
1214
strategy:
1315
matrix:
14-
go-version: [ 1.13.x, 1.14.x, 1.15.x ]
16+
go-version: [ 1.13.x, 1.14.x, 1.15.x, 1.16.x, 1.17.x ]
1517
runs-on: ubuntu-latest
1618
steps:
1719
- name: Install Go
@@ -20,22 +22,37 @@ jobs:
2022
go-version: ${{ matrix.go-version }}
2123
- name: Checkout code
2224
uses: actions/checkout@v2
25+
- name: Go cache
26+
uses: actions/cache@v2
27+
with:
28+
# In order:
29+
# * Module download cache
30+
# * Build cache (Linux)
31+
path: |
32+
~/go/pkg/mod
33+
~/.cache/go-build
34+
key: ${{ runner.os }}-go-cache-${{ hashFiles('**/go.sum') }}
35+
restore-keys: |
36+
${{ runner.os }}-go-cache
2337
- name: Restore base test coverage
38+
if: matrix.go-version == '1.17.x'
2439
uses: actions/cache@v2
2540
with:
2641
path: |
2742
unit-base.txt
2843
# Use base sha for PR or new commit hash for master/main push in test result key.
2944
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
45+
- name: Checkout base code
46+
if: matrix.go-version == '1.17.x' && env.RUN_BASE_COVERAGE == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && github.event.pull_request.base.sha != ''
47+
uses: actions/checkout@v2
3248
with:
33-
path: |
34-
vendor
35-
key: ${{ runner.os }}-go${{ matrix.go-version }}-vendor-${{ hashFiles('**/go.mod') }}
36-
- name: Populate dependencies
49+
ref: ${{ github.event.pull_request.base.sha }}
50+
path: __base
51+
- name: Run test for base code
52+
if: matrix.go-version == '1.17.x' && env.RUN_BASE_COVERAGE == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && github.event.pull_request.base.sha != ''
3753
run: |
38-
(test -d vendor && echo vendor found) || (go mod vendor && du -sh vendor && du -sh ~/go/pkg/mod)
54+
cd __base
55+
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"
3956
- name: Test
4057
id: test
4158
run: |
@@ -52,7 +69,7 @@ jobs:
5269
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }}
5370
run: cp unit.txt unit-base.txt
5471
- name: Comment Test Coverage
55-
if: matrix.go-version == '1.15.x'
72+
if: matrix.go-version == '1.17.x'
5673
uses: marocchino/sticky-pull-request-comment@v2
5774
with:
5875
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -68,7 +85,7 @@ jobs:
6885
</details>
6986
7087
- name: Upload code coverage
71-
if: matrix.go-version == '1.15.x'
88+
if: matrix.go-version == '1.17.x'
7289
uses: codecov/codecov-action@v1
7390
with:
7491
file: ./unit.coverprofile

.gitignore

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

.golangci.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# See https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml
2+
run:
3+
tests: true
4+
5+
linters-settings:
6+
errcheck:
7+
check-type-assertions: true
8+
check-blank: true
9+
gocyclo:
10+
min-complexity: 20
11+
dupl:
12+
threshold: 100
13+
misspell:
14+
locale: US
15+
unused:
16+
check-exported: false
17+
unparam:
18+
check-exported: true
19+
cyclop:
20+
max-complexity: 12
21+
22+
linters:
23+
enable-all: true
24+
disable:
25+
- tagliatelle
26+
- lll
27+
- maligned
28+
- gochecknoglobals
29+
- gomnd
30+
- wrapcheck
31+
- paralleltest
32+
- forbidigo
33+
- exhaustivestruct
34+
- interfacer # deprecated
35+
- forcetypeassert
36+
- scopelint # deprecated
37+
- ifshort # too many false positives
38+
- golint # deprecated
39+
40+
issues:
41+
exclude-use-default: false
42+
exclude-rules:
43+
- linters:
44+
- gomnd
45+
- goconst
46+
- goerr113
47+
- noctx
48+
- funlen
49+
- dupl
50+
path: "_test.go"
51+

0 commit comments

Comments
 (0)