Skip to content

Commit

Permalink
Add support for a TypeSpec/sdk regeneration preview pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
hallipr committed Jan 26, 2024
1 parent 71273b3 commit 75b8ec4
Show file tree
Hide file tree
Showing 8 changed files with 233 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ common/autoinstallers/*/.npmrc
**/types
dist-esm
dist
/artifacts
44 changes: 44 additions & 0 deletions .scripts/preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
trigger: none
pr: none

parameters:
- name: UseTypeSpecNext
displayName: Use TypeSpec "next" version
type: boolean
default: true

resources:
repositories:
- repository: sdk-repository
type: github
endpoint: Azure
name: Azure/azure-sdk-for-js
ref: refs/heads/main
- repository: azure-sdk-tools
type: github
endpoint: Azure
name: Azure/azure-sdk-tools
ref: refs/heads/main

pool:
name: azsdk-pool-mms-win-2022-general
vmImage: windows-2022

extends:
template: eng/pipelines/templates/stages/archetype-autorest-preview.yml@azure-sdk-tools
parameters:
RegenerationJobCount: 1
BuildPrereleaseVersion: true
PublishInternal: true
UseTypeSpecNext: ${{ parameters.UseTypeSpecNext }}
EmitterPackageJsonPath: packages/typespec-ts/package.json
Packages:
- name: generator
file: autorest-typescript-*.tgz
type: npm
- name: emitter
file: azure-tools-typespec-ts-*.tgz
type: npm
- name: common
file: azure-tools-rlc-common-*.tgz
type: npm
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[powershell]": {
"editor.defaultFormatter": "ms-vscode.powershell"
}
}
26 changes: 12 additions & 14 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 72 additions & 0 deletions eng/scripts/Build-Packages.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#Requires -Version 7.0
param(
[string] $BuildNumber,
[string] $Output,
[switch] $Prerelease,
[switch] $PublishInternal
)

$ErrorActionPreference = 'Stop'
Set-StrictMode -Version 3.0
$root = (Resolve-Path "$PSScriptRoot/../..").Path.Replace('\', '/')
. "$root/eng/scripts/CommandInvocation-Helpers.ps1"
Set-ConsoleEncoding

$artifactsPath = "$root/artifacts"
$outputPath = $Output ? $Output : "$artifactsPath/ci-build"

$packagesPath = New-Item "$outputPath/packages" -ItemType Directory -Force

function UpdatePackage($name, $path) {
Push-Location $path
try {
$version = (Get-Content "./package.json" -Raw | ConvertFrom-Json).version

if ($Prerelease) {
$version = "$($version.Split('-')[0])-preview.$BuildNumber"
Invoke-LoggedCommand "npm version --allow-same-version --no-git-tag-version $version"
}

$packageMatrix[$name] = $version
}
finally {
Pop-Location
}
}

function PackPackage($path) {
Push-Location $path
try {
Invoke-LoggedCommand "node ../../common/scripts/install-run-rush.js build"
Invoke-LoggedCommand "node ../../common/scripts/install-run-rush-pnpm.js pack -q --pack-destination $packagesPath"
}
finally {
Pop-Location
}
}

$packageMatrix = @{}

UpdatePackage "common" "$root/packages/rlc-common"
UpdatePackage "generator" "$root/packages/autorest.typescript"
UpdatePackage "emitter" "$root/packages/typespec-ts"

PackPackage "$root/packages/rlc-common"
PackPackage "$root/packages/autorest.typescript"
PackPackage "$root/packages/typespec-ts"

if ($PublishInternal) {
$feedUrl = "https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-js-test-autorest/npm/registry"

$overrides = @{
"@autorest/typescript" = "$feedUrl/@autorest/typescript/-/typescript-$($packageMatrix['generator']).tgz"
"@azure-tools/typespec-ts" = "$feedUrl/@azure-tools/typespec-ts/-/typespec-ts-$($packageMatrix['emitter']).tgz"
"@azure-tools/rlc-common" = "$feedUrl/@azure-tools/rlc-common/-/rlc-common-$($packageMatrix['common']).tgz"
}
}
else {
$overrides = @{}
}

$packageMatrix | ConvertTo-Json | Set-Content "$outputPath/package-versions.json"
$overrides | ConvertTo-Json | Set-Content "$outputPath/overrides.json"
50 changes: 50 additions & 0 deletions eng/scripts/CommandInvocation-Helpers.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#Requires -Version 7.0
Set-StrictMode -Version 3.0

function Set-ConsoleEncoding {
[CmdletBinding()]
param
(
[string] $Encoding = 'utf-8'
)

$outputEncoding = [System.Text.Encoding]::GetEncoding($Encoding)
[Console]::OutputEncoding = $outputEncoding
[Console]::InputEncoding = $outputEncoding
}

function Invoke-LoggedCommand {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string] $Command,

[ValidateScript({ Test-Path $_ -PathType Container })]
[string] $ExecutePath,

[switch] $IgnoreExitCode
)

$width = [Math]::Min($Host.UI.RawUI.WindowSize.Width ?? 80, 80)
$separator = '=' * $width
$startTime = Get-Date

Push-Location $ExecutePath
try {
Write-Host "$separator`n$PWD> $Command`n$separator"
Invoke-Expression $Command

$duration = (Get-Date) - $startTime
$separator = '-' * $width

if ($IgnoreExitCode -or $LASTEXITCODE -eq 0) {
Write-Host "$separator`nExit Code: $LASTEXITCODE, Duration: $duration`n$separator`n"
}
else {
Write-Error "$separator`nExit Code: $LASTEXITCODE, Duration: $duration`n$Command`n$separator`n"
}
}
finally {
Pop-Location
}
}
44 changes: 44 additions & 0 deletions eng/scripts/Initialize-Repository.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#Requires -Version 7.0
param(
[string] $BuildArtifactsPath,
[switch] $UseTypeSpecNext
)

$ErrorActionPreference = 'Stop'
Set-StrictMode -Version 3.0
$root = (Resolve-Path "$PSScriptRoot/../..").Path.Replace('\', '/')
. "$root/eng/scripts/CommandInvocation-Helpers.ps1"
Set-ConsoleEncoding

Push-Location $root
try {
# install and list npm packages
if ($BuildArtifactsPath) {
$lockFilesPath = Resolve-Path "$BuildArtifactsPath/lock-files"
# if we were passed a build_artifacts path, use the package.json and pnpm-lock.yaml from there
Write-Host "Using emitter/package.json and pnpm-lock.yaml from $lockFilesPath"
Copy-Item "$lockFilesPath/pnpm-lock.yaml" './common/config/rush/pnpm-lock.yaml' -Force
Copy-Item "$lockFilesPath/emitter/package.json" './packages/typespec-ts/package.json' -Force
}
elseif ($UseTypeSpecNext) {
Write-Host "Using TypeSpec.Next"
Invoke-LoggedCommand "npx -y @azure-tools/typespec-bump-deps@latest --use-peer-ranges ./packages/typespec-ts/package.json"
}

Invoke-LoggedCommand "node common/scripts/install-run-rush.js update"

Invoke-LoggedCommand "npm list --all"

$artifactStagingDirectory = $env:Build_ArtifactStagingDirectory
if ($artifactStagingDirectory -and !$BuildArtifactsPath) {
$lockFilesPath = "$artifactStagingDirectory/lock-files"
New-Item -ItemType Directory -Path "$lockFilesPath/emitter" | Out-Null

Write-Host "Copying typespec-ts/package.json and pnpm-lock.yaml to $lockFilesPath"
Copy-Item './common/config/rush/pnpm-lock.yaml' "$lockFilesPath/pnpm-lock.yaml" -Force
Copy-Item './packages/typespec-ts/package.json' "$lockFilesPath/emitter/package.json" -Force
}
}
finally {
Pop-Location
}
8 changes: 7 additions & 1 deletion packages/typespec-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@
"@azure/logger": "^1.0.4",
"@azure/core-util": "^1.4.0",
"eslint-plugin-require-extensions": "0.1.3",
"@typespec/ts-http-runtime": "1.0.0-alpha.20231129.4"
"@typespec/ts-http-runtime": "1.0.0-alpha.20231129.4",
"@azure-tools/typespec-azure-core": "0.37.2",
"@azure-tools/typespec-client-generator-core": "0.37.0",
"@typespec/compiler": "0.51.0",
"@typespec/http": "0.51.0",
"@typespec/rest": "0.51.0",
"@typespec/versioning": "0.51.0"
},
"peerDependencies": {
"@azure-tools/typespec-azure-core": ">=0.37.2 <1.0.0",
Expand Down

0 comments on commit 75b8ec4

Please sign in to comment.