Skip to content

Build GFC Plus

Build GFC Plus #9

Workflow file for this run

name: Build GUI.for.Clash
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
version:
description: 'Version tag (e.g. v1.17.1). Leave empty to auto-increment patch version.'
required: false
default: ''
permissions:
contents: write
jobs:
Build-Frontend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: latest
- uses: actions/setup-node@v4
with:
node-version: "latest"
cache: "pnpm"
cache-dependency-path: frontend/pnpm-lock.yaml
- run: |
cd frontend
pnpm install --frozen-lockfile
pnpm build-only
- uses: actions/upload-artifact@v4
with:
name: frontend-dist
path: frontend/dist
Build-Windows:
needs: Build-Frontend
runs-on: windows-latest
env:
APP_NAME: GUI.for.Clash
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for git describe to work
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
check-latest: true
- run: go install github.com/wailsapp/wails/v2/cmd/wails@latest
- uses: actions/download-artifact@v4
with:
name: frontend-dist
path: frontend/dist
- name: Get Version
id: get_version
shell: pwsh
run: |
if ("${{ github.event_name }}" -eq "push") {
# Tag push: use the tag name
"VERSION=${{ github.ref_name }}" | Out-File -FilePath $env:GITHUB_ENV -Append
} else {
# Manual trigger: use input or auto-increment
$inputVer = "${{ github.event.inputs.version }}"
if ($inputVer) {
"VERSION=$inputVer" | Out-File -FilePath $env:GITHUB_ENV -Append
} else {
# Auto-increment patch version
$latestTag = git describe --tags --match "v[0-9]*" --abbrev=0 2>$null
if (-not $latestTag) { $latestTag = "v0.0.0" }
$versionParts = $latestTag.Substring(1) -split '\.'
$newPatch = [int]$versionParts[2] + 1
$newTag = "v$($versionParts[0]).$($versionParts[1]).$newPatch"
Write-Host "Auto-incremented version from $latestTag to $newTag"
"VERSION=$newTag" | Out-File -FilePath $env:GITHUB_ENV -Append
}
}
- name: Build & Pack Windows
shell: pwsh
run: |
function Build-And-Pack {
param([string]$arch)
$env:GOOS="windows"
$env:GOARCH=$arch
$ldflags = "-X 'github.com/GUI-for-Cores/GUI.for.Clash/bridge.Version=$env:VERSION'"
Write-Host "==> Building Windows $arch with version $env:VERSION..."
~/go/bin/wails build -m -s -trimpath -skipbindings -devtools -tags webkit2_41 -ldflags $ldflags -o "$env:APP_NAME.exe"
cd build/bin
$zipName = "$env:APP_NAME-windows-$arch.zip"
Compress-Archive -Path "$env:APP_NAME.exe" -DestinationPath $zipName -Force
cd ../..
}
$arches = @("amd64","arm64","386")
foreach ($arch in $arches) { Build-And-Pack $arch }
- uses: actions/upload-artifact@v4
with:
name: windows-builds
path: build/bin/*.zip
Build-macOS:
needs: Build-Frontend
runs-on: macos-latest
env:
APP_NAME: GUI.for.Clash
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for git describe to work
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
check-latest: true
- run: go install github.com/wailsapp/wails/v2/cmd/wails@latest
- uses: actions/download-artifact@v4
with:
name: frontend-dist
path: frontend/dist
- run: |
go mod vendor
sed -i "" "s/\[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular\]/[NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory]/g" vendor/github.com/wailsapp/wails/v2/internal/frontend/desktop/darwin/AppDelegate.m
- name: Get Version
id: get_version
run: |
if [ "${{ github.event_name }}" == "push" ]; then
# Tag push: use the tag name
echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
else
# Manual trigger: use input or auto-increment
INPUT_VER="${{ github.event.inputs.version }}"
if [ ! -z "$INPUT_VER" ]; then
echo "VERSION=$INPUT_VER" >> $GITHUB_ENV
else
# Auto-increment patch version
LATEST_TAG=$(git describe --tags --match "v[0-9]*" --abbrev=0 2>/dev/null || echo "v0.0.0")
VERSION_NO_V=${LATEST_TAG#v}
IFS='.' read -r -a PARTS <<< "$VERSION_NO_V"
MAJOR=${PARTS[0]}
MINOR=${PARTS[1]}
PATCH=${PARTS[2]}
NEW_PATCH=$((PATCH + 1))
NEW_TAG="v$MAJOR.$MINOR.$NEW_PATCH"
echo "Auto-incremented version from $LATEST_TAG to $NEW_TAG"
echo "VERSION=$NEW_TAG" >> $GITHUB_ENV
fi
fi
- name: Build & Pack macOS
run: |
build_and_pack() {
arch=$1
export GOOS=darwin GOARCH=$arch
LDFLAGS="-X 'github.com/GUI-for-Cores/GUI.for.Clash/bridge.Version=$VERSION'"
echo "==> Building macOS $arch with version $VERSION..."
~/go/bin/wails build -m -s -trimpath -skipbindings -devtools -tags webkit2_41 -ldflags "$LDFLAGS" -o $APP_NAME.exe
cd build/bin
zip -q -r $APP_NAME-darwin-$arch.zip $APP_NAME.app
cd ../..
}
for arch in amd64 arm64; do build_and_pack $arch; done
- uses: actions/upload-artifact@v4
with:
name: macos-builds
path: build/bin/*.zip
Release:
needs: [Build-Windows, Build-macOS]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Determine Version
id: version
run: |
if [ "${{ github.event_name }}" == "push" ]; then
echo "TAG_NAME=${{ github.ref_name }}" >> $GITHUB_ENV
else
INPUT_VER="${{ github.event.inputs.version }}"
if [ ! -z "$INPUT_VER" ]; then
echo "TAG_NAME=$INPUT_VER" >> $GITHUB_ENV
else
# Get latest tag, assume format vX.Y.Z, increment Z
LATEST_TAG=$(git describe --tags --match "v[0-9]*" --abbrev=0 2>/dev/null || echo "v0.0.0")
# Remove v, split by dot
VERSION_NO_V=${LATEST_TAG#v}
IFS='.' read -r -a PARTS <<< "$VERSION_NO_V"
MAJOR=${PARTS[0]}
MINOR=${PARTS[1]}
PATCH=${PARTS[2]}
NEW_PATCH=$((PATCH + 1))
NEW_TAG="v$MAJOR.$MINOR.$NEW_PATCH"
echo "Auto-incremented version to $NEW_TAG"
echo "TAG_NAME=$NEW_TAG" >> $GITHUB_ENV
fi
fi
- uses: actions/download-artifact@v4
with:
path: release-assets
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.TAG_NAME }}
name: ${{ env.TAG_NAME }}
files: release-assets/**/*.zip
draft: false
prerelease: false
body: |
Release ${{ env.TAG_NAME }}
Auto-generated release from GitHub Actions.