Skip to content

Commit 9ec2e1a

Browse files
authored
đź‘· ci(workflows): enhance ring detection and filter base determination (#2841)
- replace nkdAgility_Ring with RingDetection for improved clarity - add Ring Detection step to determine deployment ring based on branch and pre-release label - implement Determine Filter Base step to dynamically calculate base for path filters - enhance debug outputs for better visibility into workflow execution đź”§ chore(workflows): streamline workflow variables and remove unused setup - remove redundant docs setup variables for a cleaner configuration - adjust AzureSitesEnvironment setup to use RingDetection output - simplify switch logic for deployment ring handling
2 parents 6f46084 + 9ec6994 commit 9ec2e1a

File tree

1 file changed

+113
-39
lines changed

1 file changed

+113
-39
lines changed

‎.github/workflows/main.yml‎

Lines changed: 113 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
HasChanged_src: ${{ steps.filter.outputs.src }}
4545
HasChanged_docs: ${{ steps.filter.outputs.docs }}
4646
HasChanged_automation: ${{ steps.filter.outputs.automation }}
47-
nkdAgility_Ring: ${{ steps.nkdagility.outputs.Ring }}
47+
nkdAgility_Ring: ${{ steps.RingDetection.outputs.Ring }}
4848
nkdAgility_WingetApplicationId: ${{ steps.nkdagility.outputs.WingetApplicationId }}
4949
nkdAgility_ReleaseDescription: ${{ steps.nkdagility.outputs.release_description }}
5050
nkdAgility_ReleaseDescriptionState: ${{ steps.nkdagility.outputs.release_description_state }}
@@ -78,10 +78,105 @@ jobs:
7878
uses: gittools/actions/gitversion/[email protected]
7979
with:
8080
useConfigFile: true
81+
82+
- name: "Ring Detection"
83+
shell: pwsh
84+
id: RingDetection
85+
run: |
86+
# Get Branch Name
87+
Write-Output "::group::Get Branch Name"
88+
Write-Output "-------------------------------------------"
89+
$branchName = "${{ github.head_ref || github.ref_name }}"
90+
Write-Output "We are running on: $branchName!"
91+
$branchSafeName = $branchName.Replace("/", "-")
92+
Write-Output "branchSafeName: $branchSafeName!"
93+
Write-Output "-------------------------------------------"
94+
Write-Output "::endgroup::"
95+
96+
# Ring Setup
97+
Write-Output "::group::Ring Control Setup"
98+
Write-Output "-------------------------------------------"
99+
Write-Output "Ring Control Setup"
100+
Write-Output "-------------------------------------------"
101+
$Ring = "Canary"
102+
103+
# Use GitVersion output directly instead of environment variable
104+
$preReleaseLabel = "${{ steps.gitversion.outputs.GitVersion_PreReleaseLabel }}"
105+
Write-Output "GitVersion_PreReleaseLabel: '$preReleaseLabel'"
106+
107+
switch ($preReleaseLabel) {
108+
"" {
109+
$Ring = "Production";
110+
}
111+
"Preview" {
112+
$Ring = "Preview";
113+
}
114+
default {
115+
$Ring = "Canary";
116+
}
117+
}
118+
119+
Write-Output "We are running for the $Ring Ring!"
120+
echo "Ring=$Ring" >> $env:GITHUB_OUTPUT
121+
Write-Output "-------------------------------------------"
122+
Write-Output "::endgroup::"
123+
124+
- name: "Determine Filter Base"
125+
id: filter-base
126+
shell: pwsh
127+
run: |
128+
try {
129+
# Debug current context
130+
Write-Output "=== FILTER BASE DEBUG ==="
131+
Write-Output "Event: ${{ github.event_name }}"
132+
Write-Output "Ref: ${{ github.ref }}"
133+
Write-Output "Ring: ${{ steps.RingDetection.outputs.Ring }}"
134+
Write-Output "GitVersion_PreReleaseLabel: '${{ steps.gitversion.outputs.GitVersion_PreReleaseLabel }}'"
135+
Write-Output "GitVersion_SemVer: '${{ steps.gitversion.outputs.GitVersion_SemVer }}'"
136+
Write-Output "=========================="
137+
138+
# For production builds (no pre-release label), find the last production tag
139+
if ("${{ steps.gitversion.outputs.GitVersion_PreReleaseLabel }}" -eq "") {
140+
Write-Output "Production build detected - finding last production release"
141+
142+
# Get current version to exclude it from the search
143+
$currentVersion = "v${{ steps.gitversion.outputs.GitVersion_SemVer }}"
144+
Write-Output "Current version: $currentVersion"
145+
146+
# Get all production tags, exclude current, sort by version
147+
$allProductionTags = git tag -l | Where-Object { $_ -match '^v\d+\.\d+\.\d+$' }
148+
Write-Output "All production tags found: $($allProductionTags -join ', ')"
149+
150+
$lastProductionTag = $allProductionTags |
151+
Where-Object { $_ -ne $currentVersion } |
152+
Sort-Object { [Version]($_ -replace '^v', '') } |
153+
Select-Object -Last 1
154+
155+
if ($lastProductionTag) {
156+
Write-Output "Last production tag: $lastProductionTag"
157+
echo "base=$lastProductionTag" >> $env:GITHUB_OUTPUT
158+
} else {
159+
Write-Output "No previous production tag found - this is the first release"
160+
# For first release, compare against repository root to include all files
161+
$rootCommit = git rev-list --max-parents=0 HEAD
162+
Write-Output "Using root commit: $rootCommit"
163+
echo "base=$rootCommit" >> $env:GITHUB_OUTPUT
164+
}
165+
} else {
166+
Write-Output "Pre-release build (Label: '${{ steps.gitversion.outputs.GitVersion_PreReleaseLabel }}') - using default base"
167+
echo "base=" >> $env:GITHUB_OUTPUT
168+
}
169+
} catch {
170+
Write-Error "Error determining filter base: $_"
171+
Write-Output "Falling back to default base"
172+
echo "base=" >> $env:GITHUB_OUTPUT
173+
}
174+
81175
- uses: dorny/paths-filter@v3
82176
id: filter
83177
with:
84178
list-files: json
179+
base: ${{ steps.filter-base.outputs.base }}
85180
filters: |
86181
src:
87182
- 'src/**'
@@ -94,9 +189,19 @@ jobs:
94189
shell: pwsh
95190
run: |
96191
Write-Output "=== PATH FILTER DEBUG ==="
97-
Write-Output "src filter result: ${{ steps.filter.outputs.src }}"
98-
Write-Output "docs filter result: ${{ steps.filter.outputs.docs }}"
99-
Write-Output "automation filter result: ${{ steps.filter.outputs.automation }}"
192+
Write-Output "Event: ${{ github.event_name }}"
193+
Write-Output "Ref: ${{ github.ref }}"
194+
Write-Output "Filter base used: '${{ steps.filter-base.outputs.base }}'"
195+
Write-Output "Ring: '${{ steps.RingDetection.outputs.Ring }}'"
196+
Write-Output "Current GitVersion: v${{ steps.gitversion.outputs.GitVersion_SemVer }}"
197+
Write-Output "Pre-release label: '${{ steps.gitversion.outputs.GitVersion_PreReleaseLabel }}'"
198+
Write-Output "---"
199+
Write-Output "Filter results:"
200+
Write-Output " src: ${{ steps.filter.outputs.src }}"
201+
Write-Output " docs: ${{ steps.filter.outputs.docs }}"
202+
Write-Output " automation: ${{ steps.filter.outputs.automation }}"
203+
Write-Output "---"
204+
Write-Output "Files that matched filters:"
100205
Write-Output "src files:"
101206
Write-Output '${{ steps.filter.outputs.src_files }}'
102207
Write-Output "docs files:"
@@ -124,68 +229,37 @@ jobs:
124229
Write-Output "-------------------------------------------"
125230
Write-Output "Ring Control Setup"
126231
Write-Output "-------------------------------------------"
127-
$Ring = "Canary"
232+
$Ring = "${{ steps.RingDetection.outputs.Ring }}"
128233
$WingetApplicationId = "nkdagility.azure-devops-migration-tools"
129-
$docs_deploy_folder = "./azure-devops-migration-tools/";
130-
$docs_baseURL = "/learn/azure-devops-migration-tools"
131-
$docs_baseURL_AFD = "/learn/azure-devops-migration-tools"
132234
$RunCodeRelease = 'false'
133235
$RunDocsRelease = 'false'
134-
switch ($Env:GitVersion_PreReleaseLabel) {
135-
"" {
136-
$Ring = "Production";
236+
switch ("${{ steps.RingDetection.outputs.Ring }}") {
237+
"Production" {
137238
$WingetApplicationId = "nkdagility.azure-devops-migration-tools";
138-
$docs_deploy_folder = "./azure-devops-migration-tools/"
139-
$docs_baseURL = ""
140-
$docs_baseURL_AFD = ""
141239
$AzureSitesEnvironment = ""
142240
$RunRelease = 'true'
143241
}
144242
"Preview" {
145-
$Ring = "Preview";
146243
$WingetApplicationId = "nkdagility.azure-devops-migration-tools.Preview";
147-
$docs_deploy_folder = "./azure-devops-migration-tools/";
148-
$docs_baseURL = ""
149-
$docs_baseURL_AFD = ""
150244
$AzureSitesEnvironment = "preview";
151245
$RunRelease = ( ('${{ inputs.ForceRelease }}' -eq 'true' ) -or ('${{ steps.filter.outputs.src }}' -eq 'true') -or ('${{ steps.filter.outputs.docs }}' -eq 'true') )
152246
}
153247
default {
154-
$Ring = "Canary";
155248
$WingetApplicationId = "nkdagility.azure-devops-migration-tools.Canary";
156-
$docs_deploy_folder = "./azure-devops-migration-tools/canary/$branchSafeName"
157-
$docs_baseURL = "/"
158-
$docs_baseURL_AFD = ""
159-
$AzureSitesEnvironment = "canary-${{ github.event.pull_request.number }}"
249+
$AzureSitesEnvironment = "${{ steps.RingDetection.outputs.Ring }}-${{ github.event.pull_request.number }}".ToLower()
160250
$RunRelease = 'false'
161251
}
162252
}
163253
Write-Output "We are running for the $Ring Ring!"
164254
echo "Ring=$Ring" >> $env:GITHUB_OUTPUT
165255
Write-Output "We are focused on Winget ID $WingetApplicationId!"
166256
echo "WingetApplicationId=$WingetApplicationId" >> $env:GITHUB_OUTPUT
167-
Write-Output "docs_deploy_folder=$docs_deploy_folder"
168-
echo "docs_deploy_folder=$docs_deploy_folder" >> $env:GITHUB_OUTPUT
169-
Write-Output "docs_baseURL=$docs_baseURL"
170-
echo "docs_baseURL=$docs_baseURL" >> $env:GITHUB_OUTPUT
171-
Write-Output "docs_baseURL_AFD=$docs_baseURL_AFD"
172-
echo "docs_baseURL_AFD=$docs_baseURL_AFD" >> $env:GITHUB_OUTPUT
173257
174258
Write-Output "We are running for the $AzureSitesEnvironment AzureSitesEnvironment!"
175259
echo "AzureSitesEnvironment=$AzureSitesEnvironment" >> $env:GITHUB_OUTPUT
176260
Write-Output "RunRelease=$RunRelease"
177261
echo "RunRelease=$RunRelease" >> $env:GITHUB_OUTPUT
178262
Write-Output "-------------------------------------------"
179-
Write-Output "::endgroup::"
180-
# Docs Setup
181-
Write-Output "::group::Docs Setup"
182-
Write-Output "-------------------------------------------"
183-
Write-Output "Docs"
184-
Write-Output "-------------------------------------------"
185-
$docs_version_folder = "/azure-devops-migration-tools/$Env:GitVersion_SemVer"
186-
Write-Output "docs_version_folder=$docs_version_folder"
187-
echo "docs_version_folder=$docs_version_folder" >> $env:GITHUB_OUTPUT
188-
Write-Output "-------------------------------------------"
189263
Write-Output "::endgroup::"
190264
# Get-ReleaseDescription
191265
Write-Output "::group::Release Description Setup"

0 commit comments

Comments
 (0)