Skip to content

Commit b52e3d5

Browse files
bomgarmvllow
authored andcommitted
feat: set version during build (#68)
1 parent 59a1e0f commit b52e3d5

File tree

4 files changed

+10
-23
lines changed

4 files changed

+10
-23
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ jobs:
4343
mkdir -p dist
4444
ext=""
4545
if [ "${{ matrix.os }}" = "windows" ]; then ext=".exe"; fi
46-
GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -o dist/${FILENAME}${ext}
46+
VERSION="${{ needs.release-please.outputs.tag_name }}"
47+
LDFLAGS="-ldflags -X github.com/rose-pine/rose-pine-bloom/cmd.version=${VERSION}"
48+
GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build ${LDFLAGS} -o dist/${FILENAME}${ext}
4749
- name: Upload to GitHub Release
4850
env:
4951
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

cmd/init.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55

66
"github.com/rose-pine/rose-pine-bloom/docs"
7-
"github.com/rose-pine/rose-pine-bloom/version"
87
"github.com/spf13/cobra"
98
)
109

@@ -15,7 +14,7 @@ var initCmd = &cobra.Command{
1514
Run: func(cmd *cobra.Command, args []string) {
1615
// TODO the command is not clear at this point
1716
buildCmd := "bloom TODO"
18-
if err := docs.EnsureReadmeWithBuildCommand(buildCmd, version.GetCurrentVersion()); err != nil {
17+
if err := docs.EnsureReadmeWithBuildCommand(buildCmd, version); err != nil {
1918
fmt.Println("unable to update README:", err)
2019
}
2120

cmd/root.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ package cmd
33
import (
44
"os"
55

6-
"github.com/rose-pine/rose-pine-bloom/version"
76
"github.com/spf13/cobra"
87
)
98

9+
var (
10+
// version will be set at build time using -ldflags
11+
version = "dev"
12+
)
13+
1014
var rootCmd = &cobra.Command{
1115
Use: "bloom",
1216
Short: "The Rosé Pine theme generator",
@@ -19,7 +23,7 @@ var rootCmd = &cobra.Command{
1923
// Execute adds all child commands to the root command and sets flags appropriately.
2024
// This is called by main.main(). It only needs to happen once to the rootCmd.
2125
func Execute() {
22-
rootCmd.Version = version.GetCurrentVersion()
26+
rootCmd.Version = version
2327

2428
err := rootCmd.Execute()
2529
if err != nil {

version/version.go

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)