2018-05-21 10:42:59 +00:00
|
|
|
/*
|
|
|
|
Copyright The BuildKit Authors.
|
|
|
|
Copyright The containerd Authors.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package version
|
|
|
|
|
2022-02-02 06:48:01 +00:00
|
|
|
import (
|
|
|
|
"regexp"
|
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
defaultVersion = "0.0.0+unknown"
|
|
|
|
)
|
|
|
|
|
2018-05-21 10:42:59 +00:00
|
|
|
var (
|
|
|
|
// Package is filled at linking time
|
|
|
|
Package = "github.com/moby/buildkit"
|
|
|
|
|
|
|
|
// Version holds the complete version number. Filled in at linking time.
|
2022-02-02 06:48:01 +00:00
|
|
|
Version = defaultVersion
|
2018-05-21 10:42:59 +00:00
|
|
|
|
|
|
|
// Revision is filled with the VCS (e.g. git) revision being used to build
|
|
|
|
// the program at linking time.
|
|
|
|
Revision = ""
|
|
|
|
)
|
2022-02-02 06:48:01 +00:00
|
|
|
|
|
|
|
var (
|
|
|
|
reRelease *regexp.Regexp
|
|
|
|
reDev *regexp.Regexp
|
|
|
|
reOnce sync.Once
|
|
|
|
)
|
|
|
|
|
|
|
|
func UserAgent() string {
|
|
|
|
version := defaultVersion
|
|
|
|
|
|
|
|
reOnce.Do(func() {
|
|
|
|
reRelease = regexp.MustCompile(`^(v[0-9]+\.[0-9]+)\.[0-9]+$`)
|
|
|
|
reDev = regexp.MustCompile(`^(v[0-9]+\.[0-9]+)\.[0-9]+`)
|
|
|
|
})
|
|
|
|
|
|
|
|
if matches := reRelease.FindAllStringSubmatch(version, 1); len(matches) > 0 {
|
|
|
|
version = matches[0][1]
|
|
|
|
} else if matches := reDev.FindAllStringSubmatch(version, 1); len(matches) > 0 {
|
|
|
|
version = matches[0][1] + "-dev"
|
|
|
|
}
|
|
|
|
|
|
|
|
return "buildkit/" + version
|
|
|
|
}
|