Skip to content

Publish VSCode Extension #21

Publish VSCode Extension

Publish VSCode Extension #21

name: Publish VSCode Extension
on:
workflow_dispatch:
inputs:
publish_marketplace:
type: boolean
default: false
description: Publish to marketplace
publish_github:
type: boolean
default: false
description: Publish to GitHub release
release_tag:
type: string
description: Tag to release (empty for latest tag)
required: false
jobs:
build-test-publish:
runs-on: ubuntu-latest
steps:
- name: Check if all checkboxes are unchecked
id: check_checkboxes
run: |
if [[ ${{ inputs.publish_marketplace }} == false && ${{ inputs.publish_github }} == false ]]; then
echo "All checkboxes are unchecked. Exiting workflow."
exit 1
fi
- name: Checkout
uses: actions/checkout@v4
- name: Verify and set release tag
id: set_release_tag
run: |
git fetch --prune --unshallow --tags
release_tag=${{ inputs.release_tag }}
if [ -z "$release_tag" ]; then
echo "Input tag is empty. Fetching latest tag."
release_tag=$(git describe --tags $(git rev-list --tags --max-count=1))
if [ -z "$release_tag" ]; then
echo "No latest tag available. Exiting workflow."
exit 1
fi
else
if ! git rev-parse -q --verify "refs/tags/$release_tag" >/dev/null; then
echo "Invalid tag '$release_tag'. Exiting workflow."
exit 1
fi
fi
echo "::set-output name=tag::$release_tag"
- name: Checkout to latest tag
run: git checkout ${{ steps.set_release_tag.outputs.tag }}
- name: Debug info
run: |
echo "Ref: ${{ github.ref }}"
echo "Release tag: ${{ steps.set_release_tag.outputs.tag }}"
echo "Publish marketplace input: ${{ inputs.publish_marketplace }}"
echo "Publish GitHub input: ${{ inputs.publish_github }}"
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 18.x
- run: npm install
- run: xvfb-run -a npm test
- name: Get repository name
if: inputs.publish_github
id: get_repo_name
run: |
repo_full_name=${{ github.repository }}
repo_name=${repo_full_name#*/}
echo "::set-output name=name::$repo_name"
- name: Publish to GitHub release
if: inputs.publish_github
uses: softprops/action-gh-release@v1
with:
files: |
*.vsix
tag_name: ${{ steps.set_release_tag.outputs.tag }}
name: ${{ steps.get_repo_name.outputs.name }} ${{ steps.set_release_tag.outputs.tag }}
body: |
Release ${{ steps.get_repo_name.outputs.name }} ${{ steps.set_release_tag.outputs.tag }}.
draft: false
prerelease: false
token: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to marketplace
if: ${{ !cancelled() && inputs.publish_marketplace }}
run: npm run deploy
env:
VSCE_PAT: ${{ secrets.VSCE_PAT }}