File tree Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 2222
2323 - name : Build project
2424 run : |
25+ GENERATOR_VERSION="$(cat VERSION.txt)"
26+ if [[ "${{ github.ref_name }}" != "${GENERATOR_VERSION}" ]]; then
27+ echo "ERROR: Tag ${{ github.ref_name }} does not match ${GENERATOR_VERSION} specified in VERSION.txt."
28+ exit 1
29+ fi
2530 make build-release
2631
2732 - name : Release
Original file line number Diff line number Diff line change 1+ v1.12.2
Original file line number Diff line number Diff line change @@ -2,20 +2,48 @@ package main
22
33import (
44 "bytes"
5+ _ "embed"
56 "fmt"
67 "os"
8+ runtimeDebug "runtime/debug"
79
810 "github.com/spf13/pflag"
911 "open-cluster-management.io/policy-generator-plugin/internal"
1012)
1113
14+ //go:embed VERSION.txt
15+ var version []byte
1216var debug = false
1317
18+ // Gather the Git commit
19+ var gitCommit = func () string {
20+ if info , ok := runtimeDebug .ReadBuildInfo (); ok {
21+ for _ , setting := range info .Settings {
22+ if setting .Key == "vcs.revision" {
23+ return setting .Value
24+ }
25+ }
26+ }
27+
28+ return ""
29+ }()
30+
1431func main () {
1532 // Parse command input
1633 debugFlag := pflag .Bool ("debug" , false , "Print the stack trace with error messages" )
34+ versionFlag := pflag .Bool ("version" , false , "Print the version of the generator" )
1735 pflag .Parse ()
1836
37+ if * versionFlag {
38+ versionStr := string (version )
39+ if gitCommit != "" {
40+ versionStr = fmt .Sprintf ("%s-%s" , versionStr , gitCommit )
41+ }
42+ //nolint:forbidigo
43+ fmt .Println (versionStr )
44+ os .Exit (0 )
45+ }
46+
1947 debug = * debugFlag
2048
2149 // Collect and parse PolicyGeneratorConfig file paths
You can’t perform that action at this time.
0 commit comments