Repository navigation
122 lines (104 loc) · 3.8 KB
/
Copy pathcheck-generated.yml
File metadata and controls
122 lines (104 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# Verify that generated code is up-to-date.
#
# Note that we run these checks regardless whether the input files have
# changed, because generated code can change in response to toolchain updates
# even if no files in the repository are modified.
#
# actions/setup-go runs after checkout (its cache key files must exist) and only
# when the check runs. Each job lists its own config files so the two jobs keep
# separate Go caches.
name: Check generated code
on:
pull_request:
push:
branches:
- master
- dev
permissions:
contents: read
# Branch creation/rename events can refer to the deleted old branch.
env:
GIT_DIFF: ${{ github.event_name == 'push' && github.event.created && 'all' || '' }}
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
check-mocks:
runs-on: ubuntu-26.04
steps:
- uses: actions/checkout@v7
- uses: technote-space/get-diff-action@v6
if: github.event_name != 'push' || !github.event.created
with:
# FILES matches bare file names only, so the workflow path goes in
# PATTERNS (minimatch globs) to re-run the check when it changes.
PATTERNS: |
**/*.go
.mockery.yaml
.github/workflows/check-generated.yml
- uses: actions/setup-go@v7.0.0
if: env.GIT_DIFF
with:
go-version: "1.27.3"
cache-dependency-path: |
go.sum
.mockery.yaml
.github/workflows/check-generated.yml
- name: "Check generated mocks"
if: env.GIT_DIFF
run: |
set -euo pipefail
readonly MOCKERY=3.8.1 # N.B. no leading "v"
curl -sL "https://github.com/vektra/mockery/releases/download/v${MOCKERY}/mockery_${MOCKERY}_Linux_x86_64.tar.gz" | tar -C /usr/local/bin -xzf -
make mockery 2>/dev/null
if ! git diff --exit-code ; then
echo ">> ERROR:"
echo ">>"
echo ">> Generated mocks require update (either Mockery or source files may have changed)."
echo ">> Ensure your tools are up-to-date, re-run 'make mockery' and update this PR."
echo ">>"
exit 1
fi
check-proto:
runs-on: ubuntu-26.04
steps:
- uses: actions/checkout@v7
- uses: technote-space/get-diff-action@v6
if: github.event_name != 'push' || !github.event.created
with:
PATTERNS: |
**/*.proto
buf.yaml
buf.gen.yaml
buf.lock
.github/workflows/check-generated.yml
- uses: actions/setup-go@v7.0.0
if: env.GIT_DIFF
with:
go-version: "1.27.3"
cache-dependency-path: |
go.sum
buf.yaml
buf.gen.yaml
buf.lock
.github/workflows/check-generated.yml
- name: "Check protobuf generated code"
if: env.GIT_DIFF
run: |
set -euo pipefail
# Install buf and gogo tools, so that differences that arise from
# toolchain differences are also caught.
readonly tools="$(mktemp -d)"
export PATH="${PATH}:${tools}/bin"
export GOBIN="${tools}/bin"
go install github.com/bufbuild/buf/cmd/buf
go install github.com/cosmos/gogoproto/protoc-gen-gogofaster
make proto-gen
if ! git diff --stat --exit-code ; then
echo ">> ERROR:"
echo ">>"
echo ">> Protobuf generated code requires update (either tools or .proto files may have changed)."
echo ">> Ensure your tools are up-to-date, re-run 'make proto-gen' and update this PR."
echo ">>"
exit 1
fi