From 069c34302d1d1d025dd2e024a6ac8628ac276220 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Wed, 7 Feb 2024 16:47:16 -0800 Subject: [PATCH 1/2] schema/validate: move to a separate module The old way of building the validator (go get $DEPS && go build) no longer works since Go 1.22: go: go.mod file not found in current directory or any parent directory. 'go get' is no longer supported outside a module. Move the validator sources into their own directory, with own go.mod. This fixes the build, makes it possible to use go install, and, since it is a separate module, its dependencies (gojsonschema) won't end up as dependencies of github.com/opencontainers/runtime-spec once it gets its own go.mod. Fix build and test commands in README and Makefile accordingly (and there's no need to run go get any more). Signed-off-by: Kir Kolyshkin --- .gitignore | 2 +- schema/Makefile | 13 +++++++------ schema/README.md | 13 +++---------- schema/validate/go.mod | 10 ++++++++++ schema/validate/go.sum | 13 +++++++++++++ schema/{ => validate}/validate.go | 0 6 files changed, 34 insertions(+), 17 deletions(-) create mode 100644 schema/validate/go.mod create mode 100644 schema/validate/go.sum rename schema/{ => validate}/validate.go (100%) diff --git a/.gitignore b/.gitignore index f9663c923..9882b7675 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ output -schema/validate +schema/validate/validate version.md diff --git a/schema/Makefile b/schema/Makefile index fe676ae66..3cb1c6925 100644 --- a/schema/Makefile +++ b/schema/Makefile @@ -1,5 +1,6 @@ GOOD_TESTS = $(wildcard test/good/*.json) BAD_TESTS = $(wildcard test/bad/*.json) +VALIDATE = validate/validate default: validate @@ -14,9 +15,8 @@ fmt: find . -name '*.json' -exec bash -c 'jq --indent 4 -M . {} > xx && mv xx {} || echo "skipping invalid {}"' \; .PHONY: validate -validate: validate.go - GO111MODULE=auto go get github.com/xeipuuv/gojsonschema - GO111MODULE=auto go build ./validate.go +validate: + cd validate && go build test: validate $(TESTS) for TYPE in $$(ls test); \ @@ -25,7 +25,7 @@ test: validate $(TESTS) for FILE in $$(ls "test/$${TYPE}/good"); \ do \ echo " testing test/$${TYPE}/good/$${FILE}"; \ - if ./validate "$${TYPE}-schema.json" "test/$${TYPE}/good/$${FILE}" ; \ + if $(VALIDATE) "$${TYPE}-schema.json" "test/$${TYPE}/good/$${FILE}" ; \ then \ echo " received expected validation success" ; \ else \ @@ -36,7 +36,7 @@ test: validate $(TESTS) for FILE in $$(ls "test/$${TYPE}/bad"); \ do \ echo " testing test/$${TYPE}/bad/$${FILE}"; \ - if ./validate "$${TYPE}-schema.json" "test/$${TYPE}/bad/$${FILE}" ; \ + if $(VALIDATE) "$${TYPE}-schema.json" "test/$${TYPE}/bad/$${FILE}" ; \ then \ echo " received unexpected validation success" ; \ exit 1; \ @@ -46,5 +46,6 @@ test: validate $(TESTS) done; \ done +.PHONY: clean clean: - rm -f validate + rm -f validate/validate diff --git a/schema/README.md b/schema/README.md index 831ee142a..075bc59f4 100644 --- a/schema/README.md +++ b/schema/README.md @@ -15,7 +15,7 @@ The layout of the files is as follows: * [defs.json](defs.json) - definitions for general types * [defs-linux.json](defs-linux.json) - definitions for Linux-specific types * [defs-windows.json](defs-windows.json) - definitions for Windows-specific types -* [validate.go](validate.go) - validation utility source code +* [validate](validate) - validation utility source code directory ## Utility @@ -23,13 +23,6 @@ The layout of the files is as follows: There is also included a simple utility for facilitating validation. To build it: -```bash -go get github.com/xeipuuv/gojsonschema -go build ./validate.go -``` - -Or you can just use make command to create the utility: - ```bash make validate ``` @@ -37,11 +30,11 @@ make validate Then use it like: ```bash -./validate config-schema.json /config.json +./validate/validate config-schema.json /config.json ``` Or like: ```bash -./validate https://raw.githubusercontent.com/opencontainers/runtime-spec//schema/config-schema.json /config.json +./validate/validate https://raw.githubusercontent.com/opencontainers/runtime-spec//schema/config-schema.json /config.json ``` diff --git a/schema/validate/go.mod b/schema/validate/go.mod new file mode 100644 index 000000000..363c711f7 --- /dev/null +++ b/schema/validate/go.mod @@ -0,0 +1,10 @@ +module github.com/opencontainers/runtime-spec/schema/validate + +go 1.21 + +require github.com/xeipuuv/gojsonschema v1.2.0 + +require ( + github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect + github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect +) diff --git a/schema/validate/go.sum b/schema/validate/go.sum new file mode 100644 index 000000000..ebda4aba2 --- /dev/null +++ b/schema/validate/go.sum @@ -0,0 +1,13 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c= +github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= +github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0= +github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= +github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74= +github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= diff --git a/schema/validate.go b/schema/validate/validate.go similarity index 100% rename from schema/validate.go rename to schema/validate/validate.go From 222496072a06d61eea7d3930f8db33bb4e943ba3 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Sun, 11 Oct 2026 16:09:04 -0700 Subject: [PATCH 2/2] Add go.mod Since there is no go.mod, CI has to create one on the fly (using "go mod init" and "go get"). In addition, "make docs" no longer works with Go 1.23+, since "go run ./.tool/version-doc.go" requires a module. Add go.mod (with no dependencies, and the go directive set to the minimal Go version we support and test with), and remove the go.mod creation from CI. Since schema/validate is now a separate module, run golangci-lint for it separately. To avoid using golangci-lint-action twice, bump it to v9 and use its install-only mode, running golangci-lint directly. Fixes #1280. Signed-off-by: Kir Kolyshkin --- .github/workflows/build.yml | 17 ++++++++--------- go.mod | 3 +++ 2 files changed, 11 insertions(+), 9 deletions(-) create mode 100644 go.mod diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2a570be19..62431b3c9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -30,17 +30,16 @@ jobs: with: go-version: ${{ matrix.go }} - - name: create go.mod - run: | - # Fix for "cannot find main module" issue - go mod init github.com/opencontainers/runtime-spec - - go get -d ./schema/... - - - name: run golangci-lint - uses: golangci/golangci-lint-action@v8 + - name: install golangci-lint + uses: golangci/golangci-lint-action@v9 with: version: v2.14 + install-only: true + + - name: run golangci-lint + run: | + golangci-lint run + cd schema/validate && golangci-lint run --path-prefix schema/validate - name: run tests run: | diff --git a/go.mod b/go.mod new file mode 100644 index 000000000..ee1381413 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/opencontainers/runtime-spec + +go 1.21