2024-02-08 03:48:59 -06:00
|
|
|
// Copyright (c) The OpenTofu Authors
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
// Copyright (c) 2023 HashiCorp, Inc.
|
2023-05-02 10:33:06 -05:00
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2017-10-19 18:08:35 -05:00
|
|
|
// The version package provides a location to set the release versions for all
|
|
|
|
// packages to consume, without creating import cycles.
|
|
|
|
//
|
2018-06-09 19:27:53 -05:00
|
|
|
// This package should not import any other terraform packages.
|
2017-10-19 18:08:35 -05:00
|
|
|
package version
|
|
|
|
|
|
|
|
import (
|
2023-04-03 22:38:30 -05:00
|
|
|
_ "embed"
|
2017-10-19 18:08:35 -05:00
|
|
|
"fmt"
|
2023-04-03 22:38:30 -05:00
|
|
|
"strings"
|
2017-10-19 18:08:35 -05:00
|
|
|
|
|
|
|
version "github.com/hashicorp/go-version"
|
|
|
|
)
|
|
|
|
|
2023-04-03 22:38:30 -05:00
|
|
|
// rawVersion is the current version as a string, as read from the VERSION
|
|
|
|
// file. This must be a valid semantic version.
|
|
|
|
//
|
|
|
|
//go:embed VERSION
|
|
|
|
var rawVersion string
|
|
|
|
|
|
|
|
// dev determines whether the -dev prerelease marker will
|
|
|
|
// be included in version info. It is expected to be set to "no" using
|
|
|
|
// linker flags when building binaries for release.
|
|
|
|
var dev string = "yes"
|
2017-10-19 18:08:35 -05:00
|
|
|
|
2023-04-03 22:38:30 -05:00
|
|
|
// The main version number that is being run at the moment, populated from the raw version.
|
|
|
|
var Version string
|
2017-10-19 18:08:35 -05:00
|
|
|
|
2023-04-03 22:38:30 -05:00
|
|
|
// A pre-release marker for the version, populated using a combination of the raw version
|
|
|
|
// and the dev flag.
|
|
|
|
var Prerelease string
|
|
|
|
|
|
|
|
// SemVer is an instance of version.Version representing the main version
|
|
|
|
// without any prerelease information.
|
2018-11-13 17:51:01 -06:00
|
|
|
var SemVer *version.Version
|
|
|
|
|
|
|
|
func init() {
|
2023-04-03 22:38:30 -05:00
|
|
|
semVerFull := version.Must(version.NewVersion(strings.TrimSpace(rawVersion)))
|
|
|
|
SemVer = semVerFull.Core()
|
|
|
|
Version = SemVer.String()
|
|
|
|
|
|
|
|
if dev == "no" {
|
|
|
|
Prerelease = semVerFull.Prerelease()
|
|
|
|
} else {
|
|
|
|
Prerelease = "dev"
|
|
|
|
}
|
2018-11-13 17:51:01 -06:00
|
|
|
}
|
2017-10-19 18:08:35 -05:00
|
|
|
|
|
|
|
// Header is the header name used to send the current terraform version
|
|
|
|
// in http requests.
|
|
|
|
const Header = "Terraform-Version"
|
|
|
|
|
|
|
|
// String returns the complete version string, including prerelease
|
|
|
|
func String() string {
|
2017-10-19 20:48:08 -05:00
|
|
|
if Prerelease != "" {
|
|
|
|
return fmt.Sprintf("%s-%s", Version, Prerelease)
|
2017-10-19 18:08:35 -05:00
|
|
|
}
|
2017-10-19 20:48:08 -05:00
|
|
|
return Version
|
2017-10-19 18:08:35 -05:00
|
|
|
}
|