Skip to content

Commit

Permalink
schema/validate: fix build for Go 1.22
Browse files Browse the repository at this point in the history
The old way of building (go get $DEPS && go build) is no longer working
with 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.

To get dependencies, add go.mod.

To make it possible to use go install, move the sources into own
directory.

Finally, fix build and test commands in README and Makefile wrt new
path (and there's no need to run go get any more).

Signed-off-by: Kir Kolyshkin <[email protected]>
  • Loading branch information
kolyshkin committed May 17, 2024
1 parent 2d3f72e commit 9bd41d7
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
output
schema/validate
schema/validate/validate
version.md
13 changes: 7 additions & 6 deletions schema/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
GOOD_TESTS = $(wildcard test/good/*.json)
BAD_TESTS = $(wildcard test/bad/*.json)
VALIDATE = validate/validate

default: validate

Expand All @@ -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); \
Expand All @@ -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 \
Expand All @@ -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; \
Expand All @@ -46,5 +46,6 @@ test: validate $(TESTS)
done; \
done

.PHONY: clean
clean:
rm -f validate
rm -f validate/validate
13 changes: 3 additions & 10 deletions schema/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,26 @@ 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

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
```

Then use it like:

```bash
./validate config-schema.json <yourpath>/config.json
./validate/validate config-schema.json <yourpath>/config.json
```

Or like:

```bash
./validate https://raw.githubusercontent.com/opencontainers/runtime-spec/<runtime-spec-version>/schema/config-schema.json <yourpath>/config.json
./validate/validate https://raw.githubusercontent.com/opencontainers/runtime-spec/<runtime-spec-version>/schema/config-schema.json <yourpath>/config.json
```
10 changes: 10 additions & 0 deletions schema/validate/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module github.com/opencontainers/runtime-spec/schema/validate

go 1.21.6

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
)
13 changes: 13 additions & 0 deletions schema/validate/go.sum
Original file line number Diff line number Diff line change
@@ -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=
File renamed without changes.

0 comments on commit 9bd41d7

Please sign in to comment.