Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate stringer files automatically #841

Merged
merged 6 commits into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,26 @@ jobs:
sudo ./script/build-libgit2.sh --static --system
- name: Test
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: Install libgit2 build dependencies
run: |
git submodule update --init
sudo apt-get install -y --no-install-recommends libssh2-1-dev
g4s8 marked this conversation as resolved.
Show resolved Hide resolved
go install golang.org/x/tools/cmd/stringer@latest
- name: Generate files
g4s8 marked this conversation as resolved.
Show resolved Hide resolved
run: |
export PATH=$(go env GOPATH)/bin:$PATH
make generate
- name: Check nothing changed
run: git diff --quiet --exit-code || (echo "detected changes after generate" ; git status ; exit 1)
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ TEST_ARGS ?= --count=1

default: test


generate: static-build/install/lib/libgit2.a
go generate --tags "static" ./...

# System library
# ==============
# This uses whatever version of libgit2 can be found in the system.
Expand Down
2 changes: 2 additions & 0 deletions git.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"unsafe"
)

//go:generate stringer -type ErrorClass -trimprefix ErrorClass -tags static
type ErrorClass int

const (
Expand Down Expand Up @@ -48,6 +49,7 @@ const (
ErrorClassPatch ErrorClass = C.GIT_ERROR_PATCH
)

//go:generate stringer -type ErrorCode -trimprefix ErrorCode -tags static
type ErrorCode int

const (
Expand Down