Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/rootCmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ var rootCmd = &cobra.Command{
Version: setlist.VERSION,
}

func init() {
rootCmd.SetVersionTemplate(fmt.Sprintf("{{.Name}} version %s (%s)\n", setlist.VERSION, setlist.COMMIT))
}

func loadAWSConfig(ctx context.Context) (aws.Config, error) {
if profile != "" {
slog.Info("Loading AWS config with profile", "profile", profile)
Expand Down
22 changes: 22 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import (
"fmt"

"github.com/scottbrown/setlist"

"github.com/spf13/cobra"
)

var versionCmd = &cobra.Command{
Use: "version",
Short: "Printing the current version",
Long: "Printing the current version and commit information",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("%s version %s (%s)\n", AppName, setlist.VERSION, setlist.COMMIT)
},
}

func init() {
rootCmd.AddCommand(versionCmd)
}
16 changes: 11 additions & 5 deletions taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@ vars:
build_dir: "{{ .pwd }}/.build"
dist_dir: "{{ .pwd }}/.dist"

git_version:
sh: git tag --points-at HEAD | head -1 | grep . || git rev-parse --abbrev-ref HEAD
git_commit:
sh: git rev-parse --short HEAD
ldflags: "-X {{ .app_repo }}.VERSION={{ .git_version }} -X {{ .app_repo }}.COMMIT={{ .git_commit }}"

tasks:
build:
desc: "Builds a local artifact"
cmds:
- go build -o {{ .build_dir }}/{{ .bin_name }} {{ .pkg_name }}
- go build -ldflags "{{ .ldflags }}" -o {{ .build_dir }}/{{ .bin_name }} {{ .pkg_name }}

lambda-build:
desc: "Builds the Lambda artifact"
cmds:
- GOOS=linux GOARCH=arm64 go build -tags lambda.norpc -o {{ .build_dir }}/lambda/bootstrap {{ .app_repo }}/cmd/lambda
- GOOS=linux GOARCH=arm64 go build -ldflags "{{ .ldflags }}" -tags lambda.norpc -o {{ .build_dir }}/lambda/bootstrap {{ .app_repo }}/cmd/lambda

fmt:
desc: "Formats the code"
Expand Down Expand Up @@ -79,23 +85,23 @@ tasks:
desc: "Builds a linux artifact"
cmds:
- for: [ amd64, arm64 ]
cmd: GOOS=$GOOS GOARCH={{ .ITEM }} go build -o {{ .build_dir }}/linux-{{ .ITEM }}/{{ .bin_name }} {{ .app_repo }}/cmd
cmd: GOOS=$GOOS GOARCH={{ .ITEM }} go build -ldflags "{{ .ldflags }}" -o {{ .build_dir }}/linux-{{ .ITEM }}/{{ .bin_name }} {{ .app_repo }}/cmd
env:
GOOS: linux

build-windows:
desc: "Builds a Windows artifact"
cmds:
- for: [ amd64, arm64 ]
cmd: GOOS=$GOOS GOARCH={{ .ITEM }} go build -o {{ .build_dir }}/windows-{{ .ITEM }}/{{ .bin_name }}.exe {{ .app_repo }}/cmd
cmd: GOOS=$GOOS GOARCH={{ .ITEM }} go build -ldflags "{{ .ldflags }}" -o {{ .build_dir }}/windows-{{ .ITEM }}/{{ .bin_name }}.exe {{ .app_repo }}/cmd
env:
GOOS: windows

build-darwin:
desc: "Builds a MacOS artifact"
cmds:
- for: [ amd64, arm64 ]
cmd: GOOS=darwin GOARCH={{ .ITEM }} go build -o {{ .build_dir }}/darwin-{{ .ITEM }}/{{ .bin_name }} {{ .app_repo }}/cmd
cmd: GOOS=darwin GOARCH={{ .ITEM }} go build -ldflags "{{ .ldflags }}" -o {{ .build_dir }}/darwin-{{ .ITEM }}/{{ .bin_name }} {{ .app_repo }}/cmd
env:
GOOS: darwin

Expand Down
4 changes: 4 additions & 0 deletions update.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ type ReleaseInfo struct {
// CheckForUpdates compares the current version with the latest release
// and returns information about a newer version if available
func CheckForUpdates(ctx context.Context, client HTTPDoer) (*UpdateInfo, error) {
if VERSION == "dev" {
return nil, fmt.Errorf("cannot check for updates: running a dev build")
}

// Create request with context
req, err := http.NewRequestWithContext(ctx, http.MethodGet, GithubAPI, nil)
if err != nil {
Expand Down
19 changes: 19 additions & 0 deletions update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,25 @@ func TestCheckForUpdatesHTTPError(t *testing.T) {
}
}

func TestCheckForUpdatesDevBuild(t *testing.T) {
originalVersion := VERSION
defer func() { VERSION = originalVersion }()

VERSION = "dev"

mockClient := &mockHTTPClient{}

_, err := CheckForUpdates(context.Background(), mockClient)
if err == nil {
t.Error("Expected error for dev build, got nil")
}

expected := "cannot check for updates: running a dev build"
if err.Error() != expected {
t.Errorf("Expected error %q, got %q", expected, err.Error())
}
}

func TestCheckForUpdatesWithContext(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel()
Expand Down
5 changes: 2 additions & 3 deletions version.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package setlist

// VERSION defines the current version of the Setlist application.
// This is displayed in the CLI help output and used in release artifacts.
var VERSION = "1.2.1"
var VERSION = "dev"
var COMMIT = "unknown"