-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPublish.ps1
More file actions
48 lines (43 loc) · 1.63 KB
/
Copy pathPublish.ps1
File metadata and controls
48 lines (43 loc) · 1.63 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
# Ensure we are on the main branch
$branch = git rev-parse --abbrev-ref HEAD
if ($branch -ne 'main') {
Write-Error "Not on main branch. Current branch: $branch"
exit 1
}
# Ensure working tree is clean
$status = git status --porcelain
if ($status) {
Write-Error "Working tree is not clean."
exit 1
}
# Ensure we are up to date with origin
git fetch origin main --quiet
$behind = git rev-list --count HEAD..origin/main
if ($behind -gt 0) {
Write-Error "Local branch is behind origin/main by $behind commit(s)."
exit 1
}
# Get version from Nerdbank.GitVersioning
# Get version from Nerdbank.GitVersioning via the project's MSBuild targets (the
# referenced NuGet package), so this does not depend on the global 'nbgv' CLI tool
# being installed or on PATH. The GetBuildVersion target must run for the computed
# version to be populated (a plain -getProperty evaluation returns the static
# version.json value without the Git height).
$project = Join-Path $PSScriptRoot 'LightwaveRfLinkPlus.Api/LightwaveRfLinkPlus.Api.csproj'
$buildOutput = dotnet build $project -t:GetBuildVersion --getProperty:NuGetPackageVersion -nologo -v:quiet -p:TreatWarningsAsErrors=false
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to determine version from Nerdbank.GitVersioning.`n$buildOutput"
exit 1
}
$version = ($buildOutput | Select-Object -Last 1).ToString().Trim()
Write-Host "Version: $version"
# Check if tag already exists
$existingTag = git tag -l $version
if ($existingTag) {
Write-Error "Tag $version already exists."
exit 1
}
# Create and push tag
git tag $version
git push origin $version
Write-Host "Tag $version pushed. CI will publish the package."