Skip to content

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Zheng <[email protected]>
  • Loading branch information
Two-Hearts committed Oct 31, 2022
2 parents 6399c9c + a219ad5 commit fa0eb26
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .dev.goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ builds:
- goos: windows
goarch: arm64
ldflags:
- -s -w -X {{.ModulePath}}/internal/version.Version={{.Version}} -X {{.ModulePath}}/internal/version.BuildMetadata=
- -s -w -X {{.ModulePath}}/internal/version.Version={{.Version}} -X {{.ModulePath}}/internal/version.GitCommit={{.FullCommit}} -X {{.ModulePath}}/internal/version.BuildMetadata=
archives:
- format: tar.gz
format_overrides:
Expand Down
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ builds:
- goos: windows
goarch: arm64
ldflags:
- -s -w -X {{.ModulePath}}/internal/version.Version={{.Version}} -X {{.ModulePath}}/internal/version.BuildMetadata=
- -s -w -X {{.ModulePath}}/internal/version.Version={{.Version}} -X {{.ModulePath}}/internal/version.GitCommit={{.FullCommit}} -X {{.ModulePath}}/internal/version.BuildMetadata=
archives:
- format: tar.gz
format_overrides:
Expand Down
21 changes: 15 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
MODULE = github.com/notaryproject/notation
COMMANDS = notation
GIT_TAG = $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null)
BUILD_METADATA =
ifeq ($(GIT_TAG),) # unreleased build
GIT_COMMIT = $(shell git rev-parse HEAD)
GIT_STATUS = $(shell test -n "`git status --porcelain`" && echo "dirty" || echo "unreleased")
BUILD_METADATA = $(GIT_COMMIT).$(GIT_STATUS)
GIT_COMMIT = $(shell git rev-parse HEAD)

# if the commit was tagged, BuildMetadata is empty.
ifndef BUILD_METADATA
BUILD_METADATA := unreleased
endif

ifneq ($(GIT_TAG),)
BUILD_METADATA :=
endif
LDFLAGS = -X $(MODULE)/internal/version.BuildMetadata=$(BUILD_METADATA)

# set flags
LDFLAGS := -w \
-X $(MODULE)/internal/version.GitCommit=$(GIT_COMMIT) \
-X $(MODULE)/internal/version.BuildMetadata=$(BUILD_METADATA)

GO_BUILD_FLAGS = --ldflags="$(LDFLAGS)"

.PHONY: help
Expand Down
3 changes: 1 addition & 2 deletions cmd/notation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ package main
import (
"log"

"github.com/notaryproject/notation/internal/version"
"github.com/spf13/cobra"
)

func main() {
cmd := &cobra.Command{
Use: "notation",
Short: "Notation - Notary V2",
Version: version.GetVersion(),
SilenceUsage: true,
}
cmd.AddCommand(
Expand All @@ -23,6 +21,7 @@ func main() {
pluginCommand(),
loginCommand(nil),
logoutCommand(nil))

if err := cmd.Execute(); err != nil {
log.Fatal(err)
}
Expand Down
32 changes: 32 additions & 0 deletions cmd/notation/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"fmt"
"runtime"

"github.com/notaryproject/notation/internal/version"
"github.com/spf13/cobra"
)

func versionCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "version",
Short: "Show the notation version information",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
runVersion()
},
}
return cmd
}

func runVersion() {
fmt.Printf("Notation: Notary v2, A tool to sign, store, and verify artifacts.\n\n")

fmt.Printf("Version: %s\n", version.GetVersion())
fmt.Printf("Go version: %s\n", runtime.Version())

if version.GitCommit != "" {
fmt.Printf("Git commit: %s\n", version.GitCommit)
}
}
7 changes: 7 additions & 0 deletions internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ var (
Version = "v0.11.0-alpha.4"

// BuildMetadata stores the build metadata.
//
// When execute `make build` command, it will be overridden by
// environment variable `BUILD_METADATA`. If commit tag was set,
// BuildMetadata will be empty.
BuildMetadata = "unreleased"

// GitCommit stores the git HEAD commit id
GitCommit = ""
)

// GetVersion returns the version string in SemVer 2.
Expand Down

0 comments on commit fa0eb26

Please sign in to comment.