Skip to content

Commit 1c5b13c

Browse files
azure-sdkraych1
andauthored
support spec PR trigger (Azure#39372)
Co-authored-by: ray chen <[email protected]>
1 parent a500eaf commit 1c5b13c

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

eng/common/pipelines/templates/jobs/archetype-spec-gen-sdk.yml

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ parameters:
55
type: string
66
- name: SpecRepoCommit
77
type: string
8-
default: 'HEAD'
8+
default: '$(Build.SourceBranch)'
99
- name: SdkRepoCommit
1010
type: string
1111
default: 'HEAD'
@@ -47,6 +47,15 @@ jobs:
4747
- checkout: none
4848

4949
- pwsh: |
50+
$tspConfigPathPattern = '^specification\/([^\/]+\/)+tspconfig\.yaml$'
51+
$readmePathPattern = '^specification\/([^\/]+\/){2,}readme\.md$'
52+
if (('${{ parameters.ConfigType }}' -eq 'TypeSpec') -and ('${{ parameters.ConfigPath }}' -notmatch $tspConfigPathPattern)) {
53+
Write-Host "##vso[task.logissue type=error]'ConfigPath' must be a valid 'tspconfig.yaml' file path when 'ConfigType' is set to 'TypeSpec'. For example, 'specification/contosowidgetmanager/Contoso.Management/tspconfig.yaml'"
54+
Exit 1
55+
} elseif (('${{ parameters.ConfigType }}' -eq 'OpenAPI') -and ('${{ parameters.ConfigPath }}' -notmatch $readmePathPattern)) {
56+
Write-Host "##vso[task.logissue type=error]'ConfigPath' must be a valid 'readme.md' file path when 'ConfigType' is set to 'OpenAPI'. For example, 'specification/appplatform/resource-manager/readme.md'"
57+
Exit 1
58+
}
5059
$urlPattern = '^https://github\.com/(?<organization>[^/]+)/(?<repository>[^/]+)'
5160
if ('${{ parameters.SpecRepoUrl }}' -match $urlPattern) {
5261
$specRepoOwner = $Matches['organization']
@@ -64,11 +73,11 @@ jobs:
6473
6574
if ('${{ parameters.SdkRepoUrl }}' -match $urlPattern) {
6675
if ('${{ parameters.SpecRepoUrl }}'.EndsWith('-pr') -and (-not '${{ parameters.SdkRepoUrl }}'.EndsWith('-pr'))) {
67-
Write-Host "SdkRepoUrl must be a private repository if SpecRepoUrl is a private repository."
76+
Write-Host "##vso[task.logissue type=error]SdkRepoUrl must be a private repository if SpecRepoUrl is a private repository."
6877
Exit 1
6978
}
7079
71-
$sdkRepoOwner = if ('$(SdkRepoOwner)' -eq '') { $Matches['organization'] } else { '$(SdkRepoOwner)' }
80+
$sdkRepoOwner = $Matches['organization']
7281
Write-Host "##vso[task.setvariable variable=SdkRepoOwner]$sdkRepoOwner"
7382
Write-Host "SdkRepoOwner variable set to: $sdkRepoOwner"
7483
@@ -82,16 +91,10 @@ jobs:
8291
}
8392
8493
if ([string]::IsNullOrEmpty($SpecRepoOwner) -or [string]::IsNullOrEmpty($SpecRepoName) -or [string]::IsNullOrEmpty($SdkRepoOwner) -or [string]::IsNullOrEmpty($SdkRepoName)) {
85-
Write-Host "One or more required variables is empty or invalid. Ensure that SpecRepourl and SdkRepoUrl are set to valid GitHub repository URLs."
94+
Write-Host "##vso[task.logissue type=error]One or more required variables is empty or invalid. Ensure that SpecRepoUrl and SdkRepoUrl are set to valid GitHub repository URLs."
8695
Exit 1
8796
}
8897
89-
$sdkRepoNameForSpecGen = $sdkRepoName
90-
if ($sdkRepoName.EndsWith('-for-net')) {
91-
$sdkRepoNameForSpecGen = $sdkRepoName + "-track2"
92-
}
93-
Write-Host "##vso[task.setvariable variable=SdkRepoNameForSpecGen]$sdkRepoNameForSpecGen"
94-
Write-Host "SdkRepoNameForSpecGen variable set to: $sdkRepoNameForSpecGen"
9598
displayName: "Create Run Time Variables"
9699
97100
- template: /eng/common/pipelines/templates/steps/sparse-checkout.yml
@@ -112,7 +115,7 @@ jobs:
112115
SkipCheckoutNone: true
113116

114117
- script: |
115-
if [ "${{ parameters.SpecRepoCommit }}" = "HEAD" ]; then
118+
if [ "${{ parameters.SpecRepoCommit }}" = "$(Build.SourceBranch)" ]; then
116119
cd $(SpecRepoDirectory)
117120
default_commit=$(git rev-parse HEAD)
118121
echo "##vso[task.setvariable variable=SpecRepoCommit]$default_commit"
@@ -148,6 +151,12 @@ jobs:
148151
sdk_gen_info="$sdk_gen_info '${{ parameters.ConfigPath }}',"
149152
fi
150153
154+
if [ "$(Build.Reason)" = "PullRequest" ]; then
155+
optional_params="$optional_params --n=$(System.PullRequest.PullRequestNumber)"
156+
specPrUrl="${{ parameters.SpecRepoUrl }}/pull/$(System.PullRequest.PullRequestNumber)"
157+
sdk_gen_info="$sdk_gen_info spec PR: $specPrUrl"
158+
fi
159+
151160
sdk_gen_info="$sdk_gen_info and CommitSHA: '$(SpecRepoCommit)', in SpecRepo: '${{ parameters.SpecRepoUrl }}'"
152161
echo "##vso[task.setvariable variable=GeneratedSDKInformation]$sdk_gen_info"
153162
echo "Generated SDK Information : $sdk_gen_info"
@@ -156,7 +165,7 @@ jobs:
156165
--scp "$(SpecRepoDirectory)" \
157166
--sdp "$(SdkRepoDirectory)" \
158167
--wf "$(System.DefaultWorkingDirectory)" \
159-
-l "$(SdkRepoNameForSpecGen)" \
168+
-l "$(SdkRepoName)" \
160169
-c "$(SpecRepoCommit)" \
161170
-t $true \
162171
$optional_params
@@ -210,7 +219,7 @@ jobs:
210219

211220
- task: PowerShell@2
212221
displayName: Create pull request
213-
condition: and(succeeded(), eq(variables['HasChanges'], 'true'))
222+
condition: and(succeeded(), eq(variables['HasChanges'], 'true'), ne(variables['Build.Reason'], 'PullRequest'))
214223
inputs:
215224
pwsh: true
216225
workingDirectory: $(SdkRepoDirectory)

0 commit comments

Comments
 (0)