diff --git a/.github/workflows/go-ossf-slsa3-publish.yml b/.github/workflows/go-ossf-slsa3-publish.yml deleted file mode 100644 index e3530d2..0000000 --- a/.github/workflows/go-ossf-slsa3-publish.yml +++ /dev/null @@ -1,38 +0,0 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -# This workflow lets you compile your Go project using a SLSA3 compliant builder. -# This workflow will generate a so-called "provenance" file describing the steps -# that were performed to generate the final binary. -# The project is an initiative of the OpenSSF (openssf.org) and is developed at -# https://github.com/slsa-framework/slsa-github-generator. -# The provenance file can be verified using https://github.com/slsa-framework/slsa-verifier. -# For more information about SLSA and how it improves the supply-chain, visit slsa.dev. - -name: SLSA Go releaser -on: - workflow_dispatch: - release: - types: [created] - -permissions: read-all - -jobs: - # ======================================================================================================================================== - # Prerequesite: Create a .slsa-goreleaser.yml in the root directory of your project. - # See format in https://github.com/slsa-framework/slsa-github-generator/blob/main/internal/builders/go/README.md#configuration-file - #========================================================================================================================================= - build: - permissions: - id-token: write # To sign. - contents: write # To upload release assets. - actions: read # To read workflow path. - uses: slsa-framework/slsa-github-generator/.github/workflows/builder_go_slsa3.yml@v1.4.0 - with: - go-version: 1.21 - # ============================================================================================================= - # Optional: For more options, see https://github.com/slsa-framework/slsa-github-generator#golang-projects - # ============================================================================================================= - diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 65bc11f..8279f6d 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -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 diff --git a/cmd/protoc-gen-go-kvstore/internal/generators/generate.go b/cmd/protoc-gen-go-kvstore/internal/generators/generate.go index 67f6752..b82cf49 100644 --- a/cmd/protoc-gen-go-kvstore/internal/generators/generate.go +++ b/cmd/protoc-gen-go-kvstore/internal/generators/generate.go @@ -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), } diff --git a/cmd/protoc-gen-go-kvstore/internal/ldflags.go b/cmd/protoc-gen-go-kvstore/internal/ldflags.go new file mode 100644 index 0000000..b639a4e --- /dev/null +++ b/cmd/protoc-gen-go-kvstore/internal/ldflags.go @@ -0,0 +1,7 @@ +package internal + +var ( + Version = "" + Commit = "" + Date = "" +) diff --git a/cmd/protoc-gen-go-kvstore/internal/version/version.go b/cmd/protoc-gen-go-kvstore/internal/version/version.go deleted file mode 100644 index 1b2bf35..0000000 --- a/cmd/protoc-gen-go-kvstore/internal/version/version.go +++ /dev/null @@ -1,11 +0,0 @@ -package version - -import "fmt" - -const Version = "v0.1.4" - -func PrintVersion(_ string) error { - fmt.Printf("protoc-gen-go-kvstore %s\n", Version) - - return nil -} diff --git a/cmd/protoc-gen-go-kvstore/main.go b/cmd/protoc-gen-go-kvstore/main.go index cc81281..a6afec6 100644 --- a/cmd/protoc-gen-go-kvstore/main.go +++ b/cmd/protoc-gen-go-kvstore/main.go @@ -2,13 +2,14 @@ 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() { @@ -16,7 +17,10 @@ func main() { 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 diff --git a/examples/example_kvstore.pb.go b/examples/example_kvstore.pb.go index ed03740..b775741 100644 --- a/examples/example_kvstore.pb.go +++ b/examples/example_kvstore.pb.go @@ -1,4 +1,4 @@ -// Code generated by protoc-gen-go-kvstore v0.1.3. DO NOT EDIT. +// Code generated by protoc-gen-go-kvstore . DO NOT EDIT. package examples