From 15c8714623ec14240c4c58d344c62e1b9ee22012 Mon Sep 17 00:00:00 2001
From: Troy Brown <brownts@troybrown.dev>
Date: Sat, 16 Apr 2022 01:52:06 -0400
Subject: [PATCH] Preparations for release.

---
 .github/workflows/release.yml | 116 ++++++++++++++++++++++++++--------
 CHANGELOG.md                  |   2 +-
 2 files changed, 89 insertions(+), 29 deletions(-)

diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 6c98017..6b1629a 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -1,40 +1,100 @@
-name: Release vsix to OpenVSX and VSCode marketplace
+name: Release
 on:
   release:
     types: [published]
 
 jobs:
   release:
-    name: "Release"
-    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        os: ['ubuntu-latest']
+        node-version: ['16.x']
+    runs-on: ${{ matrix.os }}
     steps:
-    - uses: actions/checkout@master
-    
-    - name: Set Node.js 14.x
-      uses: actions/setup-node@master
+    #
+    # Basic Setup
+    #
+    - name: Checkout
+      uses: actions/checkout@v3
+
+    - name: Install Node.js ${{ matrix.node-version }}
+      uses: actions/setup-node@v3
       with:
-        version: 14.x
+        node-version: ${{ matrix.node-version }}
 
-    - name: npm install
-      run: npm install
+    #
+    # Audit Versions for Consistency
+    #
+    - name: Query package.json Version
+      id: package
+      run: node -e "console.log('::set-output name=version::' + require('./package.json').version)"
 
-    - name: typescript
-      run: npx tsc
+    - name: Query package-lock.json Version
+      id: package-lock
+      run: node -e "console.log('::set-output name=version::' + require('./package-lock.json').version)"
 
-    - name: Publish to Open VSX Registry
-      uses: HaaLeo/publish-vscode-extension@v0
-      id: publishToOpenVSX
-      with:
-        pat: ${{ secrets.OPEN_VSX_TOKEN }}
-    - name: Publish to Visual Studio Marketplace
-      uses: HaaLeo/publish-vscode-extension@v0
-      with:
-        pat: ${{ secrets.VS_MARKETPLACE_TOKEN }}
-        registryUrl: https://marketplace.visualstudio.com
-        extensionFile: ${{ steps.publishToOpenVSX.outputs.vsixPath }}
-        packagePath: ''
-    - name: Upload
-      uses: djn24/add-asset-to-release@v1
+    - name: Query Latest Changelog Version
+      id: changelog
+      shell: bash
+      run: echo ::set-output name=version::$(grep --perl-regexp "^# " --max-count=1 CHANGELOG.md | awk '{print $2}')
+
+    - name: Audit package.json/package-lock.json/CHANGELOG.md/git tag Version Consistency
+      shell: bash
+      run: >
+        test ${{ steps.package.outputs.version }} = ${{ steps.package-lock.outputs.version }} -a \
+             ${{ steps.package.outputs.version }} = ${{ steps.changelog.outputs.version }}    -a \
+             refs/tags/v${{ steps.package.outputs.version }} = ${{ github.ref }}
+
+    #
+    # Install Dependencies
+    #
+    # NOTE:
+    # Use the `clean-install` instead of just `install` so that the versions identified in the
+    # package-lock.json file are used instead of attempting to install later versions that might
+    # exist.  This drives consistency between what the developers have been using and what is to
+    # be released.
+    #
+    # NOTE:
+    # Use the `--no-optional` switch to prevent installation of the `ssh2` optional dependency
+    # (i.e., `cpu-features`) package which is used to provide accelerated crypto functionality,
+    # but which is a native add-on and would require platform specific packages.
+    #
+    - name: Install Module Dependencies
+      run: npm clean-install --no-optional
+
+    #
+    # Package and Upload Extension
+    #
+    # NOTE:
+    # The "vscode:prepublish" script in package.json will be executed to compile the extension
+    # prior to packaging.
+    #
+    - name: Package Extension into .vsix file
+      id: asset
+      shell: bash
+      run: >
+        npx vsce package;
+        echo ::set-output name=vsix_path::$(ls *.vsix)
+
+    - name: Upload .vsix file to Github as release asset
+      uses: actions/upload-release-asset@v1
+      env:
+        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
       with:
-        token: ${{secrets.GITHUB_TOKEN}}
-        path: ${{ steps.publishToOpenVSX.outputs.vsixPath }}
+        upload_url: ${{ github.event.release.upload_url }}
+        asset_path: ${{ steps.asset.outputs.vsix_path }}
+        asset_name: ${{ steps.asset.outputs.vsix_path }}
+        asset_content_type: application/zip
+
+    #
+    # Publish Extension
+    #
+    - name: Publish to VSCode Extension Marketplace
+      env:
+        VSCE_PAT: ${{ secrets.VS_MARKETPLACE_TOKEN }}
+      run: npx vsce publish --packagePath ${{ steps.asset.outputs.vsix_path }}
+
+    - name: Publish to Open VSX Registry
+      env:
+        OVSX_PAT: ${{ secrets.OPEN_VSX_TOKEN }}
+      run: npx ovsx publish ${{ steps.asset.outputs.vsix_path }}
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b585995..12302fe 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,4 @@
-# Unreleased 0.26.0
+# 0.26.0
 
 * vscode dependency was increased from 1.28 to 1.55 along with the debug-adapter protocol to get rid of some outdated dependencies (@GitMensch)
 * SSH2 module updated from deprecated 0.8.9 to current 1.6.0 (@GitMensch),
-- 
GitLab