From e088830ed5671e2eb4b31c49cbf6fb6359a04bb1 Mon Sep 17 00:00:00 2001 From: Ansar Smagulov Date: Fri, 8 Dec 2023 22:38:51 +0600 Subject: [PATCH] ci: provide Linux and Windows binary builds with self-updates disabled (#28) --- .github/workflows/build.yml | 69 ++++++++++++++++++++++++++++++++----- config/selfupdate.go | 9 ++++- 2 files changed, 69 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2f43bf7a..676e2680 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,6 +42,9 @@ jobs: - name: Install Wails run: go install github.com/wailsapp/wails/v2/cmd/wails@latest + # ----- + # Linux + # ----- - name: Install Linux Wails Dependencies if: runner.os == 'Linux' run: sudo apt-get update && sudo apt-get install libgtk-3-0 libwebkit2gtk-4.0-dev gcc-aarch64-linux-gnu @@ -51,15 +54,30 @@ jobs: - name: Archive Linux Binary if: runner.os == 'Linux' run: | - cp build/bin/Zen-${{ matrix.arch }} Zen + mv build/bin/Zen-${{ matrix.arch }} Zen tar -czvf Zen_linux_${{ matrix.arch }}.tar.gz Zen rm Zen + - name: Build Linux Binary With Self-Updates Disabled + if: runner.os == 'Linux' + run: wails build -o Zen-${{ matrix.arch }} -platform linux/${{ matrix.arch }} -ldflags "-X 'github.com/anfragment/zen/config.Version=$(git describe --tags --abbrev=0)' -X 'github.com/anfragment/zen/config.noSelfUpdate=true'" + - name: Archive Linux Binary With Self-Updates Disabled + if: runner.os == 'Linux' + run: | + mv build/bin/Zen-${{ matrix.arch }} Zen + tar -czvf Zen_linux_${{ matrix.arch }}_noselfupdate.tar.gz Zen + rm Zen - name: Upload Linux Binary Artifact if: runner.os == 'Linux' uses: actions/upload-artifact@v3 with: name: Zen_linux_${{ matrix.arch }} path: Zen_linux_${{ matrix.arch }}.tar.gz + - name: Upload Linux Binary With Self-Updates Disabled Artifact + if: runner.os == 'Linux' + uses: actions/upload-artifact@v3 + with: + name: Zen_linux_${{ matrix.arch }}_noselfupdate + path: Zen_linux_${{ matrix.arch }}_noselfupdate.tar.gz - name: Release Linux Binary Artifact if: runner.os == 'Linux' uses: softprops/action-gh-release@v1 @@ -67,7 +85,17 @@ jobs: files: Zen_linux_${{ matrix.arch }}.tar.gz tag_name: ${{ github.ref }} draft: true + - name: Release Linux Binary With Self-Updates Disabled Artifact + if: runner.os == 'Linux' + uses: softprops/action-gh-release@v1 + with: + files: Zen_linux_${{ matrix.arch }}_noselfupdate.tar.gz + tag_name: ${{ github.ref }} + draft: true + # ----- + # macOS + # ----- - name: Install create-dmg if: runner.os == 'macOS' run: pip3 install setuptools && npm install -g create-dmg @@ -178,21 +206,45 @@ jobs: tag_name: ${{ github.ref }} draft: true + # ------- + # Windows + # ------- - name: Build Windows App & Installer if: runner.os == 'Windows' run: wails build -o Zen-${{ matrix.arch }}.exe -platform windows/${{ matrix.arch }} -nsis -ldflags "-X 'github.com/anfragment/zen/config.Version=$(git describe --tags --abbrev=0)'" - name: Archive Windows Binary if: runner.os == 'Windows' run: | - copy build/bin/Zen-${{ matrix.arch }}.exe Zen.exe + move build/bin/Zen-${{ matrix.arch }}.exe Zen.exe Compress-Archive -Path Zen.exe -DestinationPath Zen_windows_${{ matrix.arch }}.zip Remove-Item Zen.exe + - name: Build Windows Binary With Self-Updates Disabled + if: runner.os == 'Windows' + run: wails build -o Zen-${{ matrix.arch }}.exe -platform windows/${{ matrix.arch }} -nsis -ldflags "-X 'github.com/anfragment/zen/config.Version=$(git describe --tags --abbrev=0)' -X 'github.com/anfragment/zen/config.noSelfUpdate=true'" + - name: Archive Windows Binary With Self-Updates Disabled + if: runner.os == 'Windows' + run: | + move build/bin/Zen-${{ matrix.arch }}.exe Zen.exe + Compress-Archive -Path Zen.exe -DestinationPath Zen_windows_${{ matrix.arch }}_noselfupdate.zip + Remove-Item Zen.exe - name: Upload Archived Windows Binary Artifact if: runner.os == 'Windows' uses: actions/upload-artifact@v3 with: name: Zen_windows_${{ matrix.arch }} path: Zen_windows_${{ matrix.arch }}.zip + - name: Upload Windows Installer Artifact + if: runner.os == 'Windows' + uses: actions/upload-artifact@v3 + with: + name: Zen_windows_${{ matrix.arch }}-installer + path: build/bin/Zen-${{ matrix.arch }}-installer.exe + - name: Upload Archived Windows Binary With Self-Updates Disabled Artifact + if: runner.os == 'Windows' + uses: actions/upload-artifact@v3 + with: + name: Zen_windows_${{ matrix.arch }}_noselfupdate + path: Zen_windows_${{ matrix.arch }}_noselfupdate.zip - name: Release Archived Windows Binary if: runner.os == 'Windows' && startsWith(github.ref, 'refs/tags/v') uses: softprops/action-gh-release@v1 @@ -200,12 +252,6 @@ jobs: files: Zen_windows_${{ matrix.arch }}.zip tag_name: ${{ github.ref }} draft: true - - name: Upload Windows Installer Artifact - if: runner.os == 'Windows' - uses: actions/upload-artifact@v3 - with: - name: Zen_windows_${{ matrix.arch }}-installer - path: build/bin/Zen-${{ matrix.arch }}-installer.exe - name: Release Windows Installer if: runner.os == 'Windows' && startsWith(github.ref, 'refs/tags/v') uses: softprops/action-gh-release@v1 @@ -213,3 +259,10 @@ jobs: files: build/bin/Zen-${{ matrix.arch }}-installer.exe tag_name: ${{ github.ref }} draft: true + - name: Release Archived Windows Binary With Self-Updates Disabled + if: runner.os == 'Windows' && startsWith(github.ref, 'refs/tags/v') + uses: softprops/action-gh-release@v1 + with: + files: Zen_windows_${{ matrix.arch }}_noselfupdate.zip + tag_name: ${{ github.ref }} + draft: true diff --git a/config/selfupdate.go b/config/selfupdate.go index 335ff7cf..089dcf3a 100644 --- a/config/selfupdate.go +++ b/config/selfupdate.go @@ -14,6 +14,10 @@ import ( // Version is the current version of the binary. Set at compile time using ldflags (see .github/workflows/build.yml). var Version = "development" +// noSelfUpdate is set to "true" for builds distributed to package managers to prevent auto-updating. +// Set at compile time using ldflags (see .github/workflows/build.yml). +var noSelfUpdate = "false" + func (c *config) GetVersion() string { return Version } @@ -70,7 +74,9 @@ func SelfUpdate(ctx context.Context) { } func checkForUpdates() (bool, *selfupdate.Release) { - if Version == "development" { + log.Println("checking for updates") + if noSelfUpdate == "true" || Version == "development" { + log.Println("self-update disabled") return false, nil } @@ -82,6 +88,7 @@ func checkForUpdates() (bool, *selfupdate.Release) { v, _ := semver.ParseTolerant(Version) // ParseTolerant allows for the non-standard "v" prefix if !found || latest.Version.LTE(v) { + log.Println("current version is up-to-date") return false, nil }