-
Notifications
You must be signed in to change notification settings - Fork 28
/
version.go
77 lines (69 loc) · 2.31 KB
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (c) 2013-2014 The btcsuite developers
// Copyright (c) 2015-2024 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"github.com/decred/dcrpool/internal/semver"
)
// These variables define the application version and follow the semantic
// versioning 2.0.0 spec (https://semver.org/).
var (
// Note for maintainers:
//
// The expected process for setting the version in releases is as follows:
// - Create a release branch of the form 'release-vMAJOR.MINOR'
// - Modify the version variable below on that branch to:
// - Remove the pre-release portion
// - Set the build metadata to 'release.local'
// - Update the version variable below on the master branch to the next
// expected version while retaining a pre-release of 'pre'
//
// These steps ensure that building from source produces versions that are
// distinct from reproducible builds that override the version via linker
// flags.
// version is the application version per the semantic versioning 2.0.0 spec
// (https://semver.org/).
//
// It is defined as a variable so it can be overridden during the build
// process with:
// '-ldflags "-X main.version=fullsemver"'
// if needed.
//
// It MUST be a full semantic version per the semantic versioning spec or
// the app will panic at runtime. Of particular note is the pre-release
// and build metadata portions MUST only contain characters from
// semanticAlphabet.
version = "2.1.0-pre"
// NOTE: The following values are set via init by parsing the above version
// string.
// These fields are the individual semantic version components that define
// the application version.
major uint32
minor uint32
patch uint32
preRelease string
buildMetadata string
)
func init() {
parsedSemVer, err := semver.Parse(version)
if err != nil {
panic(err)
}
major = parsedSemVer.Major
minor = parsedSemVer.Minor
patch = parsedSemVer.Patch
preRelease = parsedSemVer.PreRelease
buildMetadata = parsedSemVer.BuildMetadata
if buildMetadata == "" {
buildMetadata = vcsCommitID()
if buildMetadata != "" {
version = fmt.Sprintf("%d.%d.%d", major, minor, patch)
if preRelease != "" {
version += "-" + preRelease
}
version += "+" + buildMetadata
}
}
}