From b27424105dc0fe57662baec82809da89a53d8140 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8E=86=E5=86=B0=E9=83=81-hermes=E7=89=88?= Date: Wed, 6 May 2026 16:02:05 +0800 Subject: [PATCH] ci: run stdb build with git bash --- .../Jenkinsfile.production-stdb-module-build | 59 ++++++------------- 1 file changed, 17 insertions(+), 42 deletions(-) diff --git a/jenkins/Jenkinsfile.production-stdb-module-build b/jenkins/Jenkinsfile.production-stdb-module-build index 42371156..fe68992e 100644 --- a/jenkins/Jenkinsfile.production-stdb-module-build +++ b/jenkins/Jenkinsfile.production-stdb-module-build @@ -71,54 +71,29 @@ pipeline { powershell ''' $ErrorActionPreference = 'Stop' $workspaceTmp = if ($env:WORKSPACE_TMP) { $env:WORKSPACE_TMP } else { "$env:WORKSPACE@tmp" } - $effectiveBuildVersion = if ($env:EFFECTIVE_BUILD_VERSION) { $env:EFFECTIVE_BUILD_VERSION } elseif ($env:BUILD_VERSION) { $env:BUILD_VERSION } else { $env:BUILD_NUMBER } $env:CARGO_HOME = "$workspaceTmp/cargo-home" $env:CARGO_TARGET_DIR = "$workspaceTmp/cargo-target/prod-release" $env:SCCACHE_DIR = "$env:USERPROFILE/.cache/sccache-stdb-module" $env:PATH = "$env:CARGO_HOME/bin;$env:PATH" - if (-not (Get-Command bash -ErrorAction SilentlyContinue)) { - throw '[stdb-build] Windows 构建节点缺少 bash,无法执行仓库现有生产构建脚本。请先安装 Git Bash 或 WSL bash,并确保 bash 在 PATH 中。' + $gitBash = @( + $env:GENARRATIVE_BASH, + 'C:\Program Files\Git\bin\bash.exe', + 'C:\Program Files\Git\usr\bin\bash.exe', + 'C:\msys64\usr\bin\bash.exe', + 'bash' + ) | Where-Object { $_ -and (($_ -eq 'bash') -or (Test-Path $_)) } | Select-Object -First 1 + if (-not $gitBash) { + throw '[stdb-build] Windows 构建节点缺少 Git Bash,无法执行仓库现有生产构建脚本。请先安装 Git for Windows,并确保 bash 在 PATH 中。' } - function Convert-ToMsysPath([string]$Path) { - if ([string]::IsNullOrWhiteSpace($Path)) { - return $Path - } - $normalized = $Path.Replace('\', '/') - if ($normalized -match '^([A-Za-z]):/(.*)$') { - return '/' + $matches[1].ToLower() + '/' + $matches[2] - } - return $normalized + $env:GENARRATIVE_BASH = $gitBash + if (-not (Get-Command cargo -ErrorAction SilentlyContinue)) { + throw '[stdb-build] 缺少 cargo。请先在 Windows 构建节点安装 Rust 工具链,并确保 cargo 在 PATH 中。' } - $bashCargoHome = Convert-ToMsysPath $env:CARGO_HOME - $bashCargoTargetDir = Convert-ToMsysPath $env:CARGO_TARGET_DIR - $bashSccacheDir = Convert-ToMsysPath $env:SCCACHE_DIR - $bashRustupHome = Convert-ToMsysPath $env:RUSTUP_HOME - $bashWorkspace = Convert-ToMsysPath $env:WORKSPACE - $bashScript = @" - set -euo pipefail - export CARGO_HOME='$bashCargoHome' - export CARGO_TARGET_DIR='$bashCargoTargetDir' - export SCCACHE_DIR='$bashSccacheDir' - export RUSTUP_HOME='$bashRustupHome' - export WORKSPACE='$bashWorkspace' - export CARGO_INCREMENTAL='$($env:CARGO_INCREMENTAL)' - export RUSTC_WRAPPER='$($env:RUSTC_WRAPPER)' - export SCCACHE_CACHE_SIZE='$($env:SCCACHE_CACHE_SIZE)' - export SOURCE_BRANCH='$($env:SOURCE_BRANCH)' - export SOURCE_COMMIT='$($env:SOURCE_COMMIT)' - chmod +x scripts/jenkins-prepare-cargo-env.sh - source scripts/jenkins-prepare-cargo-env.sh - if ! command -v cargo >/dev/null 2>&1; then - echo '[stdb-build] 缺少 cargo。请先在 Windows 构建节点安装 Rust 工具链。' >&2 - exit 1 - fi - if ! command -v sccache >/dev/null 2>&1; then - echo '[stdb-build] 未找到 sccache,改用 rustc 直接构建。' - unset RUSTC_WRAPPER - fi - npm run build:production-release -- --component spacetime-module -"@ - bash -lc $bashScript + if (-not (Get-Command sccache -ErrorAction SilentlyContinue)) { + Write-Host '[stdb-build] 未找到 sccache,改用 rustc 直接构建。' + Remove-Item Env:RUSTC_WRAPPER -ErrorAction SilentlyContinue + } + npm run build:production-release -- --component spacetime-module ''' } }