Skip to content

Commit

Permalink
publish vscode artifact and display in pr comment for try-it (#5206)
Browse files Browse the repository at this point in the history
Fix #5155

When there is any changes/PR about typespec-vscode, we want to provide
an extension to try. So we will publish `typespec-vscode-0.XXX.0.vsix`
as pipeline artifact, and will show `VSCode Extension` with the download
url in the try-it comment. Customer can download this extension file to
try.

---------

Co-authored-by: Mark Cowlishaw <[email protected]>
  • Loading branch information
2 people authored and Mingzhe Huang (from Dev Box) committed Dec 18, 2024
1 parent 27f0bef commit d79c532
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
26 changes: 26 additions & 0 deletions eng/tsp-core/pipelines/pr-tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,37 @@ extends:
--destination-path $(TYPESPEC_WEBSITE_BASE_PATH) \
--source "./website/dist/" \
--overwrite
- task: CopyFiles@2
displayName: "Copy VSCode extension .vsix to artifact directory"
inputs:
SourceFolder: "$(Build.SourcesDirectory)/packages/typespec-vscode"
Contents: "*.vsix"
TargetFolder: "$(Build.ArtifactStagingDirectory)/vscode-extension"
templateContext:
outputs:
- output: pipelineArtifact
path: $(Build.ArtifactStagingDirectory)/vscode-extension
artifact: vscode-extension
displayName: Copy VSCode extension .vsix to artifact directory
- job: tryit_comment
displayName: Create TryIt comment
dependsOn: tryit
steps:
- pwsh: |
$curlCommand = 'curl -s -u :$(System.AccessToken) "$(System.TeamFoundationCollectionUri)/$(System.TeamProject)/_apis/build/builds/$(Build.BuildId)/artifacts?artifactName=vscode-extension"'
$response = Invoke-Expression $curlCommand
$responseObject = $response | ConvertFrom-Json
Write-Host "response: $response"
$downloadUrl = $responseObject.resource.downloadUrl
Write-Output "Artifact URL: $downloadUrl"
Write-Host "##vso[task.setvariable variable=vscodeUrl]$downloadUrl"
displayName: Get vscode artifact URL
- script: npx tsx eng/tsp-core/scripts/create-tryit-comment.ts
displayName: Check already commented
env:
GH_TOKEN: $(azuresdk-github-pat)
VSCODE_DOWNLOAD_URL: $(vscodeUrl)

- job: change_comment
displayName: Describe changes on PR
Expand Down
12 changes: 10 additions & 2 deletions eng/tsp-core/scripts/create-tryit-comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ async function main() {
const repo = process.env["BUILD_REPOSITORY_ID"];
const prNumber = process.env["SYSTEM_PULLREQUEST_PULLREQUESTNUMBER"];
const ghToken = process.env.GH_TOKEN;
const vscodeDownloadUrl = process.env.VSCODE_DOWNLOAD_URL;
if (repo === undefined) {
throw new Error("BUILD_REPOSITORY_ID environment variable is not set");
}
Expand All @@ -33,17 +34,24 @@ async function main() {
return;
}

const comment = makeComment(folderName, prNumber);
const comment = makeComment(folderName, prNumber, vscodeDownloadUrl);
await writeComment(repo, prNumber, comment, ghAuth);
}

function makeComment(folderName: string, prNumber: string): string {
function makeComment(
folderName: string,
prNumber: string,
vscodeDownloadUrl: string | undefined,
): string {
const links = [
`[πŸ› Playground]( https://cadlplayground.z22.web.core.windows.net${folderName}/prs/${prNumber}/)`,
`[🌐 Website](https://tspwebsitepr.z22.web.core.windows.net${folderName}/prs/${prNumber}/)`,
`[πŸ“š Next docs](https://tspwebsitepr.z22.web.core.windows.net${folderName}/prs/${prNumber}/docs/next.html)`,
];

if (vscodeDownloadUrl) {
links.push(`[πŸ› VSCode Extension]( ${vscodeDownloadUrl})`);
}
return [
`<!-- ${TRY_ID_COMMENT_IDENTIFIER} -->`,
`You can try these changes here`,
Expand Down

0 comments on commit d79c532

Please sign in to comment.