From 133c95cd36c4e8ac795b0b3c09eb3eaea3c1deff Mon Sep 17 00:00:00 2001 From: Xevion Date: Mon, 23 Jun 2025 04:27:59 -0500 Subject: [PATCH] feat: include version information in builds --- .github/workflows/build.yml | 19 +++++++++++++++---- VERSION.txt | 1 + cmd/main.go | 4 ++++ tasks/Taskfile_windows.yml | 10 +++++----- 4 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 VERSION.txt diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5a4fdf9..1740622 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,10 +21,14 @@ jobs: - name: Build Linux Binary run: task build + - name: Get Version + id: get_version + run: echo "VERSION=$(cat VERSION.txt)" >> $GITHUB_ENV + - name: Upload Linux Binary uses: actions/upload-artifact@v4 with: - name: HATray-linux-amd64 + name: HATray-linux-amd64-${{ env.VERSION }} path: bin/HATray build-windows: @@ -59,14 +63,21 @@ jobs: - name: Build MSI 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 uses: actions/upload-artifact@v4 with: - name: HATray-windows-amd64.exe + name: HATray-windows-amd64-${{ env.VERSION }}.exe path: bin/HATray.exe - name: Upload MSI uses: actions/upload-artifact@v4 with: - name: HATray-windows-amd64.msi - path: bin/HATray-*.msi \ No newline at end of file + name: HATray-windows-amd64-${{ env.VERSION }}.msi + path: bin/HATray.msi \ No newline at end of file diff --git a/VERSION.txt b/VERSION.txt new file mode 100644 index 0000000..8a9ecc2 --- /dev/null +++ b/VERSION.txt @@ -0,0 +1 @@ +0.0.1 \ No newline at end of file diff --git a/cmd/main.go b/cmd/main.go index 38cf7dc..de01ad6 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -11,6 +11,8 @@ import ( "ha-tray/internal/service" ) +var Version = "dev" + func main() { logger, logFile, err := setupLogging() if err != nil { @@ -19,6 +21,8 @@ func main() { defer logFile.Sync() defer logFile.Close() + logger.Info("HATray started", "version", Version) + defer func() { if r := recover(); r != nil { logger.Error("uncaught panic recovered", "panic", r) diff --git a/tasks/Taskfile_windows.yml b/tasks/Taskfile_windows.yml index 7f96e38..670acf7 100644 --- a/tasks/Taskfile_windows.yml +++ b/tasks/Taskfile_windows.yml @@ -6,27 +6,27 @@ vars: tasks: build: 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: desc: "Install the service" deps: [build] cmds: # 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 # Stop the service, if running - cmd: pwsh -c 'sc stop HATray' ignore_error: true # 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 - cmd: pwsh -c 'sc start HATray' tail: desc: "Tail the log file" 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: desc: "Package the application as a MSI" @@ -34,4 +34,4 @@ tasks: cmds: - wix extension add WixToolset.Util.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}} \ No newline at end of file + - 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}} \ No newline at end of file