Skip to content

Commit 04a7438

Browse files
Sync eng/common directory with azure-sdk-tools for PR 10314 (#40522)
* Move tsp-client step to regenerate stage * Update comment * open as draft logic and fix emitter version * add comment --------- Co-authored-by: jolov <[email protected]>
1 parent f1807e7 commit 04a7438

File tree

1 file changed

+38
-42
lines changed

1 file changed

+38
-42
lines changed

eng/common/pipelines/templates/archetype-typespec-emitter.yml

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ extends:
9898

9999
- ${{ parameters.InitializationSteps }}
100100

101+
# Initialize-WorkingDirectory.ps1 is responsible for setting the emitterVersion output variable.
101102
- task: PowerShell@2
102103
displayName: 'Run initialize script'
104+
name: initialize
103105
inputs:
104106
pwsh: true
105107
filePath: $(Build.SourcesDirectory)/eng/scripts/typespec/Initialize-WorkingDirectory.ps1
@@ -117,7 +119,6 @@ extends:
117119
118120
- task: PowerShell@2
119121
displayName: 'Run build script'
120-
name: ci_build
121122
inputs:
122123
pwsh: true
123124
filePath: $(Build.SourcesDirectory)/eng/scripts/typespec/Build-Emitter.ps1
@@ -150,10 +151,7 @@ extends:
150151
artifactPath: $(Build.ArtifactStagingDirectory)
151152

152153
# Publish stage
153-
# Responsible for publishing the packages in `build_artifacts/packages` and producing `emitter-package-lock.json`
154-
# Produces the artifact `publish_artifacts` which contains the following:
155-
# emitter-package.json: Created using the package json from the build step.
156-
# emitter-package-lock.json: Created by calling `npm install` using `emitter-package.json`
154+
# Responsible for publishing the packages in `build_artifacts/packages`
157155
- ${{ if parameters.ShouldPublish }}:
158156
- stage: Publish
159157
dependsOn:
@@ -207,36 +205,6 @@ extends:
207205
ServiceEndpointUrl: https://api.esrp.microsoft.com
208206
MainPublisher: ESRPRELPACMANTEST
209207

210-
- pwsh: |
211-
npm install -g @azure-tools/typespec-client-generator-cli@latest
212-
displayName: Install tsp-client
213-
214-
- pwsh: |
215-
Write-Host "Overrides location: $(buildArtifactsPath)/packages/overrides.json"
216-
217-
if (Test-Path -Path '$(buildArtifactsPath)/packages/overrides.json') {
218-
Write-Host "Using overrides.json to generate emitter-package.json"
219-
tsp-client generate-config-files `
220-
--package-json '$(buildArtifactsPath)/lock-files/package.json' `
221-
--output-dir '$(Build.SourcesDirectory)' `
222-
--emitter-package-json-path '${{ parameters.EmitterPackageJsonOutputPath }}' `
223-
--overrides '$(buildArtifactsPath)/packages/overrides.json'
224-
} else {
225-
Write-Host "No overrides.json found. Running tsp-client without overrides."
226-
227-
tsp-client generate-config-files `
228-
--package-json '$(buildArtifactsPath)/lock-files/package.json' `
229-
--output-dir '$(Build.SourcesDirectory)' `
230-
--emitter-package-json-path '${{ parameters.EmitterPackageJsonOutputPath }}'
231-
}
232-
displayName: Generate emitter-package.json and emitter-package-lock files
233-
workingDirectory: $(Build.SourcesDirectory)
234-
235-
- template: /eng/common/pipelines/templates/steps/publish-1es-artifact.yml
236-
parameters:
237-
artifactName: publish_artifacts
238-
artifactPath: $(Build.ArtifactStagingDirectory)
239-
240208
# Regenerate stage
241209
# Responsible for regenerating the SDK code using the emitter package and the generation matrix.
242210
- ${{ if and(parameters.ShouldPublish, parameters.ShouldRegenerate) }}:
@@ -246,7 +214,7 @@ extends:
246214
- Publish
247215
variables:
248216
pullRequestTargetBranch: 'main'
249-
publishArtifactsPath: $(Pipeline.Workspace)/publish_artifacts
217+
buildArtifactsPath: $(Pipeline.Workspace)/build_artifacts
250218
branchName: $[stageDependencies.Build.Build.outputs['set_branch_name.branchName']]
251219
pool: ${{ parameters.Pool }}
252220
jobs:
@@ -262,9 +230,27 @@ extends:
262230
displayName: Download pipeline artifacts
263231

264232
- pwsh: |
265-
Write-Host "Copying *emitter-package*.json to $(Build.SourcesDirectory)/eng"
266-
Copy-Item $(publishArtifactsPath)/*emitter-package*.json $(Build.SourcesDirectory)/eng/ -Force
267-
displayName: Copy emitter-package json files
233+
npm install -g @azure-tools/typespec-client-generator-cli@latest
234+
displayName: Install tsp-client
235+
236+
- pwsh: |
237+
Write-Host "Overrides location: $(buildArtifactsPath)/packages/overrides.json"
238+
239+
if (Test-Path -Path '$(buildArtifactsPath)/packages/overrides.json') {
240+
Write-Host "Using overrides.json to generate emitter-package.json"
241+
tsp-client generate-config-files `
242+
--package-json '$(buildArtifactsPath)/lock-files/package.json' `
243+
--emitter-package-json-path '${{ parameters.EmitterPackageJsonOutputPath }}' `
244+
--overrides '$(buildArtifactsPath)/packages/overrides.json'
245+
} else {
246+
Write-Host "No overrides.json found. Running tsp-client without overrides."
247+
248+
tsp-client generate-config-files `
249+
--package-json '$(buildArtifactsPath)/lock-files/package.json' `
250+
--emitter-package-json-path '${{ parameters.EmitterPackageJsonOutputPath }}'
251+
}
252+
displayName: Generate emitter-package.json and emitter-package-lock files
253+
workingDirectory: $(Build.SourcesDirectory)
268254
269255
- ${{ parameters.InitializationSteps }}
270256

@@ -341,7 +327,7 @@ extends:
341327
- Generate
342328
variables:
343329
generateJobResult: $[dependencies.Generate.result]
344-
emitterVersion: $[stageDependencies.Build.Build.outputs['ci_build.emitterVersion']]
330+
emitterVersion: $[stageDependencies.Build.Build.outputs['initialize.emitterVersion']]
345331
steps:
346332
- template: /eng/common/pipelines/templates/steps/sparse-checkout.yml
347333

@@ -401,6 +387,16 @@ extends:
401387
} else {
402388
Write-Error "Build.Repository.Name not in the expected {Owner}/{Name} format"
403389
}
390+
391+
$openAsDraft = -not ($reason -eq 'IndividualCI' -and $sourceBranch -eq 'refs/heads/main')
392+
Write-Host "Setting OpenAsDraftBool = $openAsDraft"
393+
Write-Host "##vso[task.setvariable variable=OpenAsDraft]$openAsDraft"
394+
if ($openAsDraft) {
395+
Write-Host "##vso[task.setvariable variable=PRLabels]Do Not Merge"
396+
} else {
397+
Write-Host "##vso[task.setvariable variable=PRLabels]"
398+
}
399+
404400
displayName: Get PR title and body
405401
406402
- task: PowerShell@2
@@ -417,8 +413,8 @@ extends:
417413
-AuthToken '$(azuresdk-github-pat)'
418414
-PRTitle '$(PullRequestTitle)'
419415
-PRBody '$(PullRequestBody)'
420-
-OpenAsDraft $true
421-
-PRLabels 'Do Not Merge'
416+
-OpenAsDraft $$(OpenAsDraft)
417+
-PRLabels '$(PRLabels)'
422418
workingDirectory: $(Build.SourcesDirectory)
423419

424420
# Test stage

0 commit comments

Comments
 (0)