Skip to content

Commit

Permalink
Include version in ldflags
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsundar committed Dec 29, 2023
1 parent cbbc100 commit 25dfd60
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 54 deletions.
38 changes: 0 additions & 38 deletions .github/workflows/go-ossf-slsa3-publish.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ builds:
- darwin
main: "./cmd/protoc-gen-go-kvstore"
binary: protoc-gen-go-kvstore
ldflags:
- -s -w -X github.com/ehsundar/kvstore/cmd/protoc-gen-go-kvstore/internal.Version={{.Version}} -X github.com/ehsundar/kvstore/cmd/protoc-gen-go-kvstore/internal.Commit={{.Commit}} -X github.com/ehsundar/kvstore/cmd/protoc-gen-go-kvstore/internal.Date={{.Date}}

archives:
- format: zip
Expand Down
4 changes: 2 additions & 2 deletions cmd/protoc-gen-go-kvstore/internal/generators/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import (
"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/reflect/protoreflect"

"github.com/ehsundar/kvstore/cmd/protoc-gen-go-kvstore/internal"
"github.com/ehsundar/kvstore/cmd/protoc-gen-go-kvstore/internal/keymode"
"github.com/ehsundar/kvstore/cmd/protoc-gen-go-kvstore/internal/optparse"
"github.com/ehsundar/kvstore/cmd/protoc-gen-go-kvstore/internal/valuemode"
"github.com/ehsundar/kvstore/cmd/protoc-gen-go-kvstore/internal/version"
)

func GenerateFile(gen *protogen.Plugin, file *protogen.File) {
templateCtx := kvstoreTemplateContext{
PackageName: string(file.GoPackageName),
GenVersion: version.Version,
GenVersion: internal.Version,
Pairs: extractKeyValuePairs(file),
}

Expand Down
7 changes: 7 additions & 0 deletions cmd/protoc-gen-go-kvstore/internal/ldflags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package internal

var (
Version = ""
Commit = ""
Date = ""
)
11 changes: 0 additions & 11 deletions cmd/protoc-gen-go-kvstore/internal/version/version.go

This file was deleted.

8 changes: 6 additions & 2 deletions cmd/protoc-gen-go-kvstore/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@ package main

import (
"flag"
"fmt"
"os"

log "github.com/sirupsen/logrus"
"google.golang.org/protobuf/compiler/protogen"

"github.com/ehsundar/kvstore/cmd/protoc-gen-go-kvstore/internal"
"github.com/ehsundar/kvstore/cmd/protoc-gen-go-kvstore/internal/generators"
"github.com/ehsundar/kvstore/cmd/protoc-gen-go-kvstore/internal/version"
)

func main() {
setupLogger()
log.Infof("started protoc-gen-go-kvstore plugin")

if len(os.Args) > 1 {
flag.BoolFunc("version", "print protoc-gen-go-kvstore version", version.PrintVersion)
flag.BoolFunc("version", "print protoc-gen-go-kvstore version", func(_ string) error {
fmt.Printf("%s %s %s\n", internal.Version, internal.Commit, internal.Date)
return nil
})
flag.Parse()

return
Expand Down
2 changes: 1 addition & 1 deletion examples/example_kvstore.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 25dfd60

Please sign in to comment.