Release and Publish VS Code Extension #28
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# MIT License | |
# | |
# Copyright (c) 2025 Mickaël CANOUIL | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is | |
# furnished to do so, subject to the following conditions: | |
# | |
# The above copyright notice and this permission notice shall be included in all | |
# copies or substantial portions of the Software. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
# SOFTWARE. | |
name: Release and Publish VS Code Extension | |
on: | |
workflow_dispatch: | |
inputs: | |
type: | |
type: choice | |
description: Type | |
options: | |
- release | |
- pre-release | |
default: pre-release | |
date: | |
type: string | |
description: 'Date ("YYYY-MM-DD" or "today")' | |
default: today | |
jobs: | |
update-changelog: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: write | |
env: | |
BRANCH: ci/update-changelog-release | |
GITHUB_TOKEN: ${{ secrets.github_token }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Check for "unreleased" in CHANGELOG.md | |
id: check_unreleased | |
shell: bash | |
run: | | |
if grep -q "unreleased" CHANGELOG.md; then | |
echo "UNRELEASED_FOUND=true" >> $GITHUB_OUTPUT | |
else | |
echo "UNRELEASED_FOUND=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Update date in CHANGELOG.md | |
if: ${{ steps.check_unreleased.outputs.UNRELEASED_FOUND == 'true' }} | |
shell: bash | |
run: | | |
if [ "${{ github.event.inputs.date }}" = "today" ]; then | |
RELEASE_DATE=$(date +%Y-%m-%d) | |
else | |
RELEASE_DATE=${{ github.event.inputs.date }} | |
fi | |
sed -i "s/unreleased/${RELEASE_DATE}/" CHANGELOG.md | |
- name: Commit / Push CHANGELOG.md | |
if: ${{ steps.check_unreleased.outputs.UNRELEASED_FOUND == 'true' }} | |
env: | |
GH_TOKEN: ${{ secrets.github_token }} | |
COMMIT: "ci: automatic changelog update for release" | |
shell: bash | |
run: | | |
git config --local user.name github-actions[bot] | |
git config --local user.email 41898282+github-actions[bot]@users.noreply.github.com | |
if git show-ref --quiet refs/heads/${{ env.BRANCH }}; then | |
echo "Branch ${{ env.BRANCH }} already exists." | |
git branch -D "${{ env.BRANCH }}" | |
git push origin --delete "${{ env.BRANCH }}" | |
fi | |
git checkout -b "${{ env.BRANCH }}" | |
git add CHANGELOG.md || echo "No changes to add" | |
git commit -m "${{ env.COMMIT }}" || echo "No changes to commit" | |
git push --force origin ${{ env.BRANCH }} || echo "No changes to push" | |
- name: Create Pull Request | |
if: ${{ steps.check_unreleased.outputs.UNRELEASED_FOUND == 'true' }} | |
shell: bash | |
run: | | |
sleep 30 | |
gh pr create --fill-first --base "main" --head "${{ env.BRANCH }}" --label "Type: CI/CD :robot:" | |
- name: Merge Pull Request | |
if: ${{ steps.check_unreleased.outputs.UNRELEASED_FOUND == 'true' }} | |
shell: bash | |
run: | | |
sleep 30 | |
gh pr merge --auto --squash --delete-branch | |
release-publish: | |
runs-on: ubuntu-latest | |
needs: update-changelog | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
- name: Install dependencies | |
shell: bash | |
run: npm install | |
- name: Install Visual Studio Code Extension Manager | |
shell: bash | |
run: npm install -g @vscode/vsce | |
- name: Set version | |
shell: bash | |
run: | | |
echo "VERSION=$(jq -r .version package.json)" >> $GITHUB_ENV | |
- name: Set changelog | |
env: | |
VERSION: ${{ env.VERSION }} | |
shell: bash | |
run: | | |
awk -v version="^## ${VERSION}.*" ' | |
$0 ~ version {flag=1; next} | |
/^## / && flag {flag=0} | |
flag | |
' CHANGELOG.md >"CHANGELOG-${VERSION}.md" | |
echo "CHANGELOG=CHANGELOG-${VERSION}.md" >> $GITHUB_ENV | |
- name: Package extension | |
env: | |
GH_TOKEN: ${{ secrets.github_token }} | |
VERSION: ${{ env.VERSION }} | |
CHANGELOG: ${{ env.CHANGELOG }} | |
shell: bash | |
run: | | |
if [ "${{ github.event.inputs.type }}" = "pre-release" ]; then | |
vsce package --pre-release | |
gh release create ${VERSION} ./quarto-wizard-${VERSION}.vsix --prerelease --title ${VERSION} --notes-file ${CHANGELOG} --generate-notes | |
else | |
vsce package | |
gh release create ${VERSION} ./quarto-wizard-${VERSION}.vsix --title ${VERSION} --notes-file ${CHANGELOG} --generate-notes | |
fi | |
- name: Publish extension to Visual Studio Marketplace | |
env: | |
VS_MARKETPLACE_TOKEN: ${{ secrets.VS_MARKETPLACE_TOKEN }} | |
shell: bash | |
run: | | |
if [ "${{ github.event.inputs.type }}" = "pre-release" ]; then | |
vsce publish --pre-release --pat ${VS_MARKETPLACE_TOKEN} | |
else | |
vsce publish --pat ${VS_MARKETPLACE_TOKEN} | |
fi | |
- name: Publish extension to Open VSX Registry | |
env: | |
OPEN_VSX_REGISTRY_TOKEN: ${{ secrets.OPEN_VSX_REGISTRY_TOKEN }} | |
shell: bash | |
run: | | |
npm install --global ovsx | |
if [ "${{ github.event.inputs.type }}" = "pre-release" ]; then | |
npx ovsx publish --pre-release --pat ${OPEN_VSX_REGISTRY_TOKEN} | |
else | |
npx ovsx publish --pat ${OPEN_VSX_REGISTRY_TOKEN} | |
fi |