From c3c4116dc0153734ba1f1323f92e35dd4c943f0f Mon Sep 17 00:00:00 2001 From: Daisuke Maki Date: Tue, 17 Feb 2026 18:03:46 +0900 Subject: [PATCH] Check for generated files --- .github/workflows/ci.yml | 31 +++++++++++++++++++ hub/paging.go | 2 +- ...e_string.go => paging_request_type_gen.go} | 2 +- peco.go | 2 +- stringer_vertical_anchor.go | 17 ---------- vertical_anchor_gen.go | 25 +++++++++++++++ 6 files changed, 59 insertions(+), 20 deletions(-) rename hub/{pagingrequesttype_string.go => paging_request_type_gen.go} (90%) delete mode 100644 stringer_vertical_anchor.go create mode 100644 vertical_anchor_gen.go diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e13607e..f38ee33 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,3 +29,34 @@ jobs: run: make test - name: Build all targets run: make all + + generate: + runs-on: ubuntu-latest + name: Check generated code + steps: + - name: Checkout repository + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - name: Cache Go modules + uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - name: Setup Go + uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0 + with: + go-version: stable + check-latest: true + - name: Install stringer + run: go install golang.org/x/tools/cmd/stringer@latest + - name: Run go generate + run: go generate ./... + - name: Check for uncommitted changes + run: | + if ! git diff --exit-code; then + echo "::error::Generated code is out of date. Run 'go generate ./...' and commit the result." + exit 1 + fi diff --git a/hub/paging.go b/hub/paging.go index a7e2c22..d7d4702 100644 --- a/hub/paging.go +++ b/hub/paging.go @@ -1,4 +1,4 @@ -//go:generate stringer -type PagingRequestType +//go:generate stringer -type PagingRequestType -output paging_request_type_gen.go package hub diff --git a/hub/pagingrequesttype_string.go b/hub/paging_request_type_gen.go similarity index 90% rename from hub/pagingrequesttype_string.go rename to hub/paging_request_type_gen.go index ca7f7af..91c86cc 100644 --- a/hub/pagingrequesttype_string.go +++ b/hub/paging_request_type_gen.go @@ -1,4 +1,4 @@ -// Code generated by "stringer -type PagingRequestType"; DO NOT EDIT. +// Code generated by "stringer -type PagingRequestType -output paging_request_type_gen.go"; DO NOT EDIT. package hub diff --git a/peco.go b/peco.go index 9f1133f..571888e 100644 --- a/peco.go +++ b/peco.go @@ -1,4 +1,4 @@ -//go:generate stringer -type VerticalAnchor -output stringer_vertical_anchor.go . +//go:generate stringer -type VerticalAnchor -output vertical_anchor_gen.go . package peco diff --git a/stringer_vertical_anchor.go b/stringer_vertical_anchor.go deleted file mode 100644 index 74986d9..0000000 --- a/stringer_vertical_anchor.go +++ /dev/null @@ -1,17 +0,0 @@ -// Code generated by "stringer -type VerticalAnchor -output stringer_vertical_anchor.go ."; DO NOT EDIT. - -package peco - -import "fmt" - -const _VerticalAnchor_name = "AnchorTopAnchorBottom" - -var _VerticalAnchor_index = [...]uint8{0, 9, 21} - -func (i VerticalAnchor) String() string { - i -= 1 - if i < 0 || i >= VerticalAnchor(len(_VerticalAnchor_index)-1) { - return fmt.Sprintf("VerticalAnchor(%d)", i+1) - } - return _VerticalAnchor_name[_VerticalAnchor_index[i]:_VerticalAnchor_index[i+1]] -} diff --git a/vertical_anchor_gen.go b/vertical_anchor_gen.go new file mode 100644 index 0000000..ee34e78 --- /dev/null +++ b/vertical_anchor_gen.go @@ -0,0 +1,25 @@ +// Code generated by "stringer -type VerticalAnchor -output vertical_anchor_gen.go ."; DO NOT EDIT. + +package peco + +import "strconv" + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[AnchorTop-1] + _ = x[AnchorBottom-2] +} + +const _VerticalAnchor_name = "AnchorTopAnchorBottom" + +var _VerticalAnchor_index = [...]uint8{0, 9, 21} + +func (i VerticalAnchor) String() string { + idx := int(i) - 1 + if i < 1 || idx >= len(_VerticalAnchor_index)-1 { + return "VerticalAnchor(" + strconv.FormatInt(int64(i), 10) + ")" + } + return _VerticalAnchor_name[_VerticalAnchor_index[idx]:_VerticalAnchor_index[idx+1]] +}