How to Build and Publish a VS Code Extension in GitHub Actions
Publishing a VS Code extension by hand from a laptop drifts from the tagged source; CI ties the published version to the tag.
Install @vscode/vsce, run vsce package to produce a .vsix, then vsce publish with a Marketplace PAT on tag pushes.
Steps
- Create a Marketplace Personal Access Token and store it as
VSCE_PAT. - Install dependencies and build the extension.
- Package with
vsce packageto verify the.vsixis valid. - Run
vsce publishon tag pushes so the version matches the tag.
Workflow
.github/workflows/publish-extension.yml
name: Publish Extension
on:
push:
tags: ['v*']
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: '20' }
- run: npm ci
- run: npm run compile
- run: npx @vscode/vsce package
- run: npx @vscode/vsce publish --pat ${{ secrets.VSCE_PAT }}
- uses: actions/upload-artifact@v4
with:
name: vsix
path: '*.vsix'Notes
- The
package.jsonversionmust match the tag, or the Marketplace will reject a duplicate. - Upload the
.vsixas an artifact so you can attach it to a GitHub Release.
Related guides
How to Create a GitHub Release from a Tag in GitHub ActionsCreate a GitHub Release automatically when a version tag is pushed, generating release notes and attaching bu…
How to Publish an npm Package in GitHub ActionsPublish an npm package from GitHub Actions on a release - set up the registry with the auth token, run npm pu…