Build GFC Plus #6
This file contains hidden or 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: 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 | |
| - 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: Build & Pack Windows | |
| shell: pwsh | |
| run: | | |
| function Build-And-Pack { | |
| param([string]$arch) | |
| $env:GOOS="windows" | |
| $env:GOARCH=$arch | |
| Write-Host "==> Building Windows $arch..." | |
| ~/go/bin/wails build -m -s -trimpath -skipbindings -devtools -tags webkit2_41 -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 | |
| - 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: Build & Pack macOS | |
| run: | | |
| build_and_pack() { | |
| arch=$1 | |
| export GOOS=darwin GOARCH=$arch | |
| echo "==> Building macOS $arch..." | |
| ~/go/bin/wails build -m -s -trimpath -skipbindings -devtools -tags webkit2_41 -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. |