Skip to content

Commit

Permalink
fix: tag version in the binaries
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Webber <[email protected]>
  • Loading branch information
sebastianwebber committed Apr 2, 2022
1 parent 650853a commit c552543
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
10 changes: 9 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ builds:
goarch:
- amd64
- arm64
ldflags:
- -s
- -w
- -X github.com/pgconfig/api/pkg/version.Tag={{.Version}}
- -X github.com/pgconfig/api/pkg/version.Commit={{.Commit}}

- id: api
binary: api
Expand All @@ -35,7 +40,10 @@ builds:
- amd64
- arm64
ldflags:
- -s -w -X version.Tag={{.Version}} -X version.Commit={{.Commit}}
- -s
- -w
- -X github.com/pgconfig/api/pkg/version.Tag={{.Version}}
- -X github.com/pgconfig/api/pkg/version.Commit={{.Commit}}
nfpms:
- id: default
package_name: pgconfigctl
Expand Down
3 changes: 2 additions & 1 deletion cmd/api/handlers/v1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/pgconfig/api/pkg/docs"
"github.com/pgconfig/api/pkg/format"
"github.com/pgconfig/api/pkg/rules"
"github.com/pgconfig/api/pkg/version"
)

// GetConfig is a function to that computes the input and suggests a tuning configuration
Expand Down Expand Up @@ -181,7 +182,7 @@ func formatConf(c *fiber.Ctx, f string, output []category.SliceOutput, pgVersion
case "stackgres", "sg", "sgpostgresconfig":
b.WriteString("---\n")
}
b.WriteString(fmt.Sprintf("%s Generated by PGConfig 3.0 alpha\n", fillComment(1, comment)))
b.WriteString(fmt.Sprintf("%s Generated by PGConfig %s\n", fillComment(1, comment), version.Pretty()))
b.WriteString(fmt.Sprintf("%s %s%s\n", fillComment(1, comment), c.BaseURL(), c.OriginalURL()))
b.WriteString("\n")

Expand Down
2 changes: 1 addition & 1 deletion cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func init() {
}

func main() {
log.Printf("%s (%s)\n", version.Tag, version.Commit)
log.Printf("PGConfig API - %s\n", version.Pretty())

app := routes.New()
if err := app.Listen(fmt.Sprintf(":%d", port)); err != nil {
Expand Down
5 changes: 3 additions & 2 deletions cmd/pgconfigctl/cmd/tune.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/pgconfig/api/pkg/defaults"
"github.com/pgconfig/api/pkg/format"
"github.com/pgconfig/api/pkg/rules"
"github.com/pgconfig/api/pkg/version"
"github.com/spf13/cobra"

"github.com/mackerelio/go-osstat/memory"
Expand Down Expand Up @@ -125,12 +126,12 @@ func init() {
func export(f string, report []category.SliceOutput) {

if f == "config" {
fmt.Printf("## Generated by pgconfigctl-%s\n\n", version)
fmt.Printf("## Generated by pgconfigctl-%s\n\n", version.Pretty())
fmt.Println(format.ConfigFile(report))
return
}

fmt.Printf("-- Generated by pgconfigctl-%s\n\n", version)
fmt.Printf("-- Generated by pgconfigctl-%s\n\n", version.Pretty())
fmt.Println(format.AlterSystem(report))
}

Expand Down
9 changes: 2 additions & 7 deletions cmd/pgconfigctl/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,16 @@ import (
"fmt"

"github.com/spf13/cobra"
)

var (
version = "development"
commit = "latest"
date = "TBD"
builtBy = "hand"
"github.com/pgconfig/api/pkg/version"
)

// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "Displays version information",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("%s (%s) on %s - built by %s\n", version, commit, date, builtBy)
fmt.Printf("pgconfigctl - %s\n", version.Pretty())
},
}

Expand Down
9 changes: 8 additions & 1 deletion pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package version

const (
import "fmt"

var (
// Tag is the current $(git tag) that this code is built
Tag = "development"

// Commit is the current commit that this code is built
Commit = "latest"
)

// Pretty formats the version with commit and tag
func Pretty() string {
return fmt.Sprintf("%s (%s)", Tag, Commit)
}

0 comments on commit c552543

Please sign in to comment.