ci: run stdb build with git bash
Some checks failed
CI / verify (push) Has been cancelled

This commit is contained in:
2026-05-06 16:02:05 +08:00
parent 7364d0f2d3
commit b27424105d

View File

@@ -71,54 +71,29 @@ pipeline {
powershell ''' powershell '''
$ErrorActionPreference = 'Stop' $ErrorActionPreference = 'Stop'
$workspaceTmp = if ($env:WORKSPACE_TMP) { $env:WORKSPACE_TMP } else { "$env:WORKSPACE@tmp" } $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_HOME = "$workspaceTmp/cargo-home"
$env:CARGO_TARGET_DIR = "$workspaceTmp/cargo-target/prod-release" $env:CARGO_TARGET_DIR = "$workspaceTmp/cargo-target/prod-release"
$env:SCCACHE_DIR = "$env:USERPROFILE/.cache/sccache-stdb-module" $env:SCCACHE_DIR = "$env:USERPROFILE/.cache/sccache-stdb-module"
$env:PATH = "$env:CARGO_HOME/bin;$env:PATH" $env:PATH = "$env:CARGO_HOME/bin;$env:PATH"
if (-not (Get-Command bash -ErrorAction SilentlyContinue)) { $gitBash = @(
throw '[stdb-build] Windows 构建节点缺少 bash无法执行仓库现有生产构建脚本。请先安装 Git Bash 或 WSL bash并确保 bash 在 PATH 中。' $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) { $env:GENARRATIVE_BASH = $gitBash
if ([string]::IsNullOrWhiteSpace($Path)) { if (-not (Get-Command cargo -ErrorAction SilentlyContinue)) {
return $Path throw '[stdb-build] 缺少 cargo。请先在 Windows 构建节点安装 Rust 工具链,并确保 cargo 在 PATH 中。'
}
$normalized = $Path.Replace('\', '/')
if ($normalized -match '^([A-Za-z]):/(.*)$') {
return '/' + $matches[1].ToLower() + '/' + $matches[2]
}
return $normalized
} }
$bashCargoHome = Convert-ToMsysPath $env:CARGO_HOME if (-not (Get-Command sccache -ErrorAction SilentlyContinue)) {
$bashCargoTargetDir = Convert-ToMsysPath $env:CARGO_TARGET_DIR Write-Host '[stdb-build] 未找到 sccache改用 rustc 直接构建。'
$bashSccacheDir = Convert-ToMsysPath $env:SCCACHE_DIR Remove-Item Env:RUSTC_WRAPPER -ErrorAction SilentlyContinue
$bashRustupHome = Convert-ToMsysPath $env:RUSTUP_HOME }
$bashWorkspace = Convert-ToMsysPath $env:WORKSPACE npm run build:production-release -- --component spacetime-module
$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
''' '''
} }
} }