Skip to content

Commit a964575

Browse files
lhchavezg4s8
andauthored
Generate stringer files automatically (libgit2#841) (libgit2#865)
Added `stringer` annotations to `git.go` for `ErrorClass` and `ErrorCode`. Added `generate` rule for `Makefile` to generate string representations for these types (first building cgo files in `_obj` dir to get C constants). Finally, updated `ci` actions workflow to check that generated files are up to date. Fixes: libgit2#543 (cherry picked from commit 5e35338) Co-authored-by: Kirill <[email protected]>
1 parent a6446ac commit a964575

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

.github/workflows/ci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,26 @@ jobs:
106106
sudo ./script/build-libgit2.sh --static --system
107107
- name: Test
108108
run: go test --count=1 --tags "static,system_libgit2" ./...
109+
110+
check-generate:
111+
name: Check generated files were not modified
112+
runs-on: ubuntu-20.04
113+
steps:
114+
- name: Set up Go
115+
uses: actions/setup-go@v1
116+
with:
117+
go-version: '1.17'
118+
id: go
119+
- name: Check out code into the Go module directory
120+
uses: actions/checkout@v2
121+
- name: Install libgit2 build dependencies
122+
run: |
123+
git submodule update --init
124+
sudo apt-get install -y --no-install-recommends libssh2-1-dev
125+
go install golang.org/x/tools/cmd/stringer@latest
126+
- name: Generate files
127+
run: |
128+
export PATH=$(go env GOPATH)/bin:$PATH
129+
make generate
130+
- name: Check nothing changed
131+
run: git diff --quiet --exit-code || (echo "detected changes after generate" ; git status ; exit 1)

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ TEST_ARGS ?= --count=1
22

33
default: test
44

5+
6+
generate: static-build/install/lib/libgit2.a
7+
go generate --tags "static" ./...
8+
59
# System library
610
# ==============
711
# This uses whatever version of libgit2 can be found in the system.

git.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"unsafe"
1515
)
1616

17+
//go:generate stringer -type ErrorClass -trimprefix ErrorClass -tags static
1718
type ErrorClass int
1819

1920
const (
@@ -48,6 +49,7 @@ const (
4849
ErrorClassPatch ErrorClass = C.GIT_ERROR_PATCH
4950
)
5051

52+
//go:generate stringer -type ErrorCode -trimprefix ErrorCode -tags static
5153
type ErrorCode int
5254

5355
const (

0 commit comments

Comments
 (0)