web/ui: Add make targets for PromQL function generation.

Add make targets to generate and check PromQL function signatures and
documentation for the Mantine UI. The generate-promql-functions target
runs the Go generators and automatically lints the output files. The
check-generated-promql-functions target verifies that generated files
are up to date, similar to check-generated-parser.

Fix the gen_functions_list generator to output properly formatted
TypeScript code with correct indentation and semicolons.

Add check-generated-promql-functions to the UI tests CI job to ensure
generated files stay in sync with upstream changes.

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
pull/17713/head
Julien Pivotto 3 weeks ago
parent b8b55d0f43
commit 030cb5e4ee
  1. 18
      .github/workflows/ci.yml
  2. 14
      Makefile
  3. 4
      web/ui/mantine-ui/src/promql/tools/gen_functions_list/main.go

@ -202,20 +202,20 @@ jobs:
if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
run: exit 1
check_generated_parser:
name: Check generated parser
name: Check generated parser and functions
runs-on: ubuntu-latest
container:
image: quay.io/prometheus/golang-builder:1.25-base
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- name: Install Go
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
- uses: prometheus/promci@c0916f0a41f13444612a8f0f5e700ea34edd7c19 # v0.5.3
- uses: ./.github/promci/actions/setup_environment
with:
cache: false
go-version: 1.25.x
- name: Run goyacc and check for diff
run: make install-goyacc check-generated-parser
enable_npm: true
- run: make install-goyacc check-generated-parser
- run: make check-generated-promql-functions
golangci:
name: golangci-lint
runs-on: ubuntu-latest

@ -79,6 +79,20 @@ ui-lint:
# new Mantine-based UI is fully integrated and the old app can be removed.
cd $(UI_PATH)/react-app && npm run lint
.PHONY: generate-promql-functions
generate-promql-functions: ui-install
@echo ">> generating PromQL function signatures"
@cd $(UI_PATH)/mantine-ui/src/promql/tools && $(GO) run ./gen_functions_list > ../functionSignatures.ts
@echo ">> generating PromQL function documentation"
@cd $(UI_PATH)/mantine-ui/src/promql/tools && $(GO) run ./gen_functions_docs $(CURDIR)/docs/querying/functions.md > ../functionDocs.tsx
@echo ">> formatting generated files"
@cd $(UI_PATH)/mantine-ui && npx prettier --write --print-width 120 src/promql/functionSignatures.ts src/promql/functionDocs.tsx
.PHONY: check-generated-promql-functions
check-generated-promql-functions: generate-promql-functions
@echo ">> checking generated PromQL functions"
@git diff --exit-code -- $(UI_PATH)/mantine-ui/src/promql/functionSignatures.ts $(UI_PATH)/mantine-ui/src/promql/functionDocs.tsx || (echo "Generated PromQL function files are out of date. Please run 'make generate-promql-functions' and commit the changes." && false)
.PHONY: assets
ifndef SKIP_UI_BUILD
assets: check-node-version ui-install ui-build

@ -41,10 +41,10 @@ func main() {
sort.Strings(fnNames)
fmt.Println(`import { valueType, Func } from './ast';
export const functionSignatures: Record<string, Func> = {`)
export const functionSignatures: Record<string, Func> = {`)
for _, fnName := range fnNames {
fn := parser.Functions[fnName]
fmt.Printf(" %s: { name: '%s', argTypes: [%s], variadic: %d, returnType: %s },\n", fn.Name, fn.Name, formatValueTypes(fn.ArgTypes), fn.Variadic, formatValueType(fn.ReturnType))
}
fmt.Println("}")
fmt.Println("};")
}

Loading…
Cancel
Save