DmitryOffsec triggered release and publication #156
Workflow file for this run
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
name: Release and Publish | |
run-name: ${{ github.actor }} triggered release and publication | |
on: | |
push: | |
tags: | |
- v* | |
jobs: | |
release: | |
permissions: | |
contents: write | |
name: Create release and publish | |
runs-on: ubuntu-latest | |
steps: | |
- name: Clone repository | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.ref }} | |
- name: Setup Node | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '18' | |
cache: 'npm' | |
- name: Get release version | |
id: release_version | |
run: | | |
TAGGED_VERSION="${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_ENV | |
echo "TAGGED_VERSION=${TAGGED_VERSION}" | |
if [[ ! "${TAGGED_VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+.*$ ]]; then | |
echo "Invalid version tag '${TAGGED_VERSION}'" | |
exit 1 | |
fi | |
echo "EXT_VERSION=${TAGGED_VERSION}" >> $GITHUB_ENV | |
echo "EXT_VERSION=${TAGGED_VERSION}" | |
WRITTEN_VERSION="$(cat package.json | jq '.version' -r)" | |
echo "WRITTEN_VERSION=${WRITTEN_VERSION}" | |
if [[ $(($(echo "${TAGGED_VERSION}" | cut -f2 -d'.')%2)) -eq 1 ]]; then | |
if [[ ! "${TAGGED_VERSION}" == "${WRITTEN_VERSION}" ]]; then | |
echo "Prerelease Tag and Version in package.json are not compatible: '${TAGGED_VERSION}' vs '${WRITTEN_VERSION}'" | |
exit 1 | |
fi | |
echo "EXT_ISPREVIEW=1" >> $GITHUB_ENV | |
echo "EXT_ISPREVIEW=1" | |
else | |
if [[ "${TAGGED_VERSION}" != "${WRITTEN_VERSION}" ]]; then | |
echo "Release Tag and Version in package.json do not match: '${TAGGED_VERSION}' vs '${WRITTEN_VERSION}'" | |
exit 1 | |
fi | |
echo "EXT_ISPREVIEW=0" >> $GITHUB_ENV | |
echo "EXT_ISPREVIEW=0" | |
fi | |
- name: Get tag message body | |
run: | | |
EOF=${{ github.sha }} | |
echo "msg<<$EOF" >> $GITHUB_OUTPUT | |
echo "$(git tag -l --format='%(contents:body)' ${{ github.ref_name }})" >> $GITHUB_OUTPUT | |
echo "$EOF" >> $GITHUB_OUTPUT | |
id: get_tag_message | |
- name: Stamp version | |
run: | | |
cat package.json | jq --arg VER "${{ env.EXT_VERSION }}" '.version=$VER' > /tmp/package.json | |
cp /tmp/package.json ./package.json | |
npm ci | |
npm run vscode:prepublish | |
- name: Package release extension | |
if: env.EXT_ISPREVIEW != 1 | |
run: npx vsce package -o "./vscode-xp-${{ env.EXT_VERSION }}.vsix" | |
- name: Package pre-release extension | |
if: env.EXT_ISPREVIEW == 1 | |
run: npx vsce package --pre-release -o "./vscode-xp-${{ env.EXT_VERSION }}.vsix" | |
- name: Create release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ github.ref }} | |
release_name: v${{ env.EXT_VERSION }} | |
draft: false | |
prerelease: ${{env.EXT_ISPREVIEW == 1}} | |
body: | | |
${{ steps.get_tag_message.outputs.msg }} | |
- name: Upload release asset | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./vscode-xp-${{ env.EXT_VERSION }}.vsix | |
asset_name: vscode-xp-${{ env.EXT_VERSION }}.vsix | |
asset_content_type: application/zip | |
- name: Publish at VSCode marketplace | |
if: env.EXT_ISPREVIEW != 1 | |
run: npx vsce publish -i "./vscode-xp-${{ env.EXT_VERSION }}.vsix" -p "${{ secrets.VS_MARKETPLACE_TOKEN }}" | |
- name: Publish pre-release at VSCode marketplace | |
if: env.EXT_ISPREVIEW == 1 | |
run: npx vsce publish --pre-release -i "./vscode-xp-${{ env.EXT_VERSION }}.vsix" -p "${{ secrets.VS_MARKETPLACE_TOKEN }}" | |
- name: Publish at Open VSIX | |
if: env.EXT_ISPREVIEW != 1 | |
run: npx ovsx publish "./vscode-xp-${{ env.EXT_VERSION }}.vsix" -p "${{ secrets.OPEN_VSIX_TOKEN }}" | |
- name: Publish pre-release at Open VSIX | |
if: env.EXT_ISPREVIEW == 1 | |
run: npx ovsx publish --pre-release "./vscode-xp-${{ env.EXT_VERSION }}.vsix" -p "${{ secrets.OPEN_VSIX_TOKEN }}" |