From 22f28a996c141f4c6b6302c368257fc6c872fe10 Mon Sep 17 00:00:00 2001 From: ashmrtn <3891298+ashmrtn@users.noreply.github.com> Date: Fri, 9 Feb 2024 12:09:59 -0800 Subject: [PATCH] Add CI check to make sure generated code is checked in (#11) * Minor fixes for tools stuff * Fix the package for the tools.go file * Make it easier to install generate tools by making the install commands generate commands in the tools file * Add CI step to check for generated code Have a CI step that will fail if there's uncommitted generated changes. * Remove erroring generate statement Relevant code no longer requires the use of the stringer package. * Add uncommitted generated code to fix lint error * Fix action lint error * Remove unused type --- .github/workflows/ci.yml | 18 ++++++++++++++++++ .../m365/collection/site/collection.go | 9 --------- src/internal/m365/support/operation_string.go | 5 +++-- src/pkg/filters/filters.go | 1 - src/pkg/path/servicetype_string.go | 4 ++-- src/pkg/selectors/service_string.go | 5 +++-- src/tools.go | 9 ++++++++- 7 files changed, 34 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5f6336507..66a6aa520 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -475,6 +475,24 @@ jobs: with: go-version-file: src/go.mod + - name: Run go generate + run: | + # Install tools used for generate commands in the repo + go generate tools.go + # Actually run generate commands in the repo. + go generate ./... + + - name: Check for uncommitted changes from generated code + run: | + changes=$(git status --porcelain) + if [[ -n "$changes" ]]; then + echo "Uncommitted changes detected:" + echo "$changes" + echo "Run 'go generate' from backend/functions and commit the changes." + exit 1 + fi + echo "No uncommitted changes detected." + - name: Go Lint uses: golangci/golangci-lint-action@v3 with: diff --git a/src/internal/m365/collection/site/collection.go b/src/internal/m365/collection/site/collection.go index 6126b8761..be2c7662e 100644 --- a/src/internal/m365/collection/site/collection.go +++ b/src/internal/m365/collection/site/collection.go @@ -33,21 +33,12 @@ import ( "github.com/alcionai/canario/src/pkg/services/m365/api/graph" ) -type DataCategory int - // channel sizes const ( collectionChannelBufferSize = 50 fetchChannelSize = 5 ) -//go:generate stringer -type=DataCategory -const ( - Unknown DataCategory = 0 - List DataCategory = 1 - Pages DataCategory = 2 -) - var ( _ data.BackupCollection = &prefetchCollection{} _ data.BackupCollection = &lazyFetchCollection{} diff --git a/src/internal/m365/support/operation_string.go b/src/internal/m365/support/operation_string.go index 075f95b88..c94aa5c53 100644 --- a/src/internal/m365/support/operation_string.go +++ b/src/internal/m365/support/operation_string.go @@ -11,11 +11,12 @@ func _() { _ = x[OpUnknown-0] _ = x[Backup-1] _ = x[Restore-2] + _ = x[Export-3] } -const _Operation_name = "OpUnknownBackupRestore" +const _Operation_name = "OpUnknownBackupRestoreExport" -var _Operation_index = [...]uint8{0, 9, 15, 22} +var _Operation_index = [...]uint8{0, 9, 15, 22, 28} func (i Operation) String() string { if i < 0 || i >= Operation(len(_Operation_index)-1) { diff --git a/src/pkg/filters/filters.go b/src/pkg/filters/filters.go index e837e2053..32b49902a 100644 --- a/src/pkg/filters/filters.go +++ b/src/pkg/filters/filters.go @@ -13,7 +13,6 @@ import ( type comparator string -//go:generate stringer -type=comparator -linecomment const ( UnknownComparator comparator = "" // norm(a) == norm(b) diff --git a/src/pkg/path/servicetype_string.go b/src/pkg/path/servicetype_string.go index 24d0ca4a9..96a8672fe 100644 --- a/src/pkg/path/servicetype_string.go +++ b/src/pkg/path/servicetype_string.go @@ -21,9 +21,9 @@ func _() { _ = x[TeamsChatsMetadataService-10] } -const _ServiceType_name = "UnknownServiceexchangeonedrivesharepointexchangeMetadataonedriveMetadatasharepointMetadatagroupsgroupsMetadatachatschatsMetadata" +const _ServiceType_name = "UnknownServiceexchangeonedrivesharepointexchangeMetadataonedriveMetadatasharepointMetadatagroupsgroupsMetadatateamsChatsteamsChatsMetadata" -var _ServiceType_index = [...]uint8{0, 14, 22, 30, 40, 56, 72, 90, 96, 110, 115, 128} +var _ServiceType_index = [...]uint8{0, 14, 22, 30, 40, 56, 72, 90, 96, 110, 120, 138} func (i ServiceType) String() string { if i < 0 || i >= ServiceType(len(_ServiceType_index)-1) { diff --git a/src/pkg/selectors/service_string.go b/src/pkg/selectors/service_string.go index c20205128..e3760eb29 100644 --- a/src/pkg/selectors/service_string.go +++ b/src/pkg/selectors/service_string.go @@ -13,11 +13,12 @@ func _() { _ = x[ServiceOneDrive-2] _ = x[ServiceSharePoint-3] _ = x[ServiceGroups-4] + _ = x[ServiceTeamsChats-5] } -const _service_name = "Unknown ServiceExchangeOneDriveSharePointGroups" +const _service_name = "Unknown ServiceExchangeOneDriveSharePointGroupsTeamsChats" -var _service_index = [...]uint8{0, 15, 23, 31, 41, 47} +var _service_index = [...]uint8{0, 15, 23, 31, 41, 47, 57} func (i service) String() string { if i < 0 || i >= service(len(_service_index)-1) { diff --git a/src/tools.go b/src/tools.go index 3d7436fd1..ea4597340 100644 --- a/src/tools.go +++ b/src/tools.go @@ -1,7 +1,14 @@ //go:build tools // +build tools -package tools +package src + +// When adding a new tool, add the import for it here to make sure it gets a +// version in the go.mod file. Also add a go:generate statement here so that we +// can install all the tools for CI checks and local development just by running +// go generate tools.go. + +//go:generate go install golang.org/x/tools/cmd/stringer import ( _ "golang.org/x/tools/cmd/stringer"