使用 Github Actions 进行跨平台构建
要为所有可用平台构建 Wails 项目,您需要为每个操作系统创建一个应用程序构建。实现此目标的一种有效方法是利用 GitHub Actions。
一个用于构建 Wails 应用程序的操作位于:https://github.com/dAppServer/wails-build-action
如果现有操作无法满足您的要求,您可以从源代码中选择所需的步骤:https://github.com/dAppServer/wails-build-action/blob/main/action.yml
以下是一个完整的示例,演示了在创建新的 Git 标签时构建应用程序,然后将其上传到 Actions 工件
name: Wails build
on:
push:
tags:
# Match any new tag
- '*'
env:
# Necessary for most environments as build failure can occur due to OOM issues
NODE_OPTIONS: "--max-old-space-size=4096"
jobs:
build:
strategy:
# Failure in one platform build won't impact the others
fail-fast: false
matrix:
build:
- name: 'App'
platform: 'linux/amd64'
os: 'ubuntu-latest'
- name: 'App'
platform: 'windows/amd64'
os: 'windows-latest'
- name: 'App'
platform: 'darwin/universal'
os: 'macos-latest'
runs-on: ${{ matrix.build.os }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: recursive
- name: Build wails
uses: dAppServer/wails-build-[email protected]
id: build
with:
build-name: ${{ matrix.build.name }}
build-platform: ${{ matrix.build.platform }}
package: false
go-version: '1.20'
此示例提供了各种增强功能的机会,包括
- 缓存依赖项
- 代码签名
- 上传到 S3、Supbase 等平台
- 将机密注入为环境变量
- 将环境变量用作构建变量(例如从当前 Git 标签提取的版本变量)