mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 13:44:05 -08:00
ci: check generated parser code before running unit tests
Check that the generated parser code is consistent with the input definition. Remove the file before re-generating to make sure that missing goyacc is not effecting the check. Fixes: #7488 Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
This commit is contained in:
parent
1dd0bff4f1
commit
965f507db5
13
.github/workflows/ci.yml
vendored
13
.github/workflows/ci.yml
vendored
|
@ -143,6 +143,19 @@ jobs:
|
||||||
with:
|
with:
|
||||||
parallelism: 12
|
parallelism: 12
|
||||||
thread: ${{ matrix.thread }}
|
thread: ${{ matrix.thread }}
|
||||||
|
check_generated_parser:
|
||||||
|
name: Check generated parser
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
|
||||||
|
- name: Install Go
|
||||||
|
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
|
||||||
|
with:
|
||||||
|
cache: false
|
||||||
|
go-version: 1.22.x
|
||||||
|
- name: Run goyacc and check for diff
|
||||||
|
run: make install-goyacc check-generated-parser
|
||||||
golangci:
|
golangci:
|
||||||
name: golangci-lint
|
name: golangci-lint
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
27
Makefile
27
Makefile
|
@ -24,6 +24,7 @@ TSDB_BENCHMARK_DATASET ?= ./tsdb/testdata/20kseries.json
|
||||||
TSDB_BENCHMARK_OUTPUT_DIR ?= ./benchout
|
TSDB_BENCHMARK_OUTPUT_DIR ?= ./benchout
|
||||||
|
|
||||||
GOLANGCI_LINT_OPTS ?= --timeout 4m
|
GOLANGCI_LINT_OPTS ?= --timeout 4m
|
||||||
|
GOYACC_VERSION ?= v0.6.0
|
||||||
|
|
||||||
include Makefile.common
|
include Makefile.common
|
||||||
|
|
||||||
|
@ -78,24 +79,42 @@ assets-tarball: assets
|
||||||
@echo '>> packaging assets'
|
@echo '>> packaging assets'
|
||||||
scripts/package_assets.sh
|
scripts/package_assets.sh
|
||||||
|
|
||||||
# We only want to generate the parser when there's changes to the grammar.
|
|
||||||
.PHONY: parser
|
.PHONY: parser
|
||||||
parser:
|
parser:
|
||||||
@echo ">> running goyacc to generate the .go file."
|
@echo ">> running goyacc to generate the .go file."
|
||||||
ifeq (, $(shell command -v goyacc 2> /dev/null))
|
ifeq (, $(shell command -v goyacc 2> /dev/null))
|
||||||
@echo "goyacc not installed so skipping"
|
@echo "goyacc not installed so skipping"
|
||||||
@echo "To install: go install golang.org/x/tools/cmd/goyacc@v0.6.0"
|
@echo "To install: \"go install golang.org/x/tools/cmd/goyacc@$(GOYACC_VERSION)\" or run \"make install-goyacc\""
|
||||||
else
|
else
|
||||||
goyacc -l -o promql/parser/generated_parser.y.go promql/parser/generated_parser.y
|
$(MAKE) promql/parser/generated_parser.y.go
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
promql/parser/generated_parser.y.go: promql/parser/generated_parser.y
|
||||||
|
@echo ">> running goyacc to generate the .go file."
|
||||||
|
@goyacc -l -o promql/parser/generated_parser.y.go promql/parser/generated_parser.y
|
||||||
|
|
||||||
|
.PHONY: clean-parser
|
||||||
|
clean-parser:
|
||||||
|
@echo ">> cleaning generated parser"
|
||||||
|
@rm -f promql/parser/generated_parser.y.go
|
||||||
|
|
||||||
|
.PHONY: check-generated-parser
|
||||||
|
check-generated-parser: clean-parser promql/parser/generated_parser.y.go
|
||||||
|
@echo ">> checking generated parser"
|
||||||
|
@git diff --exit-code -- promql/parser/generated_parser.y.go || (echo "Generated parser is out of date. Please run 'make parser' and commit the changes." && false)
|
||||||
|
|
||||||
|
.PHONY: install-goyacc
|
||||||
|
install-goyacc:
|
||||||
|
@echo ">> installing goyacc $(GOYACC_VERSION)"
|
||||||
|
@go install golang.org/x/tools/cmd/goyacc@$(GOYACC_VERSION)
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
# If we only want to only test go code we have to change the test target
|
# If we only want to only test go code we have to change the test target
|
||||||
# which is called by all.
|
# which is called by all.
|
||||||
ifeq ($(GO_ONLY),1)
|
ifeq ($(GO_ONLY),1)
|
||||||
test: common-test check-go-mod-version
|
test: common-test check-go-mod-version
|
||||||
else
|
else
|
||||||
test: common-test ui-build-module ui-test ui-lint check-go-mod-version
|
test: check-generated-parser common-test ui-build-module ui-test ui-lint check-go-mod-version
|
||||||
endif
|
endif
|
||||||
|
|
||||||
.PHONY: npm_licenses
|
.PHONY: npm_licenses
|
||||||
|
|
Loading…
Reference in a new issue