diff --git a/.env.amd64 b/.env.amd64 new file mode 100644 index 000000000..50b2ffbe0 --- /dev/null +++ b/.env.amd64 @@ -0,0 +1,6 @@ +# Copyright (c) 2024 Joshua Rich +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +export PKG_ARCH=amd64 diff --git a/.env.arm b/.env.arm new file mode 100644 index 000000000..05845461b --- /dev/null +++ b/.env.arm @@ -0,0 +1,9 @@ +# Copyright (c) 2024 Joshua Rich +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +export CC=arm-linux-gnueabihf-gcc +export CC_PKG=gcc-arm-linux-gnueabihf +export PKG_ARCH=armhf +export PKG_CONFIG_PATH=/usr/lib/arm-linux-gnueabihf/pkgconfig \ No newline at end of file diff --git a/.env.arm64 b/.env.arm64 new file mode 100644 index 000000000..ed8af9fa3 --- /dev/null +++ b/.env.arm64 @@ -0,0 +1,9 @@ +# Copyright (c) 2024 Joshua Rich +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +export CC=aarch64-linux-gnu-gcc +export CC_PKG=gcc-aarch64-linux-gnu +export PKG_ARCH=arm64 +export PKG_CONFIG_PATH=/usr/lib/aarch64-linux-gnu/pkgconfig diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 000000000..2d7ea59a5 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,161 @@ +name: Build Release + +on: + push: + branches: [ main ] + +permissions: + contents: write + pull-requests: write + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + arch: [amd64,arm,arm64] + steps: + # - name: Run release please + # uses: google-github-actions/release-please-action@v4 + # id: release_please + # with: + # release-type: go + # token: ${{ secrets.GITHUB_TOKEN }} + + - name: Checkout source + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: set app version + run: echo "APPVERSION=$(git describe --tags --abbrev=0)-$(git rev-parse --short HEAD)" >> $GITHUB_ENV + + # - name: set app version for release + # if: ${{ steps.release_please.outputs.release_created }} + # run: echo "APPVERSION=${{ steps.release_please.outputs.tag_name }}" >> $GITHUB_ENV + + - name: Add ${{ matrix.arch }} package repos + if: ${{ matrix.arch }} != "amd64" + id: enable_multiarch + run: | + source .env.${{ matrix.arch }} + sudo dpkg --add-architecture ${PKG_ARCH} + sudo sed -i 's|^deb\s|deb [arch=amd64] |g' /etc/apt/sources.list + sudo cat << EOF >> /etc/apt/sources.list + deb [arch=${PKG_ARCH}] http://ports.ubuntu.com/ubuntu-ports/ jammy main + #deb-src http://ports.ubuntu.com/ubuntu-ports/ jammy main + deb [arch=${PKG_ARCH}] http://ports.ubuntu.com/ubuntu-ports/ jammy-updates main + #deb-src http://ports.ubuntu.com/ubuntu-ports/ jammy-updates main + deb [arch=${PKG_ARCH}] http://ports.ubuntu.com/ubuntu-ports/ jammy-security main + #deb-src http://ports.ubuntu.com/ubuntu-ports/ jammy-security main + EOF + + - name: Install build dependencies + # if: ${{ steps.release_please.outputs.release_created }} + id: install_packages + run: > + source .env.${{ matrix.arch }} && + sudo apt-get update && sudo apt-get -y install + desktop-file-utils gcc ${COMPILER_PKG} + libgl1-mesa-dev:${PKG_ARCH} xserver-xorg-dev:${PKG_ARCH} + libxcursor-dev:${PKG_ARCH} libxrandr-dev:${PKG_ARCH} + libxinerama-dev:${PKG_ARCH} libxi-dev:${PKG_ARCH} + libgl1-mesa-dev:${PKG_ARCH} + env: + DEBIAN_FRONTEND: noninteractive + + # - name: Install/Cache build dependencies + # # if: ${{ steps.release_please.outputs.release_created }} + # id: cache_pkg_deps + # uses: awalsh128/cache-apt-pkgs-action@latest + # with: + # packages: > + # desktop-file-utils gcc gcc-arm-none-eabi gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu + # libgl-dev:amd64 libx11-dev:amd64 libxrandr-dev:amd64 libxxf86vm-dev:amd64 libxi-dev:amd64 libxcursor-dev:amd64 libxinerama-dev:amd64 libxkbcommon-dev:amd64 + # libgl-dev:armhf libx11-dev:armhf libxrandr-dev:armhf libxxf86vm-dev:armhf libxi-dev:armhf libxcursor-dev:armhf libxinerama-dev:armhf libxkbcommon-dev:armhf + # libgl-dev:arm64 libx11-dev:arm64 libxrandr-dev:arm64 libxxf86vm-dev:arm64 libxi-dev:arm64 libxcursor-dev:arm64 libxinerama-dev:arm64 libxkbcommon-dev:arm64 + + - name: Setup Go + # if: ${{ steps.release_please.outputs.release_created }} + id: setup_go + uses: actions/setup-go@v5 + with: + go-version: '^1.22' + + - name: Install Go dependencies + # if: ${{ steps.release_please.outputs.release_created }} + id: install_go_deps + run: | + go install golang.org/x/tools/cmd/stringer@latest + go install github.com/fyne-io/fyne-cross@latest + go install golang.org/x/text/cmd/gotext@latest + go install github.com/matryer/moq@latest + go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest + + - name: Build ${{ matrix.arch }} binary + # if: ${{ steps.release_please.outputs.release_created }} + id: build_binary + run: | + source .env.${{ matrix.arch }} + go generate ./... + go build -o dist/go-hass-agent-${{ matrix.arch }} + env: + CGO_ENABLED: 1 + GOARCH: ${{ matrix.arch }} + + - name: Build with fyne-cross + # if: ${{ steps.release_please.outputs.release_created }} + id: build_fyne_cross + run: > + fyne-cross linux -arch=${{ matrix.arch }} + -icon internal/agent/ui/assets/logo-pretty.png + -release + + - name: Create package + id: nfpm_package + run: | + nfpm package --config .nfpm.yaml --packager rpm --target dist + nfpm package --config .nfpm.yaml --packager deb --target dist + nfpm package --config .nfpm.yaml --packager arch --target dist + env: + GOARCH: ${{ matrix.arch }} + + - name: Install cosign + # if: ${{ steps.release_please.outputs.release_created }} + id: cosign_install + uses: sigstore/cosign-installer@v3.5.0 + with: + cosign-release: 'v2.2.2' + + - name: Sign artifacts with cosign + id: cosign_sign + run: > + cosign --verbose=true sign --yes --key cosign.key + dist/*.{rpm,deb,zst} fync-cross/dist/linux-${{ matrix.arch }}/*.tar.xz + env: + COSIGN_PWD: ${{ secrets.COSIGN_PWD }} + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: my-artifact + path: my_files.tar + + - name: Upload release artifacts + if: ${{ steps.release_please.outputs.release_created }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: > + gh release upload ${{ steps.release_please.outputs.tag_name }} + dist/*.{rpm,deb,zst,sig} fync-cross/dist/linux-${{ matrix.arch }}/*.{tar.xz,sig} + # - name: Run Go Releaser + # uses: goreleaser/goreleaser-action@v5 + # if: ${{ steps.release_please.outputs.release_created }} + # id: run_goreleaser + # with: + # distribution: goreleaser + # version: latest + # args: release --clean + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # COSIGN_PWD: ${{ secrets.COSIGN_PWD }} \ No newline at end of file diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml index 8e5dc808a..c483eac81 100644 --- a/.github/workflows/go-test.yml +++ b/.github/workflows/go-test.yml @@ -5,7 +5,7 @@ on: branches: [ main ] jobs: - build: + test: runs-on: ubuntu-latest steps: - name: Checkout diff --git a/.gitignore b/.gitignore index d42fe3833..3d4dd0ebe 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,8 @@ !/.devcontainer/**/* !.golangci.yaml !.goreleaser.yaml +!.nfpm.yaml +!.env.* !codecov.yml !/assets/**/* diff --git a/.nfpm.yaml b/.nfpm.yaml new file mode 100644 index 000000000..3f50b93c6 --- /dev/null +++ b/.nfpm.yaml @@ -0,0 +1,46 @@ +# nfpm example configuration file +# +# check https://nfpm.goreleaser.com/configuration for detailed usage +# +name: "go-hass-agent" +version: ${APPVERSION} +section: "default" +priority: "extra" +maintainer: Joshua Rich +description: | + A Home Assistant, native app for desktop/laptop devices. +vendor: org.github.joshuar +homepage: https://github.com/joshuar/go-hass-app +license: MIT +# changelog: CHANGELOG.md +contents: + - src: dist/go-hass-agent-${GOARCH} + dst: /usr/bin/go-hass-agent + expand: true + - src: LICENSE + dst: /usr/share/licenses/go-hass-agent/LICENSE + - src: README.md + dst: /usr/share/doc/go-hass-agent/README.md + - src: internal/agent/ui/assets/logo-pretty.png + dst: /usr/share/pixmaps/go-hass-agent.png + - src: assets/go-hass-agent.desktop + dst: /usr/share/applications/go-hass-agent.desktop + - src: init/go-hass-agent.service + dst: /usr/lib/systemd/user/go-hass-agent.service +overrides: + rpm: + depends: + - libglvnd-glx + - libX11 + - libXrandr + - libXxf86vm + - libXi + - libXcursor + - libXinerama + deb: + depends: + - libgl1 + - libxi6 + - libxcursor1 + - libxrandr2 + - libxinerama1