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/.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/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 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