Skip to content

Commit ab7791b

Browse files
authored
Update deps, force errors as messages (#12)
1 parent 862eec4 commit ab7791b

File tree

11 files changed

+196
-216
lines changed

11 files changed

+196
-216
lines changed

.github/workflows/bench.yml

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ env:
2121
GO111MODULE: "on"
2222
CACHE_BENCHMARK: "off" # Enables benchmark result reuse between runs, may skew latency results.
2323
RUN_BASE_BENCHMARK: "on" # Runs benchmark for PR base in case benchmark result is missing.
24-
GO_VERSION: 1.18.x
24+
GO_VERSION: 1.22.x
2525
jobs:
2626
bench:
2727
runs-on: ubuntu-latest
2828
steps:
2929
- name: Install Go stable
3030
if: env.GO_VERSION != 'tip'
31-
uses: actions/setup-go@v3
31+
uses: actions/setup-go@v4
3232
with:
3333
go-version: ${{ env.GO_VERSION }}
34+
3435
- name: Install Go tip
3536
if: env.GO_VERSION == 'tip'
3637
run: |
@@ -40,12 +41,14 @@ jobs:
4041
tar -C ~/sdk/gotip -xzf gotip.tar.gz
4142
~/sdk/gotip/bin/go version
4243
echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV
44+
4345
- name: Checkout code
44-
uses: actions/checkout@v2
46+
uses: actions/checkout@v3
4547
with:
4648
ref: ${{ (github.event.inputs.new != '') && github.event.inputs.new || github.event.ref }}
49+
4750
- name: Go cache
48-
uses: actions/cache@v2
51+
uses: actions/cache@v3
4952
with:
5053
# In order:
5154
# * Module download cache
@@ -56,47 +59,57 @@ jobs:
5659
key: ${{ runner.os }}-go-cache-${{ hashFiles('**/go.sum') }}
5760
restore-keys: |
5861
${{ runner.os }}-go-cache
62+
5963
- name: Restore benchstat
60-
uses: actions/cache@v2
64+
uses: actions/cache@v3
6165
with:
6266
path: ~/go/bin/benchstat
63-
key: ${{ runner.os }}-benchstat
67+
key: ${{ runner.os }}-benchstat-legacy
68+
6469
- name: Restore base benchmark result
70+
id: base-benchmark
6571
if: env.CACHE_BENCHMARK == 'on'
66-
id: benchmark-base
67-
uses: actions/cache@v2
72+
uses: actions/cache@v3
6873
with:
6974
path: |
7075
bench-master.txt
7176
bench-main.txt
7277
# Use base sha for PR or new commit hash for master/main push in benchmark result key.
7378
key: ${{ runner.os }}-bench-${{ (github.event.pull_request.base.sha != github.event.after) && github.event.pull_request.base.sha || github.event.after }}
74-
- name: Checkout base code
75-
if: env.RUN_BASE_BENCHMARK == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && (github.event.pull_request.base.sha != '' || github.event.inputs.old != '')
76-
uses: actions/checkout@v2
77-
with:
78-
ref: ${{ (github.event.pull_request.base.sha != '' ) && github.event.pull_request.base.sha || github.event.inputs.old }}
79-
path: __base
80-
- name: Run base benchmark
81-
if: env.RUN_BASE_BENCHMARK == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && (github.event.pull_request.base.sha != '' || github.event.inputs.old != '')
79+
80+
- name: Run benchmark
81+
run: |
82+
export REF_NAME=new
83+
make bench
84+
OUTPUT=$(make bench-stat-diff)
85+
echo "${OUTPUT}"
86+
echo "diff<<EOF" >> $GITHUB_OUTPUT && echo "$OUTPUT" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
87+
OUTPUT=$(make bench-stat)
88+
echo "${OUTPUT}"
89+
echo "result<<EOF" >> $GITHUB_OUTPUT && echo "$OUTPUT" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
90+
91+
- name: Run benchmark for base code
92+
if: env.RUN_BASE_BENCHMARK == 'on' && steps.base-benchmark.outputs.cache-hit != 'true' && (github.event.pull_request.base.sha != '' || github.event.inputs.old != '')
8293
run: |
94+
git fetch origin master ${{ github.event.pull_request.base.sha }}
95+
HEAD=$(git rev-parse HEAD)
96+
git reset --hard ${{ github.event.pull_request.base.sha }}
8397
export REF_NAME=master
84-
cd __base
85-
make | grep bench-run && (BENCH_COUNT=5 make bench-run bench-stat && cp bench-master.txt ../bench-master.txt) || echo "No benchmarks in base"
86-
- name: Benchmark
98+
make bench-run bench-stat
99+
git reset --hard $HEAD
100+
101+
- name: Benchmark stats
87102
id: bench
88103
run: |
89104
export REF_NAME=new
90-
BENCH_COUNT=5 make bench
91105
OUTPUT=$(make bench-stat-diff)
92106
echo "${OUTPUT}"
93-
OUTPUT="${OUTPUT//$'\n'/%0A}"
94-
echo "::set-output name=diff::$OUTPUT"
107+
echo "diff<<EOF" >> $GITHUB_OUTPUT && echo "$OUTPUT" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
95108
OUTPUT=$(make bench-stat)
96109
echo "${OUTPUT}"
97-
OUTPUT="${OUTPUT//$'\n'/%0A}"
98-
echo "::set-output name=result::$OUTPUT"
99-
- name: Comment Benchmark Result
110+
echo "result<<EOF" >> $GITHUB_OUTPUT && echo "$OUTPUT" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
111+
112+
- name: Comment benchmark result
100113
continue-on-error: true
101114
uses: marocchino/sticky-pull-request-comment@v2
102115
with:

.github/workflows/cloc.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,25 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- name: Checkout code
16-
uses: actions/checkout@v2
16+
uses: actions/checkout@v3
1717
with:
1818
path: pr
1919
- name: Checkout base code
20-
uses: actions/checkout@v2
20+
uses: actions/checkout@v3
2121
with:
2222
ref: ${{ github.event.pull_request.base.sha }}
2323
path: base
24-
- name: Count Lines Of Code
24+
- name: Count lines of code
2525
id: loc
2626
run: |
27-
curl -sLO https://github.com/vearutop/sccdiff/releases/download/v1.0.1/linux_amd64.tar.gz && tar xf linux_amd64.tar.gz
27+
curl -sLO https://github.com/vearutop/sccdiff/releases/download/v1.0.3/linux_amd64.tar.gz && tar xf linux_amd64.tar.gz
28+
sccdiff_hash=$(git hash-object ./sccdiff)
29+
[ "$sccdiff_hash" == "ae8a07b687bd3dba60861584efe724351aa7ff63" ] || (echo "::error::unexpected hash for sccdiff, possible tampering: $sccdiff_hash" && exit 1)
2830
OUTPUT=$(cd pr && ../sccdiff -basedir ../base)
2931
echo "${OUTPUT}"
30-
OUTPUT="${OUTPUT//$'\n'/%0A}"
31-
echo "::set-output name=diff::$OUTPUT"
32+
echo "diff<<EOF" >> $GITHUB_OUTPUT && echo "$OUTPUT" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
3233
33-
- name: Comment Code Lines
34+
- name: Comment lines of code
3435
continue-on-error: true
3536
uses: marocchino/sticky-pull-request-comment@v2
3637
with:

.github/workflows/golangci-lint.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ jobs:
2121
steps:
2222
- uses: actions/setup-go@v3
2323
with:
24-
go-version: 1.18.x
24+
go-version: 1.22.x
2525
- uses: actions/checkout@v2
2626
- name: golangci-lint
27-
uses: golangci/golangci-lint-action@v3.1.0
27+
uses: golangci/golangci-lint-action@v4.0.0
2828
with:
2929
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
30-
version: v1.45.2
30+
version: v1.56.2
3131

3232
# Optional: working directory, useful for monorepos
3333
# working-directory: somedir

.github/workflows/gorelease.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ concurrency:
99
cancel-in-progress: true
1010

1111
env:
12-
GO_VERSION: 1.18.x
12+
GO_VERSION: 1.22.x
1313
jobs:
1414
gorelease:
1515
runs-on: ubuntu-latest
1616
steps:
1717
- name: Install Go stable
1818
if: env.GO_VERSION != 'tip'
19-
uses: actions/setup-go@v3
19+
uses: actions/setup-go@v4
2020
with:
2121
go-version: ${{ env.GO_VERSION }}
2222
- name: Install Go tip
@@ -29,22 +29,21 @@ jobs:
2929
~/sdk/gotip/bin/go version
3030
echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV
3131
- name: Checkout code
32-
uses: actions/checkout@v2
32+
uses: actions/checkout@v3
3333
- name: Gorelease cache
34-
uses: actions/cache@v2
34+
uses: actions/cache@v3
3535
with:
3636
path: |
3737
~/go/bin/gorelease
38-
key: ${{ runner.os }}-gorelease
38+
key: ${{ runner.os }}-gorelease-generic
3939
- name: Gorelease
4040
id: gorelease
4141
run: |
4242
test -e ~/go/bin/gorelease || go install golang.org/x/exp/cmd/gorelease@latest
43-
OUTPUT=$(gorelease || exit 0)
43+
OUTPUT=$(gorelease 2>&1 || exit 0)
4444
echo "${OUTPUT}"
45-
OUTPUT="${OUTPUT//$'\n'/%0A}"
46-
echo "::set-output name=report::$OUTPUT"
47-
- name: Comment Report
45+
echo "report<<EOF" >> $GITHUB_OUTPUT && echo "$OUTPUT" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
46+
- name: Comment report
4847
continue-on-error: true
4948
uses: marocchino/sticky-pull-request-comment@v2
5049
with:

.github/workflows/test-unit.yml

Lines changed: 53 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,21 @@ concurrency:
1515
env:
1616
GO111MODULE: "on"
1717
RUN_BASE_COVERAGE: "on" # Runs test for PR base in case base test coverage is missing.
18-
COV_GO_VERSION: 1.18.x # Version of Go to collect coverage
18+
COV_GO_VERSION: 1.22.x # Version of Go to collect coverage
19+
TARGET_DELTA_COV: 90 # Target coverage of changed lines, in percents
1920
jobs:
2021
test:
2122
strategy:
2223
matrix:
23-
go-version: [ 1.15.x, 1.16.x, 1.17.x, 1.18.x ]
24+
go-version: [ 1.19.x, 1.21.x, 1.22.x ]
2425
runs-on: ubuntu-latest
2526
steps:
2627
- name: Install Go stable
2728
if: matrix.go-version != 'tip'
28-
uses: actions/setup-go@v3
29+
uses: actions/setup-go@v4
2930
with:
3031
go-version: ${{ matrix.go-version }}
32+
3133
- name: Install Go tip
3234
if: matrix.go-version == 'tip'
3335
run: |
@@ -37,10 +39,12 @@ jobs:
3739
tar -C ~/sdk/gotip -xzf gotip.tar.gz
3840
~/sdk/gotip/bin/go version
3941
echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV
42+
4043
- name: Checkout code
41-
uses: actions/checkout@v2
44+
uses: actions/checkout@v3
45+
4246
- name: Go cache
43-
uses: actions/cache@v2
47+
uses: actions/cache@v3
4448
with:
4549
# In order:
4650
# * Module download cache
@@ -51,58 +55,79 @@ jobs:
5155
key: ${{ runner.os }}-go-cache-${{ hashFiles('**/go.sum') }}
5256
restore-keys: |
5357
${{ runner.os }}-go-cache
58+
5459
- name: Restore base test coverage
5560
id: base-coverage
56-
if: matrix.go-version == env.COV_GO_VERSION
61+
if: matrix.go-version == env.COV_GO_VERSION && github.event.pull_request.base.sha != ''
5762
uses: actions/cache@v2
5863
with:
5964
path: |
6065
unit-base.txt
6166
# Use base sha for PR or new commit hash for master/main push in test result key.
6267
key: ${{ runner.os }}-unit-test-coverage-${{ (github.event.pull_request.base.sha != github.event.after) && github.event.pull_request.base.sha || github.event.after }}
63-
- name: Checkout 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 != ''
65-
uses: actions/checkout@v2
66-
with:
67-
ref: ${{ github.event.pull_request.base.sha }}
68-
path: __base
68+
6969
- name: Run test for base code
7070
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 != ''
7171
run: |
72-
cd __base
73-
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"
72+
git fetch origin master ${{ github.event.pull_request.base.sha }}
73+
HEAD=$(git rev-parse HEAD)
74+
git reset --hard ${{ github.event.pull_request.base.sha }}
75+
(make test-unit && go tool cover -func=./unit.coverprofile > unit-base.txt) || echo "No test-unit in base"
76+
git reset --hard $HEAD
77+
7478
- name: Test
7579
id: test
7680
run: |
7781
make test-unit
78-
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
79-
OUTPUT=$(test -e unit-base.txt && (diff unit-base.txt unit.txt || exit 0) || cat unit.txt)
80-
echo "${OUTPUT}"
81-
OUTPUT="${OUTPUT//$'\n'/%0A}"
82+
go tool cover -func=./unit.coverprofile > unit.txt
8283
TOTAL=$(grep 'total:' unit.txt)
8384
echo "${TOTAL}"
84-
echo "::set-output name=diff::$OUTPUT"
85-
echo "::set-output name=total::$TOTAL"
86-
- name: Store base coverage
87-
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }}
88-
run: cp unit.txt unit-base.txt
89-
- name: Comment Test Coverage
85+
echo "total=$TOTAL" >> $GITHUB_OUTPUT
86+
87+
- name: Annotate missing test coverage
88+
id: annotate
89+
if: matrix.go-version == env.COV_GO_VERSION && github.event.pull_request.base.sha != ''
90+
run: |
91+
curl -sLO https://github.com/vearutop/gocovdiff/releases/download/v1.4.2/linux_amd64.tar.gz && tar xf linux_amd64.tar.gz && rm linux_amd64.tar.gz
92+
gocovdiff_hash=$(git hash-object ./gocovdiff)
93+
[ "$gocovdiff_hash" == "c37862c73a677e5a9c069470287823ab5bbf0244" ] || (echo "::error::unexpected hash for gocovdiff, possible tampering: $gocovdiff_hash" && exit 1)
94+
git fetch origin master ${{ github.event.pull_request.base.sha }}
95+
REP=$(./gocovdiff -mod github.com/$GITHUB_REPOSITORY -cov unit.coverprofile -gha-annotations gha-unit.txt -delta-cov-file delta-cov-unit.txt -target-delta-cov ${TARGET_DELTA_COV})
96+
echo "${REP}"
97+
cat gha-unit.txt
98+
DIFF=$(test -e unit-base.txt && ./gocovdiff -mod github.com/$GITHUB_REPOSITORY -func-cov unit.txt -func-base-cov unit-base.txt || echo "Missing base coverage file")
99+
TOTAL=$(cat delta-cov-unit.txt)
100+
echo "rep<<EOF" >> $GITHUB_OUTPUT && echo "$REP" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
101+
echo "diff<<EOF" >> $GITHUB_OUTPUT && echo "$DIFF" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
102+
echo "total<<EOF" >> $GITHUB_OUTPUT && echo "$TOTAL" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
103+
104+
- name: Comment test coverage
90105
continue-on-error: true
91-
if: matrix.go-version == env.COV_GO_VERSION
106+
if: matrix.go-version == env.COV_GO_VERSION && github.event.pull_request.base.sha != ''
92107
uses: marocchino/sticky-pull-request-comment@v2
93108
with:
94109
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
95110
header: unit-test
96111
message: |
97112
### Unit Test Coverage
98113
${{ steps.test.outputs.total }}
114+
${{ steps.annotate.outputs.total }}
115+
<details><summary>Coverage of changed lines</summary>
116+
117+
${{ steps.annotate.outputs.rep }}
118+
119+
</details>
120+
99121
<details><summary>Coverage diff with base branch</summary>
100122
101-
```diff
102-
${{ steps.test.outputs.diff }}
103-
```
123+
${{ steps.annotate.outputs.diff }}
124+
104125
</details>
105126
127+
- name: Store base coverage
128+
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }}
129+
run: cp unit.txt unit-base.txt
130+
106131
- name: Upload code coverage
107132
if: matrix.go-version == env.COV_GO_VERSION
108133
uses: codecov/codecov-action@v1

.golangci.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ linters:
3838
- tagliatelle
3939
- errname
4040
- ireturn
41+
- exhaustruct
42+
- nonamedreturns
43+
- nosnakecase
44+
- structcheck
45+
- varcheck
46+
- deadcode
47+
- testableexamples
48+
- dupword
49+
- depguard
50+
- tagalign
4151

4252
issues:
4353
exclude-use-default: false
@@ -49,5 +59,13 @@ issues:
4959
- noctx
5060
- funlen
5161
- dupl
62+
- structcheck
63+
- unused
64+
- unparam
65+
- nosnakecase
5266
path: "_test.go"
67+
- linters:
68+
- errcheck # Error checking omitted for brevity.
69+
- gosec
70+
path: "example_"
5371

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#GOLANGCI_LINT_VERSION := "v1.45.2" # Optional configuration to pinpoint golangci-lint version.
1+
#GOLANGCI_LINT_VERSION := "v1.56.2" # 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

0 commit comments

Comments
 (0)