Skip to content

Commit 5f1a14a

Browse files
authored
Fix release pipeline (#15821) (#15822)
1 parent f373bb2 commit 5f1a14a

File tree

3 files changed

+107
-21
lines changed

3 files changed

+107
-21
lines changed

.ado/release.yml

Lines changed: 106 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ resources:
2323
branches:
2424
include:
2525
- main
26-
- refs/heads/main
27-
- '*-stable'
28-
- 'refs/heads/*-stable'
26+
- '0.74-stable'
27+
- '0.81-stable'
28+
- '0.82-stable'
29+
- '0.83-stable'
30+
- '0.84-stable'
2931
repositories:
3032
- repository: 1ESPipelineTemplates
3133
type: git
@@ -40,11 +42,109 @@ extends:
4042
image: windows-latest
4143
os: windows
4244
stages:
45+
#
46+
# Gate stage — runs unconditionally for every trigger.
47+
# It determines whether the Release stage should proceed and sets a
48+
# descriptive build number so the pipeline history is easy to scan.
49+
#
50+
- stage: Gate
51+
displayName: Evaluate release
52+
jobs:
53+
- job: Evaluate
54+
displayName: Check if release should proceed
55+
steps:
56+
- checkout: none
57+
58+
- script: |
59+
echo == Build Variables ==
60+
echo Build.Reason: $(Build.Reason)
61+
echo Build.SourceBranch: $(Build.SourceBranch)
62+
echo Build.SourceVersion: $(Build.SourceVersion)
63+
echo Build.SourceVersionMessage: $(Build.SourceVersionMessage)
64+
echo Build.BuildNumber: $(Build.BuildNumber)
65+
echo Build.BuildId: $(Build.BuildId)
66+
echo Build.DefinitionName: $(Build.DefinitionName)
67+
echo Build.Repository.Name: $(Build.Repository.Name)
68+
echo System.TeamProject: $(System.TeamProject)
69+
echo.
70+
echo == Pipeline Resource: Publish ==
71+
echo Publish.runName: $(resources.pipeline.Publish.runName)
72+
echo Publish.runID: $(resources.pipeline.Publish.runID)
73+
echo Publish.sourceBranch: $(resources.pipeline.Publish.sourceBranch)
74+
echo Publish.sourceCommit: $(resources.pipeline.Publish.sourceCommit)
75+
echo Publish.pipelineID: $(resources.pipeline.Publish.pipelineID)
76+
echo Publish.requestedFor: $(resources.pipeline.Publish.requestedFor)
77+
echo Publish.requestedForID: $(resources.pipeline.Publish.requestedForID)
78+
displayName: Log all pipeline variables
79+
80+
- powershell: |
81+
$buildReason = $env:BUILD_REASON
82+
# Use only the first line of the commit message
83+
$sourceMessage = ($env:SOURCE_MESSAGE -split "`n")[0].Trim()
84+
$publishRunName = $env:PUBLISH_RUN_NAME
85+
$sourceBranch = $env:SOURCE_BRANCH -replace '^refs/heads/', ''
86+
87+
# Extract the datestamp (e.g. "20260319.4") from the original build number
88+
# which has the format "RNW NuGet Release 20260319.4"
89+
$originalBuildNumber = $env:BUILD_BUILDNUMBER
90+
$dateStamp = if ($originalBuildNumber -match '(\d{8}\.\d+)$') { $Matches[1] } else { "" }
91+
92+
$shouldRelease = $false
93+
$buildNumber = ""
94+
95+
if ($buildReason -eq "Manual") {
96+
$shouldRelease = $true
97+
if ($publishRunName) {
98+
$buildNumber = "$publishRunName ($sourceBranch) - $dateStamp"
99+
} else {
100+
$buildNumber = "Release ($sourceBranch) - $dateStamp"
101+
}
102+
}
103+
elseif ($sourceMessage.StartsWith("RELEASE:")) {
104+
$shouldRelease = $true
105+
$buildNumber = "$publishRunName ($sourceBranch) - $dateStamp"
106+
}
107+
else {
108+
$shouldRelease = $false
109+
# Truncate commit message for readability
110+
$shortMsg = $sourceMessage
111+
if ($shortMsg.Length -gt 60) {
112+
$shortMsg = $shortMsg.Substring(0, 57) + "..."
113+
}
114+
$buildNumber = "Skipped - $shortMsg ($sourceBranch) - $dateStamp"
115+
}
116+
117+
# Sanitize: ADO build numbers cannot contain " / : < > \ | ? @ *
118+
# and cannot end with '.'
119+
$buildNumber = $buildNumber -replace '["/:<>\\|?@*]', '_'
120+
$buildNumber = $buildNumber.TrimEnd('.')
121+
122+
Write-Host "shouldRelease: $shouldRelease"
123+
Write-Host "buildNumber: $buildNumber"
124+
125+
Write-Host "##vso[build.updatebuildnumber]$buildNumber"
126+
Write-Host "##vso[task.setvariable variable=shouldRelease;isOutput=true]$shouldRelease"
127+
name: gate
128+
displayName: Determine release eligibility and set build number
129+
env:
130+
BUILD_REASON: $(Build.Reason)
131+
BUILD_BUILDNUMBER: $(Build.BuildNumber)
132+
SOURCE_MESSAGE: $(Build.SourceVersionMessage)
133+
PUBLISH_RUN_NAME: $(resources.pipeline.Publish.runName)
134+
SOURCE_BRANCH: $(resources.pipeline.Publish.sourceBranch)
135+
136+
- script: echo Proceeding with release
137+
displayName: RELEASING - proceeding to publish
138+
condition: eq(variables['gate.shouldRelease'], 'True')
139+
140+
- script: echo Skipping release
141+
displayName: SKIPPED - not a RELEASE commit
142+
condition: eq(variables['gate.shouldRelease'], 'False')
143+
43144
- stage: Release
44145
displayName: Publish artifacts
45-
# Allow manual runs unconditionally; for build-completion triggers,
46-
# only proceed if the commit message starts with 'RELEASE:'.
47-
condition: or(eq(variables['Build.Reason'], 'Manual'), startsWith(variables['Build.SourceVersionMessage'], 'RELEASE:'))
146+
dependsOn: Gate
147+
condition: eq(dependencies.Gate.outputs['Evaluate.gate.shouldRelease'], 'True')
48148
jobs:
49149
- job: PushNpm
50150
displayName: npmjs.com - Publish npm packages

.claude/settings.local.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,4 @@ nul
193193
.store*/*
194194

195195
/npm-pkgs
196+
/.claude

0 commit comments

Comments
 (0)