Repository navigation
Expand file tree
/
Copy pathbuild.ps1
More file actions
executable file
·85 lines (72 loc) · 2.55 KB
/
Copy pathbuild.ps1
File metadata and controls
executable file
·85 lines (72 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env pwsh
param(
[string]$Configuration = "Release",
[string]$SourceRoot = $PSScriptRoot
)
$ErrorActionPreference = "Stop"
Set-Location -LiteralPath $SourceRoot
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = '1'
$env:DOTNET_CLI_TELEMETRY_OPTOUT = '1'
$env:DOTNET_NOLOGO = '1'
# ==========================================
# 1. Restore
# ==========================================
Write-Host "Restoring packages..." -ForegroundColor Cyan
dotnet restore "./AquaMai.slnx"
# ==========================================
# 2. PreBuild: Generate BuildInfo.g.cs
# ==========================================
Write-Host "Generating BuildInfo..." -ForegroundColor Cyan
try {
$gitDescribe = git describe --tags
# remove 'v' if exists
if ($gitDescribe.StartsWith("v")) {
$gitDescribe = $gitDescribe.Substring(1)
}
# Parse git describe: "1.8.0" or "1.8.0-3-gabcdef"
# Merge commit count into the patch version: "1.8.0-3-gabcdef" → "1.8.3-gabcdef"
$describeParts = $gitDescribe.Split('-')
$tagVersion = $describeParts[0]
if ($describeParts.Length -ge 3) {
$commitCount = $describeParts[1]
$hash = $describeParts[2]
$verParts = $tagVersion.Split('.')
$verParts[2] = $commitCount
$shortVer = $verParts -join '.'
$gitDescribe = "$shortVer-$hash"
} else {
$shortVer = $tagVersion
}
$branch = git rev-parse --abbrev-ref HEAD
if ($branch -ne "main") {
$gitDescribe = "$gitDescribe-$branch"
}
# Skip dirty check in CI environment
if (-not $env:CI -and -not $env:GITHUB_ACTIONS) {
$isDirty = git status --porcelain
if ($isDirty) {
$gitDescribe = "$gitDescribe-dirty"
}
}
$buildDate = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
$versionContent = @"
// Auto-generated file. Do not modify manually.
namespace AquaMai;
public static partial class BuildInfo
{
public const string Version = "$shortVer";
public const string GitVersion = "$gitDescribe";
public const string BuildDate = "$buildDate";
}
"@
Set-Content "./AquaMai/BuildInfo.g.cs" $versionContent -Encoding UTF8
} catch {
Write-Warning "Failed to generate BuildInfo.g.cs (Git describe failed?): $_"
# Fallback if needed, or just continue
}
# ==========================================
# 3. Build
# ==========================================
Write-Host "Building Solution..." -ForegroundColor Cyan
dotnet build "./AquaMai.slnx" -c $Configuration
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }