Generate stringer files automatically #841

Merged
g4s8 merged 6 commits from 543-stringer-generate into main 2021-11-08 08:38:55 -06:00
3 changed files with 32 additions and 0 deletions
Showing only changes of commit f633706986 - Show all commits

View File

@ -105,3 +105,19 @@ jobs:
sudo ./script/build-libgit2.sh --static --system sudo ./script/build-libgit2.sh --static --system
- name: Test - name: Test
run: go test --count=1 --tags "static,system_libgit2" ./... run: go test --count=1 --tags "static,system_libgit2" ./...
check-generate:
name: Check generated files were not modified
runs-on: ubuntu-20.04
steps:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: '1.17'
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Generate files
run: make generate
- name: Check nothing changed
run: git diff --quiet --exit-code || (echo "detected changes after generate" && exit 1)
lhchavez commented 2021-11-08 08:27:42 -06:00 (Migrated from github.com)
Review
        sudo apt-get install -y --no-install-recommends libssh2-1-dev
        go install golang.org/x/tools/cmd/stringer@latest

haha, stringer wasn't installed! (and we may need to tweak PATH unless GH does it for us)

```suggestion sudo apt-get install -y --no-install-recommends libssh2-1-dev go install golang.org/x/tools/cmd/stringer@latest ``` haha, `stringer` wasn't installed! (and we may need to tweak `PATH` unless GH does it for us)

View File

@ -53,3 +53,17 @@ test-static: static-build/install/lib/libgit2.a
install-static: static-build/install/lib/libgit2.a install-static: static-build/install/lib/libgit2.a
go install --tags "static" ./... go install --tags "static" ./...
define _gen_file
rm -fr _obj
go tool cgo $(1)
find ./_obj -type f ! -name '*.go' -exec rm {} \;
mv ./_obj/_cgo_gotypes.go ./_obj/cgo_gotypes.go
cd ./_obj && go generate ./...
find ./_obj -type f -name '*_string.go' -exec mv -v {} . \;
rm -fr ./_obj
endef
generate:
$(call _gen_file,diff.go)
$(call _gen_file,git.go)

2
git.go
View File

@ -14,6 +14,7 @@ import (
"unsafe" "unsafe"
) )
//go:generate stringer -type ErrorClass -trimprefix ErrorClass -tags static
type ErrorClass int type ErrorClass int
const ( const (
@ -48,6 +49,7 @@ const (
ErrorClassPatch ErrorClass = C.GIT_ERROR_PATCH ErrorClassPatch ErrorClass = C.GIT_ERROR_PATCH
) )
//go:generate stringer -type ErrorCode -trimprefix ErrorCode -tags static
type ErrorCode int type ErrorCode int
const ( const (