Skip to content

Commit ab80ff1

Browse files
authored
Merge pull request #1253 from mtrmac/schemav6
Update 2 dependencies
2 parents 3483a92 + 693d8d7 commit ab80ff1

File tree

10 files changed

+63
-30
lines changed

10 files changed

+63
-30
lines changed

.github/workflows/docs-and-linting.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ jobs:
1919
runs-on: ubuntu-latest
2020
strategy:
2121
matrix:
22-
# current Go releases plus the version in the go.mod are tested
23-
go: ['go.mod', 'oldstable', 'stable']
22+
# Current Go releases plus the versions in **/go.mod are tested.
23+
# See also BUILD_SPEC_MODULE_ONLY below.
24+
go: ['go.mod', 'schema/go.mod', 'oldstable', 'stable']
2425
# https://github.com/actions/setup-go/tree/v5#getting-go-version-from-the-gomod-file
2526
# https://github.com/actions/setup-go/tree/v5#using-stableoldstable-aliases
2627

@@ -31,17 +32,19 @@ jobs:
3132

3233
- uses: actions/setup-go@v5
3334
with:
34-
go-version: ${{ matrix.go != 'go.mod' && matrix.go || null }}
35-
go-version-file: ${{ matrix.go == 'go.mod' && 'go.mod' || null }}
36-
# cache-dependency-path: go.sum
35+
go-version: ${{ !endsWith(matrix.go, 'go.mod') && matrix.go || null }}
36+
go-version-file: ${{ endsWith(matrix.go, 'go.mod') && matrix.go || null }}
37+
cache-dependency-path: ./**/go.sum
3738

3839
- name: Render and Lint
3940
env:
4041
# do not automatically upgrade go to a different version: https://go.dev/doc/toolchain
4142
GOTOOLCHAIN: local
43+
BUILD_SPEC_MODULE_ONLY: ${{ matrix.go == 'go.mod' }}
4244
run: |
4345
export PATH="$(go env GOPATH)/bin:$PATH"
4446
make install.tools
47+
go work init . schema
4548
go get -t -d ./...
4649
ls ../
4750
make

HACKING.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ Prerequisites:
1313
- Go - latest version is recommended, see the [go.mod](go.mod) file for the minimum requirement
1414
- make
1515

16+
While developing features spanning `specs-go` and `schema`, to break the dependency cycle on an uncommitted work:
17+
18+
```shell
19+
go work init . schema
20+
```
21+
1622
The following make targets are relevant for any work involving the Go packages.
1723

1824
### Linting

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ header.html: .tool/genheader.go specs-go/version.go
7575

7676
.PHONY: validate-examples
7777
validate-examples: schema/schema.go ## validate examples in the specification markdown files
78-
go test -run TestValidate ./schema
78+
cd schema && go test -run TestValidate .
7979

8080
.PHONY: check-license
8181
check-license: ## check license headers in source files
@@ -91,6 +91,7 @@ lint: lint-go lint-md ## Run all linters
9191
lint-go: .install.lint ## lint check of Go files using golangci-lint
9292
@echo "checking Go lint"
9393
@GO111MODULE=on $(GOPATH)/bin/golangci-lint run
94+
@[ "$$BUILD_SPEC_MODULE_ONLY" = true ] || { cd schema && GO111MODULE=on $(GOPATH)/bin/golangci-lint run; }
9495

9596
.PHONY: lint-md
9697
lint-md: ## Run linting for markdown
@@ -99,7 +100,8 @@ lint-md: ## Run linting for markdown
99100

100101
.PHONY: test
101102
test: ## run the unit tests
102-
go test -race -cover $(shell go list ./... | grep -v /vendor/)
103+
go test -race -cover ./...
104+
[ "$$BUILD_SPEC_MODULE_ONLY" = true ] || { cd schema && go test -race -cover ./...; }
103105

104106
img/%.png: img/%.dot ## generate PNG from dot file
105107
dot -Tpng $^ > $@

go.mod

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,4 @@ module github.com/opencontainers/image-spec
55
// For example, updating this version to 1.19 first requires Go 1.21 to be released.
66
go 1.18
77

8-
require (
9-
github.com/opencontainers/go-digest v1.0.0
10-
github.com/russross/blackfriday v1.6.0
11-
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1
12-
)
8+
require github.com/opencontainers/go-digest v1.0.0

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
11
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
22
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
3-
github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww=
4-
github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY=
5-
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 h1:lZUw3E0/J3roVtGQ+SCrUrg3ON6NgVqpn3+iol9aGu4=
6-
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY=

schema/defs-descriptor.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"description": "Definitions particular to OpenContainer Descriptor Specification",
3+
"$schema": "http://json-schema.org/draft-04/schema#",
34
"definitions": {
45
"mediaType": {
56
"id": "https://opencontainers.org/schema/image/descriptor/mediaType",

schema/go.mod

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module github.com/opencontainers/image-spec/schema
2+
3+
go 1.21
4+
5+
require (
6+
github.com/opencontainers/go-digest v1.0.0
7+
github.com/opencontainers/image-spec v1.1.1
8+
github.com/russross/blackfriday/v2 v2.1.0
9+
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2
10+
)
11+
12+
require golang.org/x/text v0.14.0 // indirect

schema/go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI=
2+
github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
3+
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
4+
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
5+
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
6+
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
7+
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2 h1:KRzFb2m7YtdldCEkzs6KqmJw4nqEVZGK7IN2kJkjTuQ=
8+
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU=
9+
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
10+
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=

schema/spec_test.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"testing"
2828

2929
"github.com/opencontainers/image-spec/schema"
30-
"github.com/russross/blackfriday"
30+
"github.com/russross/blackfriday/v2"
3131
)
3232

3333
var (
@@ -120,9 +120,12 @@ type renderer struct {
120120
fn func(text []byte, lang string)
121121
}
122122

123-
func (r *renderer) BlockCode(out *bytes.Buffer, text []byte, lang string) {
124-
r.fn(text, lang)
125-
r.Renderer.BlockCode(out, text, lang)
123+
func (r *renderer) RenderNode(w io.Writer, node *blackfriday.Node, entering bool) blackfriday.WalkStatus {
124+
if node.Type == blackfriday.CodeBlock {
125+
lang := bytes.TrimRight(node.Info, "\t ")
126+
r.fn(node.Literal, string(lang))
127+
}
128+
return r.Renderer.RenderNode(w, node, entering)
126129
}
127130

128131
type example struct {
@@ -174,7 +177,7 @@ func extractExamples(rd io.Reader) ([]example, error) {
174177

175178
var examples []example
176179
renderer := &renderer{
177-
Renderer: blackfriday.HtmlRenderer(0, "test test", ""),
180+
Renderer: blackfriday.NewHTMLRenderer(blackfriday.HTMLRendererParameters{}),
178181
fn: func(text []byte, lang string) {
179182
examples = append(examples, parseExample(lang, string(text)))
180183
},
@@ -184,9 +187,9 @@ func extractExamples(rd io.Reader) ([]example, error) {
184187
// the side-effect of calling back for each code block.
185188
// TODO(stevvooe): Consider just parsing these with a scanner. It will be
186189
// faster and we can retain file, line no.
187-
blackfriday.MarkdownOptions(p, renderer, blackfriday.Options{
188-
Extensions: blackfriday.EXTENSION_FENCED_CODE,
189-
})
190+
_ = blackfriday.Run(p,
191+
blackfriday.WithRenderer(renderer),
192+
blackfriday.WithExtensions(blackfriday.FencedCode))
190193

191194
return examples, nil
192195
}

schema/validator.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424

2525
digest "github.com/opencontainers/go-digest"
2626
v1 "github.com/opencontainers/image-spec/specs-go/v1"
27-
"github.com/santhosh-tekuri/jsonschema/v5"
27+
"github.com/santhosh-tekuri/jsonschema/v6"
2828
)
2929

3030
// Validator wraps a media type string identifier and implements validation against a JSON schema.
@@ -83,11 +83,16 @@ func (v Validator) validateSchema(src io.Reader) error {
8383
if file.IsDir() {
8484
continue
8585
}
86-
specBuf, err := specFS.ReadFile(file.Name())
86+
specFile, err := specFS.Open(file.Name())
8787
if err != nil {
8888
return fmt.Errorf("could not read spec file %s: %w", file.Name(), err)
8989
}
90-
err = c.AddResource(file.Name(), bytes.NewReader(specBuf))
90+
defer specFile.Close()
91+
spec, err := jsonschema.UnmarshalJSON(specFile)
92+
if err != nil {
93+
return fmt.Errorf("could not decode spec file %s: %w", file.Name(), err)
94+
}
95+
err = c.AddResource(file.Name(), spec)
9196
if err != nil {
9297
return fmt.Errorf("failed to add spec file %s: %w", file.Name(), err)
9398
}
@@ -96,7 +101,7 @@ func (v Validator) validateSchema(src io.Reader) error {
96101
return fmt.Errorf("spec file has no aliases: %s", file.Name())
97102
}
98103
for _, specURL := range specURLs[file.Name()] {
99-
err = c.AddResource(specURL, bytes.NewReader(specBuf))
104+
err = c.AddResource(specURL, spec)
100105
if err != nil {
101106
return fmt.Errorf("failed to add spec file %s as url %s: %w", file.Name(), specURL, err)
102107
}
@@ -110,8 +115,7 @@ func (v Validator) validateSchema(src io.Reader) error {
110115
}
111116

112117
// read in the user input and validate
113-
var input interface{}
114-
err = json.NewDecoder(src).Decode(&input)
118+
input, err := jsonschema.UnmarshalJSON(src)
115119
if err != nil {
116120
return fmt.Errorf("unable to parse json to validate: %w", err)
117121
}

0 commit comments

Comments
 (0)