inject version information in build #37
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Wails build | |
# inspired by https://github.com/dAppServer/wails-build-action/blob/main/action.yml | |
on: [push] | |
env: | |
# Necessary for most environments as build failure can occur due to OOM issues | |
NODE_OPTIONS: "--max-old-space-size=4096" | |
jobs: | |
test: | |
name: Test | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v2 | |
- name: Setup GoLang | |
uses: actions/setup-go@v4 | |
with: | |
check-latest: true | |
go-version: 1.23.1 | |
- name: Test | |
shell: bash | |
run: | | |
mkdir frontend/dist | |
touch frontend/dist/index.html | |
go test -v ./... | |
build: | |
name: Build | |
needs: test | |
strategy: | |
fail-fast: false | |
matrix: | |
build: [ | |
{ name: 'ask-mai-linux-amd64', platform: linux/amd64, os: ubuntu-latest }, | |
# { name: 'ask-mai-linux-arm64', platform: linux/arm64, os: ubuntu-latest }, | |
# { name: 'ask-mai-linux-arm', platform: linux/arm, os: ubuntu-latest }, | |
{ name: 'ask-mai-windows-amd64', platform: windows/amd64, os: windows-latest }, | |
{ name: 'ask-mai-windows-arm64', platform: windows/arm64, os: windows-latest }, | |
{ name: 'ask-mai-windows-386', platform: windows/386, os: windows-latest }, | |
{ name: 'ask-mai-darwin-amd64', platform: darwin/amd64, os: macos-latest }, | |
{ name: 'ask-mai-darwin-arm64', platform: darwin/arm64, os: macos-latest }, | |
{ name: 'ask-mai-darwin-universal', platform: darwin/universal, os: macos-latest } | |
] | |
runs-on: ${{ matrix.build.os }} | |
steps: | |
# Checkout code | |
- name: Common - Check out code | |
uses: actions/checkout@v2 | |
# Setup and configure GoLang | |
- name: Common - Setup GoLang | |
uses: actions/setup-go@v4 | |
with: | |
check-latest: true | |
go-version: 1.23.1 | |
# Setup and configure NodeJS | |
- name: Common - Setup NodeJS | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 20 | |
# install wails and dependencies | |
- name: Common - Install Wails | |
run: | | |
WAILS_VERSION=$(cat go.mod | grep "^\s*github.com/wailsapp/wails/" | sed 's/^\s*//' | cut -d" " -f2) | |
echo "Use Wails version: ${WAILS_VERSION}" | |
go install github.com/wailsapp/wails/v2/cmd/wails@${WAILS_VERSION} | |
shell: bash | |
- name: Linux - Install Wails deps | |
if: runner.os == 'Linux' | |
run: sudo apt-get update && sudo apt-get install libgtk-3-0 libwebkit2gtk-4.0-dev gcc-aarch64-linux-gnu upx-ucl | |
shell: bash | |
- name: Windows - Install Wails deps | |
if: runner.os == 'Windows' && matrix.build.platform != 'windows/arm64' | |
run: choco install upx | |
shell: powershell | |
# Version ldflags | |
- name: Common - Set version flags | |
id: ldflags | |
run: | | |
echo -n " -X 'main.commitHash=$(git rev-parse HEAD)'" >> ldflags | |
echo -n " -X 'main.branch=$(git rev-parse --abbrev-ref HEAD)'" >> ldflags | |
echo -n " -X 'main.tag=$(git describe --tags --abbrev=0)'" >> ldflags | |
echo -n " -X 'main.built=$(date +%s%3N)'" >> ldflags | |
echo "ldflags=$(cat ldflags)" >> $GITHUB_OUTPUT | |
# Build | |
- name: Linux - Build | |
if: runner.os == 'Linux' | |
shell: bash | |
run: wails build -platform ${{ matrix.build.platform }} -ldflags "${{ steps.ldflags.outputs.ldflags }}" -upx -o ${{ matrix.build.name }} | |
- name: Windows - Build | |
if: runner.os == 'Windows' | |
shell: bash | |
run: | | |
wails build -platform ${{ matrix.build.platform }} -ldflags "${{ steps.ldflags.outputs.ldflags }}" -o ${{ matrix.build.name }}.exe | |
wails build -platform ${{ matrix.build.platform }} -ldflags "${{ steps.ldflags.outputs.ldflags }}" -upx -o ${{ matrix.build.name }}-compressed.exe | |
- name: MacOS - Build | |
if: runner.os == 'macOS' | |
shell: bash | |
run: wails build -platform ${{ matrix.build.platform }} -ldflags "${{ steps.ldflags.outputs.ldflags }}" -o ${{ matrix.build.name }} | |
# Package MacOS | |
- name: MacOS - Build .app zip file | |
if: runner.os == 'macOS' | |
shell: bash | |
run: | | |
APP_DIR_NAME="$(cat wails.json | jq -r '.name' ).app" | |
ditto -c -k ./build/bin/${APP_DIR_NAME} ./build/bin/${{ matrix.build.name }}.app.zip | |
- name: MacOS - Building Installer | |
if: runner.os == 'macOS' | |
shell: bash | |
run: | | |
APP_DIR_NAME="$(cat wails.json | jq -r '.name' ).app" | |
productbuild --component ./build/bin/${APP_DIR_NAME} ./build/bin/${{ matrix.build.name }}.pkg | |
# Upload build assets (only for tags) | |
- name: Common - Upload build artifacts | |
uses: actions/upload-artifact@v3 | |
if: startsWith(github.ref, 'refs/tags/') | |
with: | |
name: Wails Build ${{ matrix.build.name }} | |
path: | | |
*/bin/ | |
*\bin\* | |
- name: Common - Release | |
uses: softprops/action-gh-release@v1 | |
if: startsWith(github.ref, 'refs/tags/') | |
with: | |
files: | | |
*/bin/* |