-
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(go): hardcode version and get commit_hash via runtime/debug
- Loading branch information
Showing
11 changed files
with
62 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package config | ||
|
||
import ( | ||
"runtime/debug" | ||
|
||
"github.com/samber/lo" | ||
) | ||
|
||
// The version of Artalk | ||
// | ||
// Which is automatically set by the CI release workflow | ||
const Version = "v2.9.0" | ||
|
||
// The commit hash from which the binary was built (optional) | ||
// | ||
// This value is set by the build script: | ||
// `go build -ldflags "-X 'github.com/artalkjs/artalk/v2/internal/config.CommitHash=$(git rev-parse --short HEAD)'"` | ||
func CommitHash() string { | ||
info, ok := debug.ReadBuildInfo() | ||
if !ok { | ||
return "" | ||
} | ||
setting, found := lo.Find(info.Settings, func(s debug.BuildSetting) bool { return s.Key == "vcs.revision" }) | ||
if !found { | ||
return "" | ||
} | ||
if len(setting.Value) >= 7 { | ||
return setting.Value[:7] | ||
} | ||
return setting.Value | ||
} | ||
|
||
// Get the version string | ||
// (format is "Version/CommitHash" or only "Version" if CommitHash is empty) | ||
func VersionString() string { | ||
var str = Version | ||
if CommitHash() != "" { | ||
str += "/" + CommitHash() | ||
} | ||
return str | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters