Skip to content

Commit

Permalink
ci: provide Linux and Windows binary builds with self-updates disabled (
Browse files Browse the repository at this point in the history
  • Loading branch information
anfragment authored Dec 8, 2023
1 parent 22e4441 commit e088830
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 9 deletions.
69 changes: 61 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -51,23 +54,48 @@ 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
with:
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
Expand Down Expand Up @@ -178,38 +206,63 @@ 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
with:
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
with:
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
9 changes: 8 additions & 1 deletion config/selfupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down

0 comments on commit e088830

Please sign in to comment.