refactor: remove VERSION.txt, use git tags for version identification, defaulting

This commit is contained in:
2025-08-01 14:09:47 -05:00
parent 4bacef7bb9
commit 5bb9f327dc
4 changed files with 28 additions and 24 deletions

View File

@@ -2,6 +2,9 @@ name: Build
on: on:
push: push:
branches: master
tags:
- "v*"
workflow_dispatch: workflow_dispatch:
jobs: jobs:
@@ -16,7 +19,7 @@ jobs:
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v5 uses: actions/setup-go@v5
with: with:
go-version: '1.24' go-version: "1.24"
- name: Install Task - name: Install Task
uses: arduino/setup-task@v2 uses: arduino/setup-task@v2
@@ -30,8 +33,7 @@ jobs:
- name: Get Version - name: Get Version
id: get_version id: get_version
run: | run: |
VERSION=$(cat VERSION.txt 2>/dev/null | tr -d '\r\n' | xargs) VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo 'unknown')
[ -n "$VERSION" ] || { echo "VERSION could not be acquired" && exit 1; }
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "BINARY_NAME=HATray-linux-amd64-$VERSION" >> $GITHUB_OUTPUT echo "BINARY_NAME=HATray-linux-amd64-$VERSION" >> $GITHUB_OUTPUT
@@ -56,7 +58,7 @@ jobs:
- name: Set up Go - name: Set up Go
uses: actions/setup-go@v5 uses: actions/setup-go@v5
with: with:
go-version: '1.24' go-version: "1.24"
- name: Install Task - name: Install Task
uses: arduino/setup-task@v2 uses: arduino/setup-task@v2
@@ -71,13 +73,16 @@ jobs:
id: get_version_win id: get_version_win
shell: pwsh shell: pwsh
run: | run: |
# Extract the version, assert it's not null/empty # Extract the version using git tags, fallback to 'unknown' if it fails
$version = Get-Content VERSION.txt -ErrorAction SilentlyContinue try {
if ([string]::IsNullOrWhiteSpace($version)) { throw "VERSION could not be acquired" } $version = git describe --tags --abbrev=0 2>$null
if ([string]::IsNullOrWhiteSpace($version)) { $version = 'unknown' }
} catch {
$version = 'unknown'
}
# Do not append the extension, as we're creating both an .exe and an .msi echo "VERSION=$($version.Trim())" >> $env:GITHUB_OUTPUT
echo "VERSION=$($version.Trim())" >> $env:GITHUB_OUTPUT # not used, but who cares echo "BINARY_NAME=HATray-windows-amd64-$($version.Trim())" >> $env:GITHUB_OUTPUT
echo "BINARY_NAME=HATray-windows-amd64-$($version.Trim())" >> $env:GITHUB_OUTPUT
- name: Rename Windows Binary with Version - name: Rename Windows Binary with Version
shell: pwsh shell: pwsh
@@ -89,11 +94,11 @@ jobs:
name: ${{ steps.get_version_win.outputs.BINARY_NAME }}.exe name: ${{ steps.get_version_win.outputs.BINARY_NAME }}.exe
path: bin/${{ steps.get_version_win.outputs.BINARY_NAME }}.exe path: bin/${{ steps.get_version_win.outputs.BINARY_NAME }}.exe
if-no-files-found: error if-no-files-found: error
- name: Set up .NET for WiX - name: Set up .NET for WiX
uses: actions/setup-dotnet@v4 uses: actions/setup-dotnet@v4
with: with:
dotnet-version: '8.0.x' dotnet-version: "8.0.x"
- name: Install WiX Toolset - name: Install WiX Toolset
run: dotnet tool install --global wix run: dotnet tool install --global wix
@@ -115,4 +120,4 @@ jobs:
with: with:
name: ${{ steps.get_version_win.outputs.BINARY_NAME }}.msi name: ${{ steps.get_version_win.outputs.BINARY_NAME }}.msi
path: bin/${{ steps.get_version_win.outputs.BINARY_NAME }}.msi path: bin/${{ steps.get_version_win.outputs.BINARY_NAME }}.msi
if-no-files-found: error if-no-files-found: error

View File

@@ -1 +0,0 @@
0.0.1

View File

@@ -1,12 +1,12 @@
version: '3' version: "3"
vars: vars:
BINARY_NAME: '{{.APP_NAME}}' BINARY_NAME: "{{.APP_NAME}}"
tasks: tasks:
build: build:
cmds: cmds:
- go build -ldflags "-X main.Version=$(cat VERSION.txt) -X main.Commit=$(git rev-parse --short HEAD) -X 'main.BuildDate=$(date -u +%Y-%m-%dT%H:%M:%SZ)'" -o ./bin/{{.BINARY_NAME}} ./cmd/main.go - go build -ldflags "-X main.Version=$(git describe --tags --abbrev=0 2>/dev/null || echo 'unknown') -X main.Commit=$(git rev-parse --short HEAD) -X 'main.BuildDate=$(date -u +%Y-%m-%dT%H:%M:%SZ)'" -o ./bin/{{.BINARY_NAME}} ./cmd/main.go
service: service:
desc: "Install the service" desc: "Install the service"
@@ -30,4 +30,4 @@ tasks:
tail: tail:
desc: "Tail the log file" desc: "Tail the log file"
cmds: cmds:
- journalctl --user-unit HATray.service -ef - journalctl --user-unit HATray.service -ef

View File

@@ -1,9 +1,9 @@
version: '3' version: "3"
vars: vars:
BINARY_NAME: '{{.APP_NAME}}.exe' BINARY_NAME: "{{.APP_NAME}}.exe"
VERSION: VERSION:
sh: powershell -Command "Get-Content VERSION.txt" sh: powershell -Command "try { agit describe --tags --abbrev=0 } catch { 'unknown' }"
COMMIT: COMMIT:
sh: git rev-parse --short HEAD sh: git rev-parse --short HEAD
@@ -34,7 +34,7 @@ tasks:
- cmd: pwsh -c 'Copy-Item -Force -Path .\\bin\\{{.BINARY_NAME}} -Destination $env:USERPROFILE\\AppData\\Local\\HATray\\{{.BINARY_NAME}}' - cmd: pwsh -c 'Copy-Item -Force -Path .\\bin\\{{.BINARY_NAME}} -Destination $env:USERPROFILE\\AppData\\Local\\HATray\\{{.BINARY_NAME}}'
# Start the service # Start the service
- cmd: pwsh -c 'sc start HATray' - cmd: pwsh -c 'sc start HATray'
status: status:
desc: "Show the status of the service" desc: "Show the status of the service"
cmds: cmds:
@@ -44,11 +44,11 @@ tasks:
desc: "Tail the log file" desc: "Tail the log file"
cmds: cmds:
- cmd: pwsh -c 'Get-Content -Path $env:LOCALAPPDATA\\HATray\\current.log -Tail 10 -Wait' - cmd: pwsh -c 'Get-Content -Path $env:LOCALAPPDATA\\HATray\\current.log -Tail 10 -Wait'
package: package:
desc: "Package the application as a MSI" desc: "Package the application as a MSI"
deps: [build] deps: [build]
cmds: cmds:
- wix extension add WixToolset.Util.wixext - wix extension add WixToolset.Util.wixext
- wix extension add WixToolset.UI.wixext - wix extension add WixToolset.UI.wixext
- wix build -ext WixToolset.Util.wixext -ext WixToolset.UI.wixext -o ./bin/{{.APP_NAME}}.msi build/msi/HATray.wxs -arch x64 -d VERSION={{.VERSION}} -d SOURCE=./bin/{{.BINARY_NAME}} - wix build -ext WixToolset.Util.wixext -ext WixToolset.UI.wixext -o ./bin/{{.APP_NAME}}.msi build/msi/HATray.wxs -arch x64 -d VERSION={{.VERSION}} -d SOURCE=./bin/{{.BINARY_NAME}}