Skip to content

Commit 045ff7b

Browse files
committed
I don't have permission to add a pipeline so let's try to filter them out
I wish there was a built in method for yml to do this instead. For example, pr: has exclude which lets us not run the ci if changes are only in certain components. Ideally we could do something similar for the stages and condition them based on dnup/ non dnup changes? Note that we still need to have the .vsts-pr.yml file as the root pipeline file, and we can't just exclude running the entire thing as it controls the SDK pipeline as well.
1 parent c7e95cb commit 045ff7b

File tree

2 files changed

+117
-27
lines changed

2 files changed

+117
-27
lines changed

.vsts-pr.yml

Lines changed: 69 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,56 +24,98 @@ variables:
2424
- template: /eng/pipelines/templates/variables/sdk-defaults.yml
2525
# Variables used: DncEngPublicBuildPool
2626
- template: /eng/common/templates/variables/pool-providers.yml
27+
# Variable to determine if PR changes are limited to dnup paths
28+
- name: isDnupOnlyChanges
29+
value: $[in(variables['Build.Reason'], 'PullRequest', 'Manual')]
2730

2831
resources:
2932
containers:
3033
- container: azureLinux30Amd64
3134
image: mcr.microsoft.com/dotnet-buildtools/prereqs:azurelinux-3.0-net10.0-build-amd64
3235

3336
stages:
34-
############### BUILD STAGE ###############
35-
- stage: build
36-
displayName: Build
37+
############### FILTER CHANGES STAGE ###############
38+
- stage: filter_changes
39+
displayName: Filter PR Changes
3740
jobs:
38-
############### WINDOWS ###############
39-
- template: /eng/pipelines/templates/jobs/sdk-job-matrix.yml@self
41+
- template: /eng/pipelines/templates/jobs/filter-dnup-changes.yml
4042
parameters:
4143
pool:
4244
name: $(DncEngPublicBuildPool)
4345
demands: ImageOverride -equals windows.vs2022.amd64.open
46+
47+
############### BUILD STAGE ###############
48+
- stage: build
49+
displayName: Build
50+
dependsOn: filter_changes
51+
variables:
52+
isDnupOnlyChanges: $[ stageDependencies.filter_changes.FilterDnupChanges.outputs['SetDnupFlag.isDnupOnlyChanges'] ]
53+
jobs:
54+
# If changes are dnup-only, run only dnup tests
55+
- ${{ if eq(variables['isDnupOnlyChanges'], 'true') }}:
56+
############### DNUP TESTS ONLY ###############
57+
- template: /eng/pipelines/templates/jobs/dnup-tests.yml
58+
parameters:
59+
pool:
60+
name: $(DncEngPublicBuildPool)
61+
demands: ImageOverride -equals windows.vs2022.amd64.open
4462
os: windows
45-
helixTargetQueue: windows.amd64.vs2022.pre.open
4663

47-
############### LINUX ###############
48-
- template: /eng/pipelines/templates/jobs/sdk-job-matrix.yml
49-
parameters:
50-
pool:
51-
name: $(DncEngPublicBuildPool)
52-
demands: ImageOverride -equals build.ubuntu.2204.amd64.open
64+
- template: /eng/pipelines/templates/jobs/dnup-tests.yml
65+
parameters:
66+
pool:
67+
name: $(DncEngPublicBuildPool)
68+
demands: ImageOverride -equals build.ubuntu.2204.amd64.open
5369
os: linux
54-
helixTargetQueue: ubuntu.2204.amd64.open
5570

56-
############### MACOS ###############
57-
- template: /eng/pipelines/templates/jobs/sdk-job-matrix.yml
58-
parameters:
59-
pool:
60-
name: Azure Pipelines
61-
vmImage: macOS-latest
71+
- template: /eng/pipelines/templates/jobs/dnup-tests.yml
72+
parameters:
73+
pool:
74+
name: Azure Pipelines
75+
vmImage: macOS-latest
6276
os: macOS
63-
helixTargetQueue: osx.15.amd64.open
64-
### ARM64 ###
65-
- ${{ if eq(parameters.enableArm64Job, true) }}:
77+
78+
# Otherwise run the full SDK matrix
79+
- ${{ if ne(variables['isDnupOnlyChanges'], 'true') }}:
80+
############### WINDOWS ###############
81+
- template: /eng/pipelines/templates/jobs/sdk-job-matrix.yml@self
82+
parameters:
83+
pool:
84+
name: $(DncEngPublicBuildPool)
85+
demands: ImageOverride -equals windows.vs2022.amd64.open
86+
os: windows
87+
helixTargetQueue: windows.amd64.vs2022.pre.open
88+
89+
############### LINUX ###############
90+
- template: /eng/pipelines/templates/jobs/sdk-job-matrix.yml
91+
parameters:
92+
pool:
93+
name: $(DncEngPublicBuildPool)
94+
demands: ImageOverride -equals build.ubuntu.2204.amd64.open
95+
os: linux
96+
helixTargetQueue: ubuntu.2204.amd64.open
97+
98+
############### MACOS ###############
6699
- template: /eng/pipelines/templates/jobs/sdk-job-matrix.yml
67100
parameters:
68101
pool:
69102
name: Azure Pipelines
70103
vmImage: macOS-latest
71104
os: macOS
72-
helixTargetQueue: osx.13.arm64.open
73-
macOSJobParameterSets:
74-
- categoryName: TestBuild
75-
targetArchitecture: arm64
76-
runtimeIdentifier: osx-arm64
105+
helixTargetQueue: osx.15.amd64.open
106+
### ARM64 ###
107+
- ${{ if eq(parameters.enableArm64Job, true) }}:
108+
- template: /eng/pipelines/templates/jobs/sdk-job-matrix.yml
109+
parameters:
110+
pool:
111+
name: Azure Pipelines
112+
vmImage: macOS-latest
113+
os: macOS
114+
helixTargetQueue: osx.13.arm64.open
115+
macOSJobParameterSets:
116+
- categoryName: TestBuild
117+
targetArchitecture: arm64
118+
runtimeIdentifier: osx-arm64
77119

78120
############### DOTNET-FORMAT ###############
79121
- template: /eng/dotnet-format/dotnet-format-integration.yml
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Filter job to check if changes are dnup-only
2+
parameters:
3+
pool: {}
4+
5+
jobs:
6+
- job: FilterDnupChanges
7+
displayName: Filter dnup-only Changes
8+
pool: ${{ parameters.pool }}
9+
10+
steps:
11+
- checkout: self
12+
fetchDepth: 0
13+
14+
- powershell: |
15+
# Initialize the variable to false
16+
$isDnupOnly = $true
17+
18+
# If PR, get the changed files
19+
if ($env:BUILD_REASON -eq 'PullRequest') {
20+
Write-Host "This is a PR build, checking changed files..."
21+
$targetBranch = "$env:SYSTEM_PULLREQUEST_TARGETBRANCH"
22+
Write-Host "Target branch: $targetBranch"
23+
24+
# Get changed files in the PR
25+
$changedFiles = git diff --name-only origin/$targetBranch..HEAD
26+
27+
Write-Host "Changed files:"
28+
$changedFiles | ForEach-Object { Write-Host " $_" }
29+
30+
# Check if any changed files are outside dnup paths
31+
foreach ($file in $changedFiles) {
32+
if (-not ($file.StartsWith("src/Installer/") -or $file.StartsWith("test/dnup.Tests/"))) {
33+
Write-Host "Found change outside dnup paths: $file"
34+
$isDnupOnly = $false
35+
break
36+
}
37+
}
38+
} else {
39+
# If not a PR, we assume it's not dnup-only
40+
Write-Host "This is not a PR build, setting isDnupOnly to false"
41+
$isDnupOnly = $false
42+
}
43+
44+
# Set the variable for later stages
45+
Write-Host "##vso[task.setvariable variable=isDnupOnlyChanges;isOutput=true]$isDnupOnly"
46+
Write-Host "isDnupOnlyChanges = $isDnupOnly"
47+
displayName: Check if changes are dnup-only
48+
name: SetDnupFlag

0 commit comments

Comments
 (0)