Skip to content

Commit 52eb5f5

Browse files
authored
Merge pull request #2 from SgtCoDFish/version
Add version flag
2 parents 44c8c40 + 57d35fd commit 52eb5f5

File tree

4 files changed

+65
-5
lines changed

4 files changed

+65
-5
lines changed

Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,20 @@ TEMPLATE_FILES := $(shell find boilerplate-templates -name "*.boilertmpl")
2626

2727
GOLANGCI_LINT_VERSION := v1.52.2
2828

29+
GOFLAGS := -trimpath
30+
31+
RELEASE_VERSION := $(shell git describe --tags --match='v*' --abbrev=14)
32+
GITCOMMIT := $(shell git rev-parse HEAD)
33+
34+
GOLDFLAGS := -w -s \
35+
-X 'github.com/cert-manager/boilersuite/internal/version.AppVersion=$(RELEASE_VERSION)' \
36+
-X 'github.com/cert-manager/boilersuite/internal/version.AppGitCommit=$(GITCOMMIT)'
37+
2938
.PHONY: build
3039
build: $(BINDIR)/boilersuite
3140

3241
$(BINDIR)/boilersuite: $(GO_FILES) $(TEMPLATE_FILES) | $(BINDIR)
33-
CGO_ENABLED=0 go build -o $@ main.go
42+
CGO_ENABLED=0 go build $(GOFLAGS) -ldflags "$(GOLDFLAGS)" -o $@ main.go
3443

3544
.PHONY: test
3645
test:

OWNERS

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
approvers:
2+
- munnerz
3+
- joshvanl
4+
- wallrj
5+
- jakexks
6+
- maelvls
7+
- irbekrm
8+
- sgtcodfish
9+
- inteon
10+
reviewers:
11+
- munnerz
12+
- joshvanl
13+
- wallrj
14+
- jakexks
15+
- maelvls
16+
- irbekrm
17+
- sgtcodfish
18+
- inteon

internal/version/version.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
Copyright 2023 The cert-manager Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package version
18+
19+
var (
20+
// AppVersion is set by the Go linker
21+
AppVersion = "development"
22+
23+
// AppGitCommit is set by the Go linker
24+
AppGitCommit = "0000000000000000000000000000000000000000"
25+
)

main.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"strings"
3030

3131
"github.com/cert-manager/boilersuite/internal/boilersuite"
32+
"github.com/cert-manager/boilersuite/internal/version"
3233
)
3334

3435
const (
@@ -49,12 +50,19 @@ func main() {
4950
skipFlag := flag.String("skip", "", "Space-separated list of prefixes for paths which shouldn't be checked. Spaces in prefixes not supported.")
5051
authorFlag := flag.String("author", defaultAuthor, fmt.Sprintf("The expected author for files, which will be substituted for the %q marker in templates", boilersuite.AuthorMarkerRegex))
5152
verboseFlag := flag.Bool("verbose", false, "If set, prints verbose output")
52-
cpuprofile := flag.String("cpuprofile", "", "If set, writes CPU profiling information to the given filename")
53+
cpuProfile := flag.String("cpuprofile", "", "If set, writes CPU profiling information to the given filename")
54+
printVersion := flag.Bool("version", false, "If set, prints the version and exits")
5355

5456
flag.Parse()
5557

58+
if *printVersion {
59+
logger.Printf("version: %s", version.AppVersion)
60+
logger.Printf(" commit: %s", version.AppGitCommit)
61+
os.Exit(0)
62+
}
63+
5664
if flag.NArg() != 1 {
57-
logger.Fatalf("usage: %s [--skip \"paths to skip\"] [--author \"example\"] [--verbose] <path-to-dir>", os.Args[0])
65+
logger.Fatalf("usage: %s [--version] [--skip \"paths to skip\"] [--author \"example\"] [--verbose] <path-to-dir>", os.Args[0])
5866
}
5967

6068
var skippedDirs []string
@@ -67,8 +75,8 @@ func main() {
6775
verboseLogger = log.New(os.Stdout, "[VERBOSE] ", log.LstdFlags)
6876
}
6977

70-
if *cpuprofile != "" {
71-
f, err := os.Create(*cpuprofile)
78+
if *cpuProfile != "" {
79+
f, err := os.Create(*cpuProfile)
7280
if err != nil {
7381
logger.Fatal(err)
7482
}

0 commit comments

Comments
 (0)