Files
Archive/clash-nyanpasu/.github/workflows/deps-build-windows-nsis.yaml
T
2026-03-17 20:16:44 +01:00

285 lines
9.1 KiB
YAML

name: '[Single] Build Windows NSIS'
on:
workflow_dispatch:
inputs:
portable:
description: 'Build Portable pkg'
required: true
type: boolean
default: false
fixed-webview:
description: 'Fixed WebView'
required: true
type: boolean
default: false
nightly:
description: 'Nightly prepare'
required: true
type: boolean
default: false
tag:
description: 'Release Tag'
required: true
type: string
arch:
type: choice
description: 'build arch target'
required: true
default: 'x86_64'
options:
- x86_64
- i686
- aarch64
workflow_call:
inputs:
portable:
description: 'Build Portable pkg'
required: true
type: boolean
default: false
fixed-webview:
description: 'Fixed WebView'
required: true
type: boolean
default: false
nightly:
description: 'Nightly prepare'
required: true
type: boolean
default: false
tag:
description: 'Release Tag'
required: true
type: string
arch:
type: string
description: 'build arch target'
required: true
default: 'x86_64'
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Install Rust nightly
run: |
rustup install nightly --profile minimal --no-self-update
rustup default nightly
- name: Setup Rust target
if: ${{ inputs.arch != 'x86_64' }}
run: |
rustup target add ${{ inputs.arch }}-pc-windows-msvc
- name: Install Node latest
uses: actions/setup-node@v6
with:
node-version: 24
- uses: pnpm/action-setup@v5
name: Install pnpm
with:
run_install: false
- uses: denoland/setup-deno@v2
with:
deno-version: v2.x
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v5
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- uses: Swatinem/rust-cache@v2
name: Cache Rust dependencies
with:
workspaces: 'backend'
key: ${{ inputs.arch }}
- name: Install Node.js dependencies
run: |
pnpm i
- name: Prepare sidecars and resources
run: |
$condition = '${{ inputs.arch }}'
switch ($condition) {
'x86_64' {
pnpm prepare:check
}
'i686' {
pnpm prepare:check --arch ia32 --sidecar-host i686-pc-windows-msvc
}
'aarch64' {
pnpm prepare:check --arch arm64 --sidecar-host aarch64-pc-windows-msvc
}
}
- name: Download fixed WebView
if: ${{ inputs.fixed-webview == true }}
run: |
$condition = '${{ inputs.arch }}'
switch ($condition) {
'x86_64' {
$arch= 'x64'
}
'i686' {
$arch = 'x86'
}
'aarch64' {
$arch = 'arm64'
}
}
$version = '127.0.2651.105'
$uri = "https://github.com/westinyang/WebView2RuntimeArchive/releases/download/$version/Microsoft.WebView2.FixedVersionRuntime.$version.$arch.cab"
$outfile = "Microsoft.WebView2.FixedVersionRuntime.$version.$arch.cab"
echo "Downloading $uri to $outfile"
invoke-webrequest -uri $uri -outfile $outfile
echo "Download finished, attempting to extract"
expand.exe $outfile -F:* ./backend/tauri
echo "Extraction finished"
- name: Prepare (Windows NSIS and Portable)
if: ${{ inputs.fixed-webview == false }}
run: ${{ inputs.nightly == true && 'pnpm prepare:nightly --nsis' || 'pnpm prepare:release --nsis' }}
- name: Prepare (Windows NSIS and Portable) with fixed WebView
if: ${{ inputs.fixed-webview == true }}
run: ${{ inputs.nightly == true && 'pnpm prepare:nightly --nsis --fixed-webview' || 'pnpm prepare:release --nsis --fixed-webview' }}
- name: Build UI
run: |
pnpm -F ui build
# TODO: optimize strategy
- name: Tauri build x86_64
if: ${{ inputs.arch == 'x86_64' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }}
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }}
NIGHTLY: ${{ inputs.nightly == true && 'true' || 'false' }}
run: |
pnpm tauri build ${{ inputs.nightly == true && '-f nightly -c ./backend/tauri/tauri.nightly.conf.json' || '-f default-meta' }}
- name: Tauri build i686
if: ${{ inputs.arch == 'i686' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }}
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }}
NIGHTLY: ${{ inputs.nightly == true && 'true' || 'false' }}
run: |
pnpm tauri build ${{ inputs.nightly == true && '-f nightly -c ./backend/tauri/tauri.nightly.conf.json --target i686-pc-windows-msvc' || '-f default-meta --target i686-pc-windows-msvc' }}
- name: Tauri build arm64
if: ${{ inputs.arch == 'aarch64' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }}
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }}
NIGHTLY: ${{ inputs.nightly == true && 'true' || 'false' }}
run: |
pnpm tauri build ${{ inputs.nightly == true && '-f nightly -c ./backend/tauri/tauri.nightly.conf.json --target aarch64-pc-windows-msvc' || '-f default-meta --target aarch64-pc-windows-msvc' }}
- name: Rename fixed webview bundle name
if: ${{ inputs.fixed-webview == true }}
run: |
$files = Get-ChildItem -Path "./backend/target" -Recurse -Include "*.exe", "*.zip", "*.zip.sig" | Where-Object { $_.FullName -like "*\bundle\*" }
$condition = '${{ inputs.arch }}'
switch ($condition) {
'x86_64' {
$arch= 'x64'
}
'i686' {
$arch = 'x86'
}
'aarch64' {
$arch = 'arm64'
}
}
foreach ($file in $files) {
echo "Renaming $file"
$newname = $file.FullName -replace $arch, "fixed-webview-$arch"
Rename-Item -Path $file -NewName $newname
}
- name: Portable Bundle
if: ${{ inputs.portable == true }}
run: |
pnpm portable ${{ inputs.fixed-webview == true && '--fixed-webview' || '' }}
env:
RUST_ARCH: ${{ inputs.arch }}
TAG_NAME: ${{ inputs.tag }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }}
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }}
NIGHTLY: ${{ inputs.nightly == true && 'true' || 'false' }}
VITE_WIN_PORTABLE: 1
- name: Upload NSIS Installer
uses: actions/upload-artifact@v7
with:
name: Clash.Nyanpasu-windows-${{ inputs.arch }}${{ inputs.fixed-webview == true && '-fixed-webview' || '' }}-nsis-installer
path: |
./backend/target/**/bundle/**/*.exe
./backend/target/**/bundle/**/*.zip
./backend/target/**/bundle/**/*.zip.sig
- name: Upload portable
if: ${{ inputs.portable == true }}
uses: actions/upload-artifact@v7
with:
name: Clash.Nyanpasu-windows-${{ inputs.arch }}${{ inputs.fixed-webview == true && '-fixed-webview' || '' }}-portable
path: |
./*_portable.zip
- name: Set file server folder path
if: ${{ inputs.nightly == true }}
shell: bash
run: |
GIT_HASH=$(git rev-parse --short HEAD)
echo "FOLDER_PATH=nightly/${GIT_HASH}" >> $GITHUB_ENV
- name: Upload to file server
if: ${{ inputs.nightly == true }}
shell: bash
continue-on-error: true
run: |
deno run -A scripts/deno/upload-build-artifacts.ts \
"backend/target/**/bundle/**/*.exe" \
"*_portable.zip"
env:
FILE_SERVER_TOKEN: ${{ secrets.FILE_SERVER_TOKEN }}
FOLDER_PATH: ${{ env.FOLDER_PATH }}
- name: Upload file server results
if: ${{ inputs.nightly == true }}
uses: actions/upload-artifact@v7
with:
name: upload-results-windows-${{ inputs.arch }}${{ inputs.fixed-webview == true && '-fixed-webview' || '' }}
path: ./upload-results.json
if-no-files-found: ignore