feat: include version information in builds

This commit is contained in:
2025-06-23 04:27:59 -05:00
parent 5b17297837
commit 133c95cd36
4 changed files with 25 additions and 9 deletions

View File

@@ -21,10 +21,14 @@ jobs:
- name: Build Linux Binary - name: Build Linux Binary
run: task build run: task build
- name: Get Version
id: get_version
run: echo "VERSION=$(cat VERSION.txt)" >> $GITHUB_ENV
- name: Upload Linux Binary - name: Upload Linux Binary
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: HATray-linux-amd64 name: HATray-linux-amd64-${{ env.VERSION }}
path: bin/HATray path: bin/HATray
build-windows: build-windows:
@@ -59,14 +63,21 @@ jobs:
- name: Build MSI - name: Build MSI
run: task package run: task package
- name: Get Version
id: get_version_win
shell: pwsh
run: |
$version = Get-Content VERSION.txt
echo "VERSION=$version" | Out-File -FilePath $env:GITHUB_ENV -Append
- name: Upload Windows Binary - name: Upload Windows Binary
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: HATray-windows-amd64.exe name: HATray-windows-amd64-${{ env.VERSION }}.exe
path: bin/HATray.exe path: bin/HATray.exe
- name: Upload MSI - name: Upload MSI
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: HATray-windows-amd64.msi name: HATray-windows-amd64-${{ env.VERSION }}.msi
path: bin/HATray-*.msi path: bin/HATray.msi

1
VERSION.txt Normal file
View File

@@ -0,0 +1 @@
0.0.1

View File

@@ -11,6 +11,8 @@ import (
"ha-tray/internal/service" "ha-tray/internal/service"
) )
var Version = "dev"
func main() { func main() {
logger, logFile, err := setupLogging() logger, logFile, err := setupLogging()
if err != nil { if err != nil {
@@ -19,6 +21,8 @@ func main() {
defer logFile.Sync() defer logFile.Sync()
defer logFile.Close() defer logFile.Close()
logger.Info("HATray started", "version", Version)
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
logger.Error("uncaught panic recovered", "panic", r) logger.Error("uncaught panic recovered", "panic", r)

View File

@@ -6,27 +6,27 @@ vars:
tasks: tasks:
build: build:
cmds: cmds:
- go build -o ./bin/{{.BINARY_NAME}} ./cmd/main.go - go build -ldflags "-X main.Version=$(Get-Content VERSION.txt)" -o ./bin/{{.BINARY_NAME}} ./cmd/main.go
service: service:
desc: "Install the service" desc: "Install the service"
deps: [build] deps: [build]
cmds: cmds:
# Create the service, if not already present # Create the service, if not already present
- cmd: pwsh -c 'sc create HATray binPath= "$env:USERPROFILE\AppData\Local\HATray\{{.BINARY_NAME}}" start=auto' - cmd: pwsh -c 'sc create HATray binPath= "$env:USERPROFILE\\AppData\\Local\\HATray\\{{.BINARY_NAME}}" start=auto'
ignore_error: true ignore_error: true
# Stop the service, if running # Stop the service, if running
- cmd: pwsh -c 'sc stop HATray' - cmd: pwsh -c 'sc stop HATray'
ignore_error: true ignore_error: true
# Replace the binary # Replace the binary
- 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'
tail: tail:
desc: "Tail the log file" desc: "Tail the log file"
cmds: cmds:
- cmd: pwsh -c 'Get-Content -Path $env:USERPROFILE\AppData\Local\HATray\current.log -Tail 100 -Wait' - cmd: pwsh -c 'Get-Content -Path $env:USERPROFILE\\AppData\\Local\\HATray\\current.log -Tail 100 -Wait'
package: package:
desc: "Package the application as a MSI" desc: "Package the application as a MSI"
@@ -34,4 +34,4 @@ tasks:
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}}-{{.VERSION}}.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=$(Get-Content VERSION.txt) -d SOURCE=./bin/{{.BINARY_NAME}}