Skip to content

Commit b3b7bbd

Browse files
committed
Add basic yml for running PR tests in dnup
we will want to consolidate this into the SDK later. run pr ci on dnup 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 1fc9790 commit b3b7bbd

File tree

4 files changed

+234
-27
lines changed

4 files changed

+234
-27
lines changed

.vsts-dnup-pr.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
trigger:
2+
branches:
3+
include:
4+
- dnup
5+
paths:
6+
include:
7+
- src/Installer/dnup/
8+
- test/dnup.Tests/
9+
- global.json
10+
- .vsts-dnup-tests.yml
11+
12+
parameters:
13+
- name: enableArm64Job
14+
displayName: Enables the ARM64 job
15+
type: boolean
16+
default: true
17+
18+
variables:
19+
20+
pr:
21+
branches:
22+
include:
23+
- dnup
24+
- main
25+
paths:
26+
include:
27+
- src/Installer/dnup/
28+
- test/dnup.Tests/
29+
- global.json
30+
- .vsts-dnup-tests.yml
31+
32+
variables:
33+
buildConfiguration: Release
34+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
35+
DOTNET_CLI_TELEMETRY_OPTOUT: 1
36+
37+
stages:
38+
- stage: dnup_tests
39+
displayName: dnup tests
40+
jobs:
41+
- template: /eng/pipelines/templates/jobs/dnup-tests.yml@self
42+
parameters:
43+
os: windows
44+
pool:
45+
name: $(DncEngPublicBuildPool)
46+
demands: ImageOverride -equals windows.vs2022.amd64.open
47+
- template: /eng/pipelines/templates/jobs/dnup-tests.yml@self
48+
parameters:
49+
os: linux
50+
pool:
51+
name: $(DncEngPublicBuildPool)
52+
demands: ImageOverride -equals build.ubuntu.2204.amd64.open
53+
- template: /eng/pipelines/templates/jobs/dnup-tests.yml@self
54+
parameters:
55+
os: macOS
56+
pool:
57+
name: Azure Pipelines
58+
vmImage: macOS-latest

.vsts-pr.yml

Lines changed: 70 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pr:
88
- main
99
- release/*
1010
- internal/release/*
11+
- dnup
1112
paths:
1213
exclude:
1314
- documentation/*
@@ -24,56 +25,98 @@ variables:
2425
- template: /eng/pipelines/templates/variables/sdk-defaults.yml
2526
# Variables used: DncEngPublicBuildPool
2627
- template: /eng/common/templates/variables/pool-providers.yml
28+
# Variable to determine if PR changes are limited to dnup paths
29+
- name: isDnupOnlyChanges
30+
value: $[in(variables['Build.Reason'], 'PullRequest', 'Manual')]
2731

2832
resources:
2933
containers:
3034
- container: azureLinux30Amd64
3135
image: mcr.microsoft.com/dotnet-buildtools/prereqs:azurelinux-3.0-net10.0-build-amd64
3236

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

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
65+
- template: /eng/pipelines/templates/jobs/dnup-tests.yml
66+
parameters:
67+
pool:
68+
name: $(DncEngPublicBuildPool)
69+
demands: ImageOverride -equals build.ubuntu.2204.amd64.open
5370
os: linux
54-
helixTargetQueue: ubuntu.2204.amd64.open
5571

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

78121
############### DOTNET-FORMAT ###############
79122
- template: /eng/dotnet-format/dotnet-format-integration.yml
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
parameters:
2+
# Basic parameters mirroring style of other job templates
3+
pool: {}
4+
categoryName: dnupTests
5+
dependsOn: ''
6+
variables: {}
7+
oneESCompat:
8+
templateFolderName: templates
9+
publishTaskPrefix: ''
10+
timeoutInMinutes: 60
11+
os: windows
12+
13+
jobs:
14+
- job: ${{ parameters.categoryName }}_${{ parameters.os }}
15+
displayName: 'dnup tests: ${{ parameters.os }}'
16+
timeoutInMinutes: ${{ parameters.timeoutInMinutes }}
17+
pool: ${{ parameters.pool }}
18+
dependsOn: ${{ parameters.dependsOn }}
19+
variables:
20+
- ${{ insert }}: ${{ parameters.variables }}
21+
steps:
22+
- ${{ if eq(parameters.os, 'windows') }}:
23+
- powershell: |
24+
Write-Host "Restoring dnup tests"
25+
dotnet restore test/dnup.Tests/dnup.Tests.csproj
26+
displayName: Restore
27+
- powershell: |
28+
dotnet build test/dnup.Tests/dnup.Tests.csproj -c Release --no-restore
29+
displayName: Build
30+
- powershell: |
31+
dotnet test test/dnup.Tests/dnup.Tests.csproj -c Release --no-build --logger "trx;LogFileName=dnup-tests.trx" --results-directory $(Build.SourcesDirectory)/artifacts/dnupTestResults
32+
displayName: Test
33+
- ${{ if ne(parameters.os, 'windows') }}:
34+
- script: |
35+
echo "Restoring dnup tests"
36+
dotnet restore test/dnup.Tests/dnup.Tests.csproj
37+
displayName: Restore
38+
- script: |
39+
dotnet build test/dnup.Tests/dnup.Tests.csproj -c Release --no-restore
40+
displayName: Build
41+
- script: |
42+
dotnet test test/dnup.Tests/dnup.Tests.csproj -c Release --no-build --logger "trx;LogFileName=dnup-tests.trx" --results-directory $(Build.SourcesDirectory)/artifacts/dnupTestResults
43+
displayName: Test
44+
- task: PublishTestResults@2
45+
displayName: Publish dnup test results
46+
condition: always()
47+
inputs:
48+
testResultsFormat: VSTest
49+
testResultsFiles: '**/dnup-tests.trx'
50+
searchFolder: $(Build.SourcesDirectory)/artifacts/dnupTestResults
51+
testRunTitle: 'dnup ${{ parameters.os }}'
52+
- task: PublishBuildArtifacts@1
53+
displayName: Publish dnup test artifacts
54+
condition: always()
55+
inputs:
56+
PathtoPublish: $(Build.SourcesDirectory)/artifacts/dnupTestResults
57+
ArtifactName: dnupTestResults_${{ parameters.os }}
58+
publishLocation: Container
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)