From adcc99fd60afc9db76df820ae6852b8abf70c087 Mon Sep 17 00:00:00 2001 From: jadon <16850875+wolffshots@users.noreply.github.com> Date: Tue, 9 Apr 2024 15:00:41 +0200 Subject: [PATCH] chore!: auto-update version via tag in ci --- .github/workflows/go.yml | 14 +++++++++++++- api/api.go | 1 + main.go | 5 ++++- sensors/sensors.go | 1 + 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 6c02908..05ae485 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -31,7 +31,19 @@ jobs: go-version: 1.21.9 - name: Build for linux/arm - run: env GOOS=linux GOARCH=arm GOARM=6 go build -ldflags="-s -w" -o ./phocus -v main.go + run: | + if [[ $GITHUB_REF == refs/tags/* ]]; then + TAG_NAME="${GITHUB_REF#refs/tags/}" + echo "Current tag is $TAG_NAME" + env GOOS=linux GOARCH=arm GOARM=6 go build -ldflags="-X 'main.version=$TAG_NAME' -s -w" -o ./phocus -v main.go + else + echo "Not on a tag. The commit SHA is $GITHUB_SHA" + env GOOS=linux GOARCH=arm GOARM=6 go build -ldflags="-X 'main.version=$GITHUB_SHA' -s -w" -o ./phocus -v main.go + fi + env: + GITHUB_REF: ${{ github.ref }} + GITHUB_SHA: ${{ github.sha }} + test: runs-on: ubuntu-latest needs: [build] diff --git a/api/api.go b/api/api.go index 63197c0..766f87a 100644 --- a/api/api.go +++ b/api/api.go @@ -45,6 +45,7 @@ var upgrader = websocket.Upgrader{ } // AddQPGSnMessages is the meat of the QueueQPGSn functionality +// TODO refactor to take a number in for how many inverters func AddQPGSnMessages(timeBetween time.Duration) error { QueueMutex.Lock() if len(Queue) < 2 { diff --git a/main.go b/main.go index 72f3144..82f720e 100644 --- a/main.go +++ b/main.go @@ -19,7 +19,7 @@ import ( serial "github.com/wolffshots/phocus/v2/serial" // comms with inverter ) -const version = "v2.11.1" +var version = "development" type Configuration struct { Serial struct { @@ -72,9 +72,12 @@ func Router(client mqtt.Client, profiling bool) error { func main() { log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds | log.Llongfile) log.Println("Starting up phocus") + log.Printf("Phocus Version: %s\n\n", version) configuration, err := ParseConfig("config.json") + // TODO log some other useful info here + // just give a chance to see the http server coming up time.Sleep(3 * time.Second) diff --git a/sensors/sensors.go b/sensors/sensors.go index 3fd52cc..430f64e 100644 --- a/sensors/sensors.go +++ b/sensors/sensors.go @@ -26,6 +26,7 @@ type Sensor struct { Icon string // "icon": "mdi:battery", } +// TODO refactor to take a number in for how many inverters var sensors = []Sensor{ { SensorTopic: "homeassistant/sensor/phocus/version/config",