Skip to content

Commit 8f2450e

Browse files
committed
makefile
1 parent 1905691 commit 8f2450e

File tree

6 files changed

+54
-2
lines changed

6 files changed

+54
-2
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bin/**

Makefile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.ONESHELL:
2+
.SHELLFLAGS += -x -e
3+
PWD = $(shell pwd)
4+
UID = $(shell id -u)
5+
GID = $(shell id -g)
6+
VERSION = "0.1.0"
7+
LD_FLAGS = -X goauthentik.io/cli/pkg/cfg.Version=${VERSION}
8+
GO_FLAGS = -ldflags "${LD_FLAGS}" -v
9+
10+
bin/ak:
11+
$(eval LD_FLAGS := -X goauthentik.io/cli/pkg/cfg.Version=${VERSION} -X goauthentik.io/cli/pkg/cfg.BuildHash=dev-$(shell git rev-parse HEAD))
12+
go build \
13+
-ldflags "${LD_FLAGS} -X goauthentik.io/cli/pkg/cfg.BuildHash=${GIT_BUILD_HASH}" \
14+
-v -a -o bin/ak .
15+
16+
clean:
17+
rm -rf ${PWD}/bin/*

cmd/root.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package cmd
22

33
import (
4+
"fmt"
45
"os"
56

67
log "github.com/sirupsen/logrus"
78
"github.com/spf13/cobra"
9+
"goauthentik.io/cli/pkg/cfg"
810
)
911

1012
func mustFlag[T any](res T, err error) T {
@@ -17,7 +19,7 @@ func mustFlag[T any](res T, err error) T {
1719
// rootCmd represents the base command when called without any subcommands
1820
var rootCmd = &cobra.Command{
1921
Use: "ak",
20-
Short: "authentik CLI",
22+
Short: fmt.Sprintf("authentik CLI v%s", cfg.FullVersion()),
2123
PersistentPreRun: func(cmd *cobra.Command, args []string) {
2224
verbose := mustFlag(cmd.Flags().GetBool("verbose"))
2325
if verbose {

pkg/agent/tray.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/kolide/systray"
77
"goauthentik.io/cli/pkg/agent/icon"
8+
"goauthentik.io/cli/pkg/cfg"
89
)
910

1011
func (a *Agent) startSystray() {
@@ -25,7 +26,7 @@ func (a *Agent) systrayReady() {
2526
}
2627

2728
func (a *Agent) systrayEarlyItems() {
28-
_ = systray.AddMenuItem("authentik CLI v0.1", "")
29+
_ = systray.AddMenuItem(fmt.Sprintf("authentik CLI v%s", cfg.FullVersion()), "")
2930
}
3031

3132
func (a *Agent) systrayLateItems() {
File renamed without changes.

pkg/cfg/version.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package cfg
2+
3+
import (
4+
"strings"
5+
)
6+
7+
// Set via ldflags
8+
var (
9+
Version = ""
10+
BuildHash = ""
11+
)
12+
13+
func FullVersion() string {
14+
version := strings.Builder{}
15+
version.WriteString(Version)
16+
if BuildHash != "" {
17+
version.WriteRune('-')
18+
if len(BuildHash) >= 8 {
19+
version.WriteString(BuildHash[:8])
20+
} else {
21+
version.WriteString(BuildHash)
22+
}
23+
}
24+
return version.String()
25+
}
26+
27+
func init() {
28+
if BuildHash == "" {
29+
BuildHash = "dev"
30+
}
31+
}

0 commit comments

Comments
 (0)