diff --git a/Makefile b/Makefile index 3d53ca4dcfc..1b73564210f 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/contribute/feature-toggles.md b/contribute/feature-toggles.md index 79e0178392d..131834bcaf8 100644 --- a/contribute/feature-toggles.md +++ b/contribute/feature-toggles.md @@ -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 diff --git a/pkg/services/featuremgmt/registry.go b/pkg/services/featuremgmt/registry.go index ff11f1f2737..7d0521cc8ce 100644 --- a/pkg/services/featuremgmt/registry.go +++ b/pkg/services/featuremgmt/registry.go @@ -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