Files
prysm/runtime/version/version.go
satushh cf63d112be Graffiti implementation (#16089)
<!-- Thanks for sending a PR! Before submitting:

1. If this is your first PR, check out our contribution guide here
https://docs.prylabs.network/docs/contribute/contribution-guidelines
You will then need to sign our Contributor License Agreement (CLA),
which will show up as a comment from a bot in this pull request after
you open it. We cannot review code without a signed CLA.
2. Please file an associated tracking issue if this pull request is
non-trivial and requires context for our team to understand. All
features and most bug fixes should have
an associated issue with a design discussed and decided upon. Small bug
   fixes and documentation improvements don't need issues.
3. New features and bug fixes must have tests. Documentation may need to
be updated. If you're unsure what to update, send the PR, and we'll
discuss
   in review.
4. Note that PRs updating dependencies and new Go versions are not
accepted.
   Please file an issue instead.
5. A changelog entry is required for user facing issues.
-->

**What type of PR is this?**

Feature

**What does this PR do? Why is it needed?**

This PR implements graffiti as described in the corresponding spec doc
`graffiti-proposal-brief.md `

**Which issues(s) does this PR fix?**

- https://github.com/OffchainLabs/prysm/issues/13558

**Other notes for review**

**Acknowledgements**

- [ ] I have read
[CONTRIBUTING.md](https://github.com/prysmaticlabs/prysm/blob/develop/CONTRIBUTING.md).
- [ ] I have included a uniquely named [changelog fragment
file](https://github.com/prysmaticlabs/prysm/blob/develop/CONTRIBUTING.md#maintaining-changelogmd).
- [ ] I have added a description to this PR with sufficient context for
reviewers to understand this PR.
2026-02-12 12:35:15 +00:00

60 lines
1.5 KiB
Go

// Package version executes and returns the version string
// for the currently running process.
package version
import (
"fmt"
"log"
"os/exec"
"strconv"
"strings"
"time"
)
// The value of these vars are set through linker options.
var gitCommit = "Local build"
var buildDate = "Moments ago"
var buildDateUnix = "0"
var gitTag = "Unknown"
// Version returns the version string of this build.
func Version() string {
if buildDate == "{DATE}" {
now := time.Now().Format(time.RFC3339)
buildDate = now
}
if buildDateUnix == "{DATE_UNIX}" {
buildDateUnix = strconv.Itoa(int(time.Now().Unix()))
}
return fmt.Sprintf("%s. Built at: %s", BuildData(), buildDate)
}
// SemanticVersion returns the Major.Minor.Patch version of this build.
func SemanticVersion() string {
return gitTag
}
// BuildData returns the git tag and commit of the current build.
func BuildData() string {
// if doing a local build, these values are not interpolated
if gitCommit == "{STABLE_GIT_COMMIT}" {
commit, err := exec.Command("git", "rev-parse", "HEAD").Output()
if err != nil {
log.Println(err)
} else {
gitCommit = strings.TrimRight(string(commit), "\r\n")
}
}
return fmt.Sprintf("Prysm/%s/%s", gitTag, gitCommit)
}
// GetCommitPrefix returns the first 4 characters of the git commit.
// This is used for graffiti generation per the client identification spec.
// Note: BuildData() must be called before this (happens at startup via Version()).
func GetCommitPrefix() string {
if len(gitCommit) < 4 {
return gitCommit
}
return gitCommit[:4]
}