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
62 changes: 57 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,45 @@ on:
pull_request:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0

- uses: actions/setup-go@v6
with:
go-version-file: 'go.mod'

- run: go version

- name: Build
run: make

- run: bin/gamon3 -v

- name: Print embedded module version information
run: go version -m bin/gamon3

test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0

- uses: actions/setup-go@v6
with:
go-version-file: 'go.mod'

- run: go version

- name: Run tests
run: make test

lint:
runs-on: ubuntu-latest

Expand All @@ -18,14 +57,16 @@ jobs:

- uses: actions/setup-go@v6
with:
go-version: '1.25'
go-version-file: 'go.mod'

- run: go version

- name: golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: v2.6

test:
check-release-build-parity:
runs-on: ubuntu-latest

steps:
Expand All @@ -35,7 +76,18 @@ jobs:

- uses: actions/setup-go@v6
with:
go-version: '1.25'
go-version-file: 'go.mod'

- name: Run tests
run: make test
- run: go version

- name: Install GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
version: "~> v2"
install-only: true

- name: Show GoReleaser version
run: goreleaser -v

- name: Compare Makefile builds to GoReleaser builds
run: scripts/check-reproducible-builds
6 changes: 4 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ jobs:
pull-requests: write

steps:
- uses: actions/checkout@v5
- uses: actions/checkout@v6
with:
fetch-depth: 0

- uses: actions/setup-go@v6
with:
go-version: '1.25'
go-version-file: 'go.mod'

- run: go version

- name: Install GoReleaser
uses: goreleaser/goreleaser-action@v6
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ go.work.sum
# Added by goreleaser init:
dist/

build/
bin/

node_modules/
11 changes: 11 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,23 @@ before:
hooks:
- go mod tidy

gomod:
proxy: true

builds:
- env:
- CGO_ENABLED=0
- GAMON3_VERSION={{ if index .Env "GAMON3_VERSION" }}{{ .Env.GAMON3_VERSION }}{{ else }}{{ .Version }}{{ end }}
goos:
- darwin
- linux
flags:
- -v
- -buildvcs=auto
- -trimpath
ldflags:
- -s -w
- -X github.com/peter-bread/gamon3/v2/internal/build.Version={{ .Env.GAMON3_VERSION }}

archives:
- formats: [tar.gz]
Expand Down
43 changes: 35 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,37 @@
.PHONY: build test cover clean install goreleaser

BUILD_DIR = build
override VALID_BUILD_MODES := release debug

VERSION ?= $(shell git describe --tags --dirty --always)
LDFLAGS ?= -X main.version=$(VERSION)
# Release builds by default, must explicitly set BUILD_MODE=debug for dev builds.
BUILD_MODE ?= release

ifneq ($(filter $(BUILD_MODE),$(VALID_BUILD_MODES)),$(BUILD_MODE))
$(error Invalid BUILD_MODE '$(BUILD_MODE)'; must be one of: [$(VALID_BUILD_MODES)])
endif

# This is the default value. In contexts where VCS information is unavaliable,
# this needs to be set manually.
#
# For example, in a Homebrew formula, this set to 'version.to_s'.
GAMON3_VERSION ?= $(shell git describe --tags --dirty --always)

BIN := bin
CGO_ENABLED := 0

LDFLAGS_COMMON := -X github.com/peter-bread/gamon3/v2/internal/build.Version=$(GAMON3_VERSION)
GOFLAGS_COMMON := -v -buildvcs=auto

ifeq ($(BUILD_MODE), release)
LDFLAGS := -s -w $(LDFLAGS_COMMON)
GOFLAGS := -trimpath $(GOFLAGS_COMMON)
else ifeq ($(BUILD_MODE), debug)
LDFLAGS := $(LDFLAGS_COMMON)
GOFLAGS := $(GOFLAGS_COMMON)
endif

build:
mkdir -p $(BUILD_DIR)
go build -o $(BUILD_DIR) -v -ldflags "$(LDFLAGS)"
mkdir -p $(BIN)
CGO_ENABLED=$(CGO_ENABLED) go build $(GOFLAGS) -o "$(BIN)" -ldflags "$(LDFLAGS)"

test:
go test -v ./...
Expand All @@ -17,17 +41,20 @@ cover:

clean:
go clean
rm -rf $(BUILD_DIR)
rm -rf $(BIN)


PREFIX ?= /usr/local

install: build
install -d $(PREFIX)/bin
install $(BUILD_DIR)/gamon3 $(PREFIX)/bin
install $(BIN)/gamon3 $(PREFIX)/bin

################################################################################

# This will use '.goreleaser.yaml' and build in 'dist/'.
# GAMON3_VERSION is passed to ensure version output is the same as using 'make'.
# This is just for checking that GoReleaser and Makefile builds are the same.
goreleaser:
goreleaser release --snapshot --clean
GAMON3_VERSION=$(GAMON3_VERSION) goreleaser release --snapshot --clean
# goreleaser release --snapshot --clean
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ go install github.com/peter-bread/gamon3/v2@latest

### Build From Source

To build and install Gamon3 under the default prefix (`/usr/local`), run:
To build and install a release version Gamon3 under the default prefix
(`/usr/local`), run:

```bash
git clone https://github.com/peter-bread/gamon3
Expand All @@ -83,6 +84,12 @@ To install under a custom prefix, e.g. `~/.local`, run:
make install PREFIX=~/.local
```

If you wish to build with debug information, use

```bash
make BUILD_MODE=debug
```

## Usage

### Authenticate with GH CLI
Expand Down
6 changes: 3 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ THE SOFTWARE.
package cmd

import (
"fmt"
"os"

"github.com/peter-bread/gamon3/v2/cmd/hook"
Expand Down Expand Up @@ -52,9 +53,8 @@ func Execute() {
}
}

func SetVersion(version, commit, date string) {
// TODO: Use `commit` and `date` in version output (MAYBE).
rootCmd.Version = version
func SetVersion(version, os, arch string) {
rootCmd.Version = fmt.Sprintf("%s %s-%s", version, os, arch)
}

func init() {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/peter-bread/gamon3/v2

go 1.25.0
go 1.25

require (
github.com/goccy/go-yaml v1.18.0
Expand Down
46 changes: 46 additions & 0 deletions internal/build/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Copyright © 2025 Peter Sheehan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

// Package build sets build information for the binary.
package build

import (
"runtime"
"runtime/debug"
)

var (
Version = "dev"
Os = "unknown"
Arch = "unknown"
)

func init() {
if Version == "dev" {
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Version != "(devel)" {
Version = info.Main.Version
}
}

Os = runtime.GOOS
Arch = runtime.GOARCH
}
10 changes: 4 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ package main

import (
"github.com/peter-bread/gamon3/v2/cmd"
"github.com/peter-bread/gamon3/v2/internal/build"
)

var (
version = "dev"
commit = "none"
date = "unknown"
)
func init() {
cmd.SetVersion(build.Version, build.Os, build.Arch)
}

func main() {
cmd.SetVersion(version, commit, date)
cmd.Execute()
}
Loading