diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ec9e4e6886..23efe285a6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -73,7 +73,7 @@ jobs: name: Create matrix id: scripts run: | - scripts=$(jq -ncR '[inputs]' <<< "$(ls -I .validate -I all -I default -I dco -I golangci-lint.yml -I yamllint.yaml -A ./hack/validate/)") + scripts=$(cd ./hack/validate && jq -nc '$ARGS.positional - ["all", "default", "dco"] | map(select(test("[.]")|not)) + ["generate-files"]' --args *) echo "matrix=$scripts" >> $GITHUB_OUTPUT - name: Show matrix diff --git a/Makefile b/Makefile index 7d7f5404c2..dc95ad7eac 100644 --- a/Makefile +++ b/Makefile @@ -214,6 +214,11 @@ test-unit: build ## run the unit tests validate: build ## validate DCO, Seccomp profile generation, gofmt,\n./pkg/ isolation, golint, tests, tomls, go vet and vendor $(DOCKER_RUN_DOCKER) hack/validate/all +validate-generate-files: + $(BUILD_CMD) --target "validate" \ + --output "type=cacheonly" \ + --file "./hack/dockerfiles/generate-files.Dockerfile" . + validate-%: build ## validate specific check $(DOCKER_RUN_DOCKER) hack/validate/$* @@ -235,3 +240,12 @@ swagger-docs: ## preview the API documentation -e 'REDOC_OPTIONS=hide-hostname="true" lazy-rendering' \ -p $(SWAGGER_DOCS_PORT):80 \ bfirsh/redoc:1.14.0 + +.PHONY: generate-files +generate-files: + $(eval $@_TMP_OUT := $(shell mktemp -d -t moby-output.XXXXXXXXXX)) + $(BUILD_CMD) --target "update" \ + --output "type=local,dest=$($@_TMP_OUT)" \ + --file "./hack/dockerfiles/generate-files.Dockerfile" . + cp -R "$($@_TMP_OUT)"/. . + rm -rf "$($@_TMP_OUT)"/* diff --git a/hack/dockerfiles/generate-files.Dockerfile b/hack/dockerfiles/generate-files.Dockerfile new file mode 100644 index 0000000000..40d52f5918 --- /dev/null +++ b/hack/dockerfiles/generate-files.Dockerfile @@ -0,0 +1,73 @@ +# syntax=docker/dockerfile:1 + +ARG GO_VERSION=1.20.4 +ARG BASE_DEBIAN_DISTRO="bullseye" +ARG PROTOC_VERSION=3.11.4 + +# protoc is dynamically linked to glibc so can't use alpine base +FROM golang:${GO_VERSION}-${BASE_DEBIAN_DISTRO} AS base +RUN apt-get update && apt-get --no-install-recommends install -y git unzip +ARG PROTOC_VERSION +ARG TARGETOS +ARG TARGETARCH +RUN <&2 'ERROR: The result of "go generate" differs. Please update with "make generate-files"' + echo "$diff" + exit 1 + fi +EOT