Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions eng/common/pipelines/templates/archetype-typespec-emitter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ parameters:
- name: EmitterPackagePath
type: string

# Whether to bundle the emitter package and upload it to the typespec
# playground blob storage so it can be loaded by the in-browser playground
# (e.g. https://azure.github.io/typespec-azure). The upload only runs on
# non-PR builds in the internal project. Requires the `TypeSpec Storage`
# service connection.
- name: UploadPlaygroundBundle
type: boolean
default: false

extends:
template: /eng/pipelines/templates/stages/1es-redirect.yml
parameters:
Expand Down Expand Up @@ -148,6 +157,32 @@ extends:
env:
NPM_CONFIG_USERCONFIG: $(emitterNpmrcPath)

# Bundle the emitter and upload it to the typespec playground blob
# storage so the in-browser playground can load it. The previous
# `Run build script` step has already produced the package's `dist/`
# artifacts, so the bundler can run directly against them. The
# explicit --version argument records the stamped prerelease version
# in the uploaded manifest because Build-Emitter.ps1 restores
# package.json after packing.
- ${{ if and(parameters.UploadPlaygroundBundle, eq(variables['System.TeamProject'], 'internal'), ne(variables['Build.Reason'], 'PullRequest')) }}:
- script: npm ci
displayName: 'Install playground bundle uploader'
workingDirectory: $(Build.SourcesDirectory)/eng/common/playground-bundle
env:
NPM_CONFIG_USERCONFIG: $(emitterNpmrcPath)

- task: AzureCLI@2
displayName: 'Upload playground bundle'
inputs:
azureSubscription: "TypeSpec Storage"
scriptType: "bash"
scriptLocation: "inlineScript"
workingDirectory: $(Build.SourcesDirectory)
inlineScript: >
node eng/common/playground-bundle/upload.mjs
--package-path ${{ parameters.EmitterPackagePath }}
--version $(initialize.emitterVersion)

- pwsh: |
$sourceBranch = '$(Build.SourceBranch)'
$buildReason = '$(Build.Reason)'
Expand Down
30 changes: 30 additions & 0 deletions eng/common/playground-bundle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# playground-bundle

Self-contained tooling used by the shared `archetype-typespec-emitter.yml`
pipeline template to bundle a TypeSpec emitter package and upload it to the
typespec playground blob storage (`https://typespec.blob.core.windows.net/pkgs/`).

The uploaded `<pkgName>/latest.json` import map is consumed by the in-browser
TypeSpec playgrounds (e.g. the [Azure playground](https://azure.github.io/typespec-azure))
via their `additionalPlaygroundPackages` configuration.

## Files

- `package.json` — dependencies pinned for reproducibility.
- `upload.mjs` — the upload script. Mirrors `bundleAndUploadStandalonePackage`
from microsoft/typespec's `@typespec/bundle-uploader` package.

## How it is invoked

The `archetype-typespec-emitter.yml` template runs `npm ci` in this folder
and then invokes `node upload.mjs --package-path <path> --version <stamped-version>`
inside an `AzureCLI@2` task that authenticates against the `TypeSpec Storage`
service connection.

Pipelines opt in by setting `UploadPlaygroundBundle: true` on
`archetype-typespec-emitter.yml`. The bundler is run directly against the
package's already-built `dist/` (produced by `Build-Emitter.ps1`), so no
additional build step is required. The explicit `--version` argument is
needed because `Build-Emitter.ps1` restores `package.json` after packing,
which would otherwise cause the bundle manifest to record the
non-prerelease version from source control.
Loading