diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0caadf9..9a61233 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,9 +8,10 @@ on: permissions: contents: write packages: write + id-token: write jobs: - goreleaser: + release: runs-on: ubuntu-latest steps: - name: Checkout @@ -19,12 +20,6 @@ jobs: fetch-depth: 0 - name: Set up Go uses: actions/setup-go@v4 - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - name: Run GoReleaser uses: goreleaser/goreleaser-action@v5 with: @@ -32,4 +27,21 @@ jobs: version: latest args: release --clean env: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" \ No newline at end of file + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + - name: copy binary to local ha folder + run: | + mkdir home-assistant/addons/sbam/bin/ + cp -v dist/sbam_linux_amd64_v1/bin/sbam home-assistant/addons/sbam/bin/ + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Publish build - Home Assistant builder + uses: home-assistant/builder@2024.01.0 + with: + args: | + --amd64 \ + --target /data/home-assistant/addons/sbam \ + --addon \ No newline at end of file diff --git a/.gitignore b/.gitignore index 8c5ed2d..2ddef7c 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,7 @@ *.so *.dylib bin/ - +home-assistant/addons/sbam/bin/ # Test binary, built with `go test -c` *.test diff --git a/.goreleaser.yml b/.goreleaser.yml index 7cdc996..44e17f3 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -2,15 +2,14 @@ before: hooks: - go mod tidy +release: + prerelease: true + builds: - id: "sbam" binary: bin/sbam env: - CGO_ENABLED=0 -dockers: - - image_templates: - - "ghcr.io/atbore-phx/{{ .ProjectName }}-amd64:{{ .Version }}" - - "ghcr.io/atbore-phx/{{ .ProjectName }}-amd64:latest" changelog: sort: asc diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 5ecddf2..0000000 --- a/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM homeassistant/amd64-base:latest - -COPY bin/sbam /usr/bin/ -RUN chmod a+x /usr/bin/sbam \ No newline at end of file diff --git a/home-assistant/addons/sbam/Dockerfile b/home-assistant/addons/sbam/Dockerfile index d8ba574..4affba1 100644 --- a/home-assistant/addons/sbam/Dockerfile +++ b/home-assistant/addons/sbam/Dockerfile @@ -5,4 +5,7 @@ FROM $BUILD_FROM COPY run.sh / RUN chmod a+x /run.sh +COPY bin/sbam /usr/bin/ +RUN chmod a+x /usr/bin/sbam + CMD [ "/run.sh" ] \ No newline at end of file diff --git a/home-assistant/addons/sbam/build.json b/home-assistant/addons/sbam/build.json new file mode 100644 index 0000000..4915b2c --- /dev/null +++ b/home-assistant/addons/sbam/build.json @@ -0,0 +1,5 @@ +{ + "build_from": { + "amd64": "ghcr.io/home-assistant/amd64-base:3.18" + } +} diff --git a/home-assistant/addons/sbam/config.json b/home-assistant/addons/sbam/config.json new file mode 100644 index 0000000..b972ae7 --- /dev/null +++ b/home-assistant/addons/sbam/config.json @@ -0,0 +1,9 @@ +{ + "name": "sbam", + "version": "1.3.0", + "slug": "sbam", + "description": "Smart Battery Avanced Manager", + "arch": ["amd64"], + "url": "https://github.com/atbore-phx/sbam", + "image": "ghcr.io/atbore-phx/ha-sbam" +} \ No newline at end of file diff --git a/home-assistant/addons/sbam/run.sh b/home-assistant/addons/sbam/run.sh old mode 100644 new mode 100755 diff --git a/home-assistant/addons/test_local.sh b/home-assistant/addons/test_local.sh new file mode 100755 index 0000000..294dfc4 --- /dev/null +++ b/home-assistant/addons/test_local.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +BUILDCONTAINER_DATA_PATH="/data" +PATHTOBUILD="$BUILDCONTAINER_DATA_PATH" +ARCH=amd64 + + +PROJECTDIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )/sbam +ROOTDIR=$PROJECTDIR/../../../ +cd $PRROOTDIROJECTDIR/../../../ +make build +cd - + + +rm -rf $PROJECTDIR/bin +mkdir -p $PROJECTDIR/bin +cp $ROOTDIR/bin/sbam $PROJECTDIR/bin/ + +echo "project directory is $PROJECTDIR" +echo "build container data path is $BUILDCONTAINER_DATA_PATH" +echo "build container target build path is $PATHTOBUILD" +CMD="docker run --rm -ti --name hassio-builder --privileged -v $PROJECTDIR:$BUILDCONTAINER_DATA_PATH -v /var/run/docker.sock:/var/run/docker.sock:ro homeassistant/amd64-builder --target $PATHTOBUILD --$ARCH --test --docker-hub local" +echo "$CMD" +$CMD \ No newline at end of file diff --git a/repository.json b/repository.json new file mode 100644 index 0000000..2718285 --- /dev/null +++ b/repository.json @@ -0,0 +1,5 @@ +{ + "name": "sbam Smart Battery Manager", + "url": "https://github.com/atbore-phx/sbam", + "maintainer": "atbore-phx" +} \ No newline at end of file