#!/usr/bin/env bash # compile-windows.sh — build Flutter Windows desktop, package into dist/ set -euo pipefail # shellcheck source=scripts/ci/_env.sh . "$(dirname "$0")/_env.sh" TAG="$1" VER="${TAG#v}" echo "==> compile-windows: version=${VER}" # Sync Flutter pubspec version (done in the checkout, before copying out) sed -i "s/^version:.*/version: ${VER}+1/" client/pubspec.yaml # The Forgejo Windows runner checks out under # C:\Windows\System32\config\systemprofile\.cache\act\...\hostexecutor # Building there triggers WOW64 filesystem redirection (System32 -> SysWOW64) # which breaks CMake/Flutter native paths. So copy the Flutter project to a # clean short path OUTSIDE System32 and build there. This replaces the previous # `subst W:` trick, which was fragile due to cmd/MSYS quoting. BUILD_ROOT="/c/jiu-build" BUILD_CLIENT="${BUILD_ROOT}/client" echo "==> copying client/ to ${BUILD_CLIENT}" rm -rf "$BUILD_ROOT" mkdir -p "$BUILD_ROOT" cp -r client "$BUILD_CLIENT" # `cp -r` turns Flutter's plugin symlinks (windows/flutter/ephemeral/.plugin_symlinks/*) # into real directories. flutter's createPluginSymlinks only cleans up *symlinks*, so it # then fails to create a symlink over the copied real dir (errno 183 / PathExists). # Drop all regenerable artifacts so the build below recreates them cleanly. rm -rf "${BUILD_CLIENT}/windows/flutter/ephemeral" \ "${BUILD_CLIENT}/.dart_tool" \ "${BUILD_CLIENT}/build" # Build (run from the clean path; pushd/popd avoids needing $() to save cwd) pushd "$BUILD_CLIENT" > /dev/null flutter create --platforms=windows . --project-name jiu_client flutter build windows --release \ "--dart-define=BASE_URL=https://jiu.51yanmei.com" \ "--dart-define=PUBLIC_URL=https://jiu.51yanmei.com" \ "--dart-define=APP_VERSION=${TAG}" popd > /dev/null # Package the Release folder into dist/ using PowerShell Compress-Archive. # Source is an absolute Windows path; destination is relative to the workspace. mkdir -p dist REL_WIN='C:\jiu-build\client\build\windows\x64\runner\Release' echo "==> packaging ${REL_WIN} -> dist/jiu-windows-x64.zip" powershell -NoProfile -Command \ "Compress-Archive -Path '${REL_WIN}\*' -DestinationPath 'dist\jiu-windows-x64.zip' -Force" echo "==> compile-windows: done — dist/ contents:" ls -lh dist/