Skip to content

Commit 05caac3

Browse files
Split generator pipelines and make E2E publish work (#49321)
* tsp-client debug * backtick * workingdirectory * add working directory * source * don't install globally * outputdir * sources * fix path * Pass version * backtick * use eng * print emitter version * fix print * remove version * fix * relative path * add back version * Temp work for multiple-emitter-prs * create dir * pass name * fix version * fix file name * fix filename * fix build path * fix working directory and always pass emitter path * Use parameter default * npmrc * ci * remove packagename * remove pn * make lockfiles * skip mgmt for now * fix outputdirectory build * copy nmrc to source dir * fix npmrc * print the registry * ugh * fix overrides * add logging * fix escaped $ * fix $ * log * print overrides * fix * fix override path * actually commit changes * buildartifactspath * more logs * fix path * updates * restore * fix * remove lockfilespath * fix arg * if * logging * Add package path * sync * move inside function * check-codegen * Revert unintended change * revert doc * delete artifacts * revert * delete * revert * revert --------- Co-authored-by: Patrick Hallisey <[email protected]>
1 parent a134521 commit 05caac3

File tree

6 files changed

+199
-129
lines changed

6 files changed

+199
-129
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
trigger:
2+
branches:
3+
include:
4+
- main
5+
paths:
6+
include:
7+
- eng/packages/http-client-csharp
8+
- eng/packages/http-client-csharp-mgmt
9+
- eng/scripts/typespec
10+
pr:
11+
branches:
12+
include:
13+
- main
14+
- feature/*
15+
- hotfix/*
16+
- release/*
17+
paths:
18+
include:
19+
- eng/packages/http-client-csharp
20+
- eng/packages/http-client-csharp-mgmt
21+
- eng/scripts/typespec
22+
23+
parameters:
24+
- name: UseTypeSpecNext
25+
displayName: "Use TypeSpec Next"
26+
type: boolean
27+
default: false
28+
- name: ShouldPublish
29+
displayName: "Publish packages"
30+
type: boolean
31+
default: false
32+
- name: PublishPublic
33+
displayName: "Publish to npmjs.org"
34+
type: boolean
35+
default: false
36+
- name: ShouldRegenerate
37+
displayName: "Regenerate clients"
38+
type: boolean
39+
default: false
40+
41+
variables:
42+
- template: /eng/pipelines/templates/variables/image.yml
43+
44+
extends:
45+
template: /eng/common/pipelines/templates/archetype-typespec-emitter.yml
46+
parameters:
47+
EmitterPackageJsonPath: eng/http-client-csharp-mgmt-emitter-package.json
48+
EmitterPackagePath: eng/packages/http-client-csharp-mgmt
49+
SparseCheckoutPaths:
50+
- /sdk/core/Azure.Core/src/Shared
51+
- /sdk/core/Azure.Core.TestFramework/src
52+
BuildPrereleaseVersion: true
53+
UseTypeSpecNext: ${{ parameters.UseTypeSpecNext }}
54+
${{ if eq(variables['System.TeamProject'], 'internal') }}:
55+
${{ if eq(variables['Build.Reason'], 'Manual') }}:
56+
ShouldPublish: ${{ parameters.ShouldPublish }}
57+
${{ if startswith(variables['Build.SourceBranch'], 'refs/pull/') }}: # PR ref's can't be published to public, even in a manual run
58+
PublishPublic: false
59+
PublishDependsOnTest: false
60+
${{ else }}: # Any other manual run can go to public
61+
PublishPublic: ${{ parameters.PublishPublic }}
62+
PublishDependsOnTest: ${{ parameters.PublishPublic }}
63+
${{ else }}: # All automatic runs publish, but only CI of main goes public
64+
ShouldPublish: true
65+
PublishDependsOnTest: false
66+
PublishPublic: ${{ and(eq(variables['Build.Reason'], 'IndividualCI'), eq(variables['Build.SourceBranch'], 'refs/heads/main')) }}
67+
RegenerationJobCount: 5
68+
MinimumPerJob: 10
69+
OnlyGenerateTypespec: true
70+
TestMatrix:
71+
All:
72+
TestArguments: -UnitTests -GenerationChecks -Filter .NET
73+
SpectorName: "http-client-csharp-mgmt"

eng/packages/http-client-csharp/ci.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ trigger:
55
paths:
66
include:
77
- eng/packages/http-client-csharp
8-
- eng/packages/http-client-csharp-mgmt
98
- eng/scripts/typespec
109
pr:
1110
branches:
@@ -17,14 +16,9 @@ pr:
1716
paths:
1817
include:
1918
- eng/packages/http-client-csharp
20-
- eng/packages/http-client-csharp-mgmt
2119
- eng/scripts/typespec
2220

2321
parameters:
24-
- name: BuildPrereleaseVersion
25-
displayName: "Build prerelease version"
26-
type: boolean
27-
default: true
2822
- name: UseTypeSpecNext
2923
displayName: "Use TypeSpec Next"
3024
type: boolean
@@ -48,11 +42,12 @@ variables:
4842
extends:
4943
template: /eng/common/pipelines/templates/archetype-typespec-emitter.yml
5044
parameters:
51-
EmitterPackageJsonPath: /eng/azure-typespec-emitter-package.json
45+
EmitterPackageJsonOutputPath: eng/http-client-csharp-emitter-package.json
46+
EmitterPackagePath: eng/packages/http-client-csharp
5247
SparseCheckoutPaths:
5348
- /sdk/core/Azure.Core/src/Shared
5449
- /sdk/core/Azure.Core.TestFramework/src
55-
BuildPrereleaseVersion: ${{ parameters.BuildPrereleaseVersion }}
50+
BuildPrereleaseVersion: true
5651
UseTypeSpecNext: ${{ parameters.UseTypeSpecNext }}
5752
${{ if eq(variables['System.TeamProject'], 'internal') }}:
5853
${{ if eq(variables['Build.Reason'], 'Manual') }}:
Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,76 @@
11
#Requires -Version 7.0
22

33
param(
4-
[string] $BuildNumber,
54
[string] $OutputDirectory,
6-
[switch] $Prerelease,
7-
[switch] $TargetNpmJsFeed
5+
[switch] $TargetNpmJsFeed,
6+
[string] $emitterPackagePath
87
)
98

109
$ErrorActionPreference = 'Stop'
1110
Set-StrictMode -Version 3.0
1211
. "$PSScriptRoot/../../common/scripts/common.ps1"
1312
Set-ConsoleEncoding
1413

15-
$packageRoot = Resolve-Path "$RepoRoot/eng/packages/http-client-csharp"
16-
$mgmtPackageRoot = Resolve-Path "$RepoRoot/eng/packages/http-client-csharp-mgmt"
17-
$outputPath = $OutputDirectory ? $OutputDirectory : (Join-Path $packageRoot "artifacts" "build")
18-
$mgmtOutputPath = $OutputDirectory ? $OutputDirectory : (Join-Path $mgmtPackageRoot "artifacts" "build")
19-
2014
function Build-Emitter {
2115
param (
2216
[string]$packageRoot,
23-
[string]$outputPath
17+
[string]$outputPath,
18+
[hashtable]$overrides
2419
)
2520

2621
Push-Location $packageRoot
2722
try {
2823
Write-Host "Working in $PWD"
29-
30-
$outputPath = New-Item -ItemType Directory -Force -Path $outputPath | Select-Object -ExpandProperty FullName
31-
32-
$emitterVersion = (npm pkg get version).Trim('"')
24+
Write-Host "TargetNpmJsFeed: $TargetNpmJsFeed"
3325

34-
if ($BuildNumber) {
35-
# set package versions
36-
$versionTag = $Prerelease ? "-alpha" : "-beta"
37-
38-
$emitterVersion = "$($emitterVersion.Split('-')[0])$versionTag.$BuildNumber"
39-
Write-Host "Setting output variable 'emitterVersion' to $emitterVersion"
40-
Write-Host "##vso[task.setvariable variable=emitterVersion;isoutput=true]$emitterVersion"
41-
}
26+
$outputPath = New-Item -ItemType Directory -Force -Path $outputPath | Select-Object -ExpandProperty FullName
4227

4328
# build and pack the emitter
44-
Invoke-LoggedCommand "npm install @types/node --save-dev" -GroupOutput
4529
Invoke-LoggedCommand "npm run build" -GroupOutput
4630

47-
if ($BuildNumber) {
48-
Write-Host "Updating version package.json to the new emitter version`n"
49-
Invoke-LoggedCommand "npm pkg set version=$emitterVersion"
50-
}
51-
5231
# remove any existing tarballs
5332
Remove-Item -Path "./*.tgz" -Force | Out-Null
54-
33+
5534
#pack the emitter
5635
Invoke-LoggedCommand "npm pack"
5736
$file = Get-ChildItem -Filter "*.tgz" | Select-Object -ExpandProperty FullName
5837

59-
# ensure the packages directory exists
60-
New-Item -ItemType Directory -Force -Path "$outputPath/packages" | Out-Null
38+
Write-Host "Copying $file to $outputPath"
39+
Copy-Item $file -Destination $outputPath
6140

62-
Write-Host "Copying $file to $outputPath/packages"
63-
Copy-Item $file -Destination "$outputPath/packages"
64-
65-
if ($TargetNpmJsFeed) {
66-
$overrides = @{}
67-
}
68-
else {
41+
if (!$TargetNpmJsFeed) {
6942
$feedUrl = "https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-js-test-autorest/npm/registry"
7043

71-
$overrides = @{
72-
"@azure-typespec/http-client-csharp" = "$feedUrl/@azure-typespec/http-client-csharp/-/http-client-csharp-$emitterVersion.tgz"
73-
}
44+
$packageJson = Get-Content -Path "./package.json" | ConvertFrom-Json
45+
$packageVersion = $packageJson.version
46+
$packageName = $packageJson.name
47+
48+
$unscopedName = $packageName.Split("/")[1]
49+
$overrides[$packageName] = "$feedUrl/$packageName/-/$unscopedName-$packageVersion.tgz"
7450
}
51+
52+
# restore the package.json and package-lock.json files to their original state
53+
Write-Host "Restoring package.json and package-lock.json to their original state"
54+
Invoke-LoggedCommand "git restore package.json package-lock.json"
7555
}
7656
finally {
7757
Pop-Location
7858
}
7959
}
8060

81-
Build-Emitter -packageRoot $packageRoot -outputPath $outputPath
61+
$overrides = @{}
62+
63+
$outputPath = $OutputDirectory ? $OutputDirectory : (Join-Path $RepoRoot "artifacts" "emitters")
64+
New-Item -ItemType Directory -Force -Path $outputPath | Out-Null
65+
66+
# strip leading slash from emitterPackagePath if it exists
67+
if ($emitterPackagePath.StartsWith("/")) {
68+
$emitterPackagePath = $emitterPackagePath.Substring(1)
69+
}
70+
$packageRoot = Join-Path $RepoRoot $emitterPackagePath
71+
Build-Emitter -packageRoot $packageRoot -outputPath $outputPath -overrides $overrides
72+
73+
Write-Host "Writing overrides to $outputPath/overrides.json"
8274

83-
Build-Emitter -packageRoot $mgmtPackageRoot -outputPath $mgmtOutputPath
75+
$overrides | ConvertTo-Json | Out-File -FilePath "$outputPath/overrides.json" -Encoding utf8 -Force
76+
Get-Content -Path "$outputPath/overrides.json" | Out-Host
Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,25 @@
11
#Requires -Version 7.0
22

3+
param(
4+
[string] $EmitterPackagePath
5+
)
6+
37
$ErrorActionPreference = 'Stop'
48
Set-StrictMode -Version 3.0
59

6-
$packageRoot = Resolve-Path "$PSScriptRoot../../../packages/http-client-csharp"
7-
Push-Location $packageRoot
10+
Push-Location $EmitterPackagePath
811

912
try {
10-
& "$packageRoot/eng/scripts/Generate.ps1"
13+
& "$EmitterPackagePath/eng/scripts/Generate.ps1"
1114

1215
Write-Host 'Checking generated files difference...'
1316
git -c core.safecrlf=false diff --ignore-space-at-eol --exit-code
1417
if ($LastExitCode -ne 0) {
15-
Write-Error 'Generated codes of Azure generator are not up to date. Please run: eng/packages/http-client-csharp/eng/scripts/Generate.ps1'
18+
Write-Error 'Generated code of Azure generator is not up to date. Please run: /eng/scripts/Generate.ps1'
1619
exit 1
1720
}
1821
Write-Host 'Done for Azure generator. No change is detected.'
1922
}
2023
finally {
2124
Pop-Location
2225
}
23-
24-
$mgmtPackageRoot = Resolve-Path "$PSScriptRoot../../../packages/http-client-csharp-mgmt"
25-
Push-Location $mgmtPackageRoot
26-
27-
try {
28-
& "$mgmtPackageRoot/eng/scripts/Generate.ps1"
29-
30-
Write-Host 'Checking generated files difference...'
31-
git -c core.safecrlf=false diff --ignore-space-at-eol --exit-code
32-
if ($LastExitCode -ne 0) {
33-
Write-Error 'Generated codes of mgmt generator are not up to date. Please run: eng/packages/http-client-csharp/eng/scripts/Generate.ps1'
34-
exit 1
35-
}
36-
Write-Host 'Done for mgmt generator. No change is detected.'
37-
}
38-
finally {
39-
Pop-Location
40-
}

0 commit comments

Comments
 (0)