fix: refer correct version of schema in func.yaml (#2924)

Signed-off-by: Matej Vašek <mvasek@redhat.com>
This commit is contained in:
Matej Vašek 2025-07-08 20:11:02 +02:00 committed by GitHub
parent 630064caef
commit 6a3ef466f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 36 additions and 11 deletions

View File

@ -28,7 +28,7 @@ VTAG := $(shell [ -z $(VTAG) ] && echo $(ETAG) || echo $(VTAG))
VERS ?= $(shell git describe --tags --match 'v*')
KVER ?= $(shell git describe --tags --match 'knative-*')
LDFLAGS := -X knative.dev/func/pkg/app.vers=$(VERS) -X knative.dev/func/pkg/app.kver=$(KVER) -X knative.dev/func/pkg/app.hash=$(HASH)
LDFLAGS := -X knative.dev/func/pkg/version.Vers=$(VERS) -X knative.dev/func/pkg/version.Kver=$(KVER) -X knative.dev/func/pkg/version.Hash=$(HASH)
FUNC_UTILS_IMG ?= ghcr.io/knative/func-utils:v2
LDFLAGS += -X knative.dev/func/pkg/k8s.SocatImage=$(FUNC_UTILS_IMG)

2
go.mod
View File

@ -11,6 +11,7 @@ require (
github.com/Microsoft/go-winio v0.6.2
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2
github.com/alecthomas/jsonschema v0.0.0-20220216202328-9eeeec9d044b
github.com/blang/semver/v4 v4.0.0
github.com/buildpacks/pack v0.36.4
github.com/chainguard-dev/git-urls v1.0.2
github.com/cloudevents/sdk-go/v2 v2.15.2
@ -111,7 +112,6 @@ require (
github.com/aws/smithy-go v1.22.2 // indirect
github.com/awslabs/amazon-ecr-credential-helper/ecr-login v0.0.0-20250205235911-d2398ba46815 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/blendle/zapdriver v1.3.1 // indirect
github.com/buildpacks/imgutil v0.0.0-20240605145725-186f89b2d168 // indirect
github.com/buildpacks/libcnb v1.30.3 // indirect

View File

@ -10,12 +10,12 @@ import (
"syscall"
"github.com/AlecAivazis/survey/v2/terminal"
"knative.dev/func/cmd"
"knative.dev/func/pkg/docker"
"knative.dev/func/pkg/version"
)
var vers, kver, hash string
func Main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
@ -32,9 +32,9 @@ func Main() {
cfg := cmd.RootCommandConfig{
Name: "func",
Version: cmd.Version{
Vers: vers,
Kver: kver,
Hash: hash,
Vers: version.Vers,
Kver: version.Kver,
Hash: version.Hash,
}}
if err := cmd.NewRootCmd(cfg).ExecuteContext(ctx); err != nil {

View File

@ -10,9 +10,12 @@ import (
"strings"
"time"
"github.com/blang/semver/v4"
"github.com/google/go-containerregistry/pkg/name"
"gopkg.in/yaml.v2"
fnlabels "knative.dev/func/pkg/k8s/labels"
"knative.dev/func/pkg/version"
"knative.dev/pkg/ptr"
)
@ -444,12 +447,12 @@ func (f Function) Write() (err error) {
}
defer rwFile.Close()
tagVersion := f.SpecVersion
schemaURI := funcYamlSchemaURI()
// Write schema header
schemaHeader := fmt.Sprintf(`# $schema: https://raw.githubusercontent.com/knative/func/refs/tags/v%s/schema/func_yaml-schema.json
# yaml-language-server: $schema=https://raw.githubusercontent.com/knative/func/refs/tags/v%s/schema/func_yaml-schema.json
`, tagVersion, tagVersion)
schemaHeader := fmt.Sprintf(`# $schema: %s
# yaml-language-server: $schema=%s
`, schemaURI, schemaURI)
if _, err = rwFile.WriteString(schemaHeader); err != nil {
return err
@ -479,6 +482,25 @@ func (f Function) Write() (err error) {
return
}
func funcYamlSchemaURI() string {
var (
ref = "main"
kver semver.Version
err error
)
kver, err = semver.Parse(strings.TrimPrefix(version.Kver, "knative-v"))
if err == nil {
ref = fmt.Sprintf("release-%d.%d", kver.Major, kver.Minor)
} else {
if version.Hash != "" {
ref = version.Hash
}
}
return fmt.Sprintf("https://raw.githubusercontent.com/knative/func"+
"/%s/schema/func_yaml-schema.json", ref)
}
type stampOptions struct{ journal bool }
type stampOption func(o *stampOptions)

3
pkg/version/version.go Normal file
View File

@ -0,0 +1,3 @@
package version
var Vers, Kver, Hash string