Build and Publish VS Code Themes From Azure DevOps
Hello!
Let’s not mince words: automating builds/releases/deployments makes development an awful lot simpler. All of the VS Code theme repos have the same yaml pipeline to publish them to the Visual Studio Gallery. Once you have gone through the process of setting up a publisher in the Visual Studio Gallery it’s straightforward to automate publishing packages.
In the code below you’ll see that there is a variable called $(POSTMAN)
(no, idk why I called it this either), which is a PAT created specficially for publishing. This is set through the variables of a DevOps pipeline. I probably could use a variable group and reference that, but I’m lazy.
The process to generate a PAT is on the same page referenced earlier, but a little further up. It’s probably worth reading through the entire article, but those sections give you the gist of what’s happening.
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
name: $(BuildDefinitionName)_$(VersionNumber)_$(SourceBranchName)
variables:
- name: BaseVersionNumber
value: "0.865"
- name: Minor
value: $[counter(variables['BaseVersionNumber'], 1)]
- name: VersionNumber
value: $(BaseVersionNumber).$(Minor)
steps:
- task: PowerShell@2
displayName: "Update Build Number"
inputs:
targetType: 'inline'
script: |
$BuildName = $env:BUILD_DEFINITIONNAME +'_'+$env:VERSIONNUMBER +'_'+ $env:BUILD_SOURCEBRANCHNAME
Write-Host "##vso[build.updatebuildnumber]$BuildName"
- task: Bash@3
displayName: "Package and Publish VS Code Theme"
inputs:
targetType: 'inline'
script: |
npm install -g [email protected]
echo $PAT
git config user.email "[email protected]"
git config user.name "RichieBzzzt"
sudo npm install -g vsce
vsce package
vsce publish $(VersionNumber) -p $PAT
failOnStderr: false
workingDirectory: $(System.DefaultWorkingDirectory)
env:
PAT: $(POSTMAN)
- task: CopyFiles@2
displayName: "Copy Files to: $(build.artifactstagingdirectory)"
inputs:
Contents: |
**
TargetFolder: "$(build.artifactstagingdirectory)"
- task: PublishBuildArtifacts@1
displayName: "Publish Artifact: sofetch"
inputs:
ArtifactName: sofetch