Build: Add "gen-feature-toggles" Makefile target (#84803)

* Add Makefile target "make gen-feature-toggles" to generate feature toggles files

* Better output for gen-feature-toggles
This commit is contained in:
Giuseppe Guerra 2024-03-21 12:04:49 +01:00 committed by GitHub
parent b23541c298
commit 3387132b9b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 2 deletions

View File

@ -7,7 +7,7 @@ WIRE_TAGS = "oss"
-include local/Makefile
include .bingo/Variables.mk
.PHONY: all deps-go deps-js deps build-go build-backend build-server build-cli build-js build build-docker-full build-docker-full-ubuntu lint-go golangci-lint test-go test-js gen-ts test run run-frontend clean devenv devenv-down protobuf drone help gen-go gen-cue fix-cue
.PHONY: all deps-go deps-js deps build-go build-backend build-server build-cli build-js build build-docker-full build-docker-full-ubuntu lint-go golangci-lint test-go test-js gen-ts test run run-frontend clean devenv devenv-down protobuf drone help gen-go gen-cue fix-cue gen-feature-toggles
GO = go
GO_FILES ?= ./pkg/... ./pkg/apiserver/... ./pkg/apimachinery/... ./pkg/promlib/...
@ -106,6 +106,17 @@ gen-cue: ## Do all CUE/Thema code generation
go generate ./kinds/gen.go
go generate ./public/app/plugins/gen.go
gen-feature-toggles:
## First go test run fails because it will re-generate the feature toggles.
## Second go test run will compare the generated files and pass.
@echo "generate feature toggles"
go test -v ./pkg/services/featuremgmt/... > /dev/null 2>&1; \
if [ $$? -eq 0 ]; then \
echo "feature toggles already up-to-date"; \
else \
go test -v ./pkg/services/featuremgmt/...; \
fi
gen-go: $(WIRE)
@echo "generate go files"
$(WIRE) gen -tags $(WIRE_TAGS) ./pkg/server

View File

@ -5,7 +5,7 @@ This guide helps you get started adding your feature behind a feature flag in Gr
## Steps to adding a feature toggle
1. Define the feature toggle in [registry.go](../pkg/services/featuremgmt/registry.go). To see what each feature stage means, look at the comments [here](../pkg/services/featuremgmt/features.go). If you are a community member, use the [CODEOWNERS](../.github/CODEOWNERS) file to determine which team owns the package you are updating.
2. Run the go tests mentioned at the top of [this file](../pkg/services/featuremgmt/toggles_gen.go). This will generate all the additional files needed: `toggles_gen` for the backend, `grafana-data` for the frontend, and docs. You can run the test by running `go test ./pkg/services/featuremgmt/...`. This will say the tests failed the first time, but it will have generated the right code. If you re-run the tests, it will pass.
2. Run the go tests mentioned at the top of [this file](../pkg/services/featuremgmt/toggles_gen.go). This will generate all the additional files needed: `toggles_gen` for the backend, `grafana-data` for the frontend, and docs. You can run the test by running `make gen-feature-toggles`.
## How to use it in the code

View File

@ -3,6 +3,8 @@
// Then run tests in:
// pkg/services/featuremgmt/toggles_gen_test.go
// twice to generate and validate the feature flag files
//
// Alternatively, use `make gen-feature-toggles`
package featuremgmt