|
| 1 | +# Template (steps): PublishMarketplace for autopep8 extension |
| 2 | +# Expects working directory already populated (or artifact previously downloaded) with: autopep8.vsix, extension.manifest, extension.signature.p7s |
| 3 | +# Provides optional prerelease publishing via parameter. |
| 4 | +# |
| 5 | +# Usage (example inside a stage job): |
| 6 | +# steps: |
| 7 | +# - template: build/templates/publish.yml@self |
| 8 | +# parameters: |
| 9 | +# azureSubscription: Autopep8PublishServiceConnection |
| 10 | +# artifactName: drop |
| 11 | +# vsixName: autopep8.vsix |
| 12 | +# manifestName: extension.manifest |
| 13 | +# signatureName: extension.signature.p7s |
| 14 | +# publishFolder: vscode-autopep8 |
| 15 | +# preRelease: true |
| 16 | +# noVerify: true |
| 17 | +# |
| 18 | +# Notes: |
| 19 | +# - Azure DevOps Marketplace resource GUID (499b84ac-1321-427f-aa17-267ca6975798) is hardcoded in publish script. |
| 20 | +# - This uses Managed Identity via AzureCLI@2 to acquire an AAD token and passes it as a PAT. |
| 21 | +# - Requires extension artifacts already signed (signature file present). |
| 22 | + |
| 23 | +parameters: |
| 24 | + - name: azureSubscription |
| 25 | + type: string |
| 26 | + - name: vsixName |
| 27 | + type: string |
| 28 | + default: autopep8.vsix |
| 29 | + - name: manifestName |
| 30 | + type: string |
| 31 | + default: extension.manifest |
| 32 | + - name: signatureName |
| 33 | + type: string |
| 34 | + default: extension.signature.p7s |
| 35 | + - name: publishFolder |
| 36 | + type: string |
| 37 | + default: vscode-autopep8 |
| 38 | + - name: preRelease |
| 39 | + type: boolean |
| 40 | + default: false |
| 41 | + - name: noVerify |
| 42 | + type: boolean |
| 43 | + default: true |
| 44 | + |
| 45 | +steps: |
| 46 | + # Assumes files already present at $(Build.ArtifactStagingDirectory)/publishFolder |
| 47 | + |
| 48 | + - task: AzureCLI@2 |
| 49 | + displayName: Acquire token & publish extension |
| 50 | + inputs: |
| 51 | + azureSubscription: ${{ parameters.azureSubscription }} |
| 52 | + scriptType: pscore |
| 53 | + scriptLocation: inlineScript |
| 54 | + inlineScript: | |
| 55 | + # Hardcoded Azure DevOps Marketplace resource GUID |
| 56 | + $resource = "499b84ac-1321-427f-aa17-267ca6975798" |
| 57 | + Write-Host "Acquiring AAD token for resource: $resource" |
| 58 | + az rest -u https://app.vssps.visualstudio.com/_apis/profile/profiles/me --resource $resource | Out-Null |
| 59 | + $aadToken = az account get-access-token --query accessToken --resource $resource -o tsv |
| 60 | + if (-not $aadToken) { Write-Error 'Failed to acquire AAD token.'; exit 1 } |
| 61 | +
|
| 62 | + $root = "$(Build.ArtifactStagingDirectory)/${{ parameters.publishFolder }}" |
| 63 | + $vsixPath = Join-Path $root "${{ parameters.vsixName }}" |
| 64 | + $manifestPath = Join-Path $root "${{ parameters.manifestName }}" |
| 65 | + $signaturePath = Join-Path $root "${{ parameters.signatureName }}" |
| 66 | +
|
| 67 | + Write-Host "VSIX Path: $vsixPath" |
| 68 | + Write-Host "Manifest Path: $manifestPath" |
| 69 | + Write-Host "Signature Path: $signaturePath" |
| 70 | +
|
| 71 | + if (-not (Test-Path $vsixPath)) { Write-Error "VSIX file not found: $vsixPath"; exit 1 } |
| 72 | + if (-not (Test-Path $manifestPath)) { Write-Error "Manifest file not found: $manifestPath"; exit 1 } |
| 73 | + if (-not (Test-Path $signaturePath)) { Write-Error "Signature file not found: $signaturePath"; exit 1 } |
| 74 | +
|
| 75 | + Write-Host "Listing publish folder contents: $root" |
| 76 | + Get-ChildItem -Recurse $root | Select-Object FullName,Length | Format-Table -AutoSize |
| 77 | +
|
| 78 | + $extraFlags = '' |
| 79 | + if ('${{ parameters.noVerify }}' -eq 'True') { $extraFlags = "$extraFlags --noVerify" } |
| 80 | +
|
| 81 | + if ('${{ parameters.preRelease }}' -eq 'True') { |
| 82 | + Write-Host 'Publishing as pre-release' |
| 83 | + # npx @vscode/vsce@latest publish --pat $aadToken --packagePath $vsixPath --manifestPath $manifestPath --signaturePath $signaturePath $extraFlags --pre-release |
| 84 | + } else { |
| 85 | + Write-Host 'Publishing as stable release' |
| 86 | + # npx @vscode/vsce@latest publish --pat $aadToken --packagePath $vsixPath --manifestPath $manifestPath --signaturePath $signaturePath $extraFlags |
| 87 | + } |
| 88 | +
|
| 89 | + if ($LASTEXITCODE -ne 0) { |
| 90 | + Write-Error "vsce publish failed with exit code $LASTEXITCODE" |
| 91 | + exit $LASTEXITCODE |
| 92 | + } |
| 93 | + Write-Host 'Publish succeeded ✅' |
| 94 | +
|
| 95 | + - task: PowerShell@2 |
| 96 | + displayName: Post-publish summary |
| 97 | + inputs: |
| 98 | + targetType: inline |
| 99 | + script: | |
| 100 | + Write-Host 'Published extension artifacts:' |
| 101 | + Get-ChildItem "$(Build.ArtifactStagingDirectory)/${{ parameters.publishFolder }}" -File | Select-Object Name,Length | Format-Table -AutoSize |
| 102 | + Write-Host "Pre-release parameter: ${{ parameters.preRelease }}" |
0 commit comments