Change versioning to use git commits counts instead of semver

- less work for me
- more frequent releases
This commit is contained in:
Benson Wong
2024-12-14 09:53:13 -08:00
parent e2443251ad
commit 22d3f1a4f9
4 changed files with 35 additions and 8 deletions

View File

@@ -2,8 +2,8 @@ name: goreleaser
on:
push:
tags:
- '*'
branches:
- main
permissions:
contents: write
@@ -20,14 +20,18 @@ jobs:
-
name: Set up Go
uses: actions/setup-go@v5
- name: Get commit count
id: get_commit_count
run: echo "COMMIT_COUNT=$(git rev-list --count HEAD)" >> $GITHUB_OUTPUT
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
# 'latest', 'nightly', or a semver
version: '~> v2'
args: release --clean
version: latest
args: release --clean --snapshot
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GORELEASER_CURRENT_TAG: v${{ steps.get_commit_count.outputs.COMMIT_COUNT }}

View File

@@ -1,5 +1,8 @@
version: 2
release:
name_template: "v{{.Env.GORELEASER_CURRENT_TAG}}"
builds:
- env:
- CGO_ENABLED=0

View File

@@ -2,6 +2,16 @@
APP_NAME = llama-swap
BUILD_DIR = build
# Get the current Git hash
GIT_HASH := $(shell git rev-parse --short HEAD)
ifneq ($(shell git status --porcelain),)
# There are untracked changes
GIT_HASH := $(GIT_HASH)+
endif
# Get the build number from the commit count on the main branch
COMMIT_COUNT := $(shell git rev-list --count HEAD)
# Default target: Builds binaries for both OSX and Linux
all: mac linux simple-responder
@@ -18,12 +28,12 @@ test-all:
# Build OSX binary
mac:
@echo "Building Mac binary..."
GOOS=darwin GOARCH=arm64 go build -o $(BUILD_DIR)/$(APP_NAME)-darwin-arm64
GOOS=darwin GOARCH=arm64 go build -ldflags="-X main.GIT_HASH=${GIT_HASH} -X main.COMMIT_COUNT=${COMMIT_COUNT}" -o $(BUILD_DIR)/$(APP_NAME)-darwin-arm64
# Build Linux binary
linux:
@echo "Building Linux binary..."
GOOS=linux GOARCH=amd64 go build -o $(BUILD_DIR)/$(APP_NAME)-linux-amd64
GOOS=linux GOARCH=amd64 go build -ldflags="-X main.GIT_HASH=${GIT_HASH} -X main.COMMIT_COUNT=${COMMIT_COUNT}" -o $(BUILD_DIR)/$(APP_NAME)-linux-amd64
# for testing proxy.Process
simple-responder:

View File

@@ -9,13 +9,23 @@ import (
"github.com/mostlygeek/llama-swap/proxy"
)
// see Makefile which injects new values at build time
var GIT_HASH string = "abcd1234"
var COMMIT_COUNT string = "0-dev"
func main() {
// Define a command-line flag for the port
configPath := flag.String("config", "config.yaml", "config file name")
listenStr := flag.String("listen", ":8080", "listen ip/port")
showVersion := flag.Bool("version", false, "show version of build")
flag.Parse() // Parse the command-line flags
if *showVersion {
fmt.Printf("version: v%s (%s)\n", COMMIT_COUNT, GIT_HASH)
os.Exit(0)
}
config, err := proxy.LoadConfig(*configPath)
if err != nil {
fmt.Printf("Error loading config: %v\n", err)