Skip to content

Commit

Permalink
[ROAD-641] Fix: deployment pipeline for vs (#102)
Browse files Browse the repository at this point in the history
* chore: introduce local action

* chore: combine releasing into one workflow step

* chore: add version prefix for 2022 vsix file when uploading to releases

* chore: incorporate changes from review

Co-authored-by: Pavel Sorokin <[email protected]>
  • Loading branch information
aldanchenko and pavel-snyk authored Apr 9, 2022
1 parent edef85a commit aefb46b
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 137 deletions.
12 changes: 12 additions & 0 deletions .github/actions/next-git-tag/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: 'Get Next SemVer Tag'
description: 'Get next Git tag in semver format'
outputs:
next-tag:
description: 'next Git tag in semver format'
value: ${{ steps.get-next-semver-tag.outputs.next-tag }}
runs:
using: 'composite'
steps:
- id: get-next-semver-tag
run: ${{ github.action_path }}/next-git-tag.ps1
shell: pwsh
39 changes: 39 additions & 0 deletions .github/actions/next-git-tag/next-git-tag.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<#
.SYNOPSIS
This script calculates a next Git tag in SemVer format.
#>
[CmdletBinding()]
Param()

[string[]]$AllTags = (git tag --sort=committerdate)
Write-Verbose "all tags: $AllTags"
$LatestTag = $AllTags[$AllTags.Length - 1]
Write-Host "Found latest Git tag: $LatestTag"

# split the tag by dots and increment patch version
$v = $LatestTag -split "\."
[string] $MajorStr = $v[0]
[int] $Major = 0
if ($MajorStr.StartsWith("v"))
{
$Major = $MajorStr.Substring(1)
}
else
{
$Major = $MajorStr
}
[int] $Minor = $v[1]
[int] $Patch = $v[2]

Write-Verbose "MAJOR part: $Major"
Write-Verbose "MINOR part: $Minor"
Write-Verbose "PATCH part: $Patch"

# hardcoded increment for patch
$Patch += 1;

$NextSemverTag = "$Major.$Minor.$Patch"
Write-Host "Next SemVer tag: $NextSemverTag"

# Return next tag to workflow
echo "::set-output name=next-tag::$NextSemverTag"
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ jobs:

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- uses: microsoft/variable-substitution@v1
with:
files: '.\Snyk.Common\appsettings.json'
Expand All @@ -37,7 +40,7 @@ jobs:
- name: Setup VSTest
uses: darenm/Setup-VSTest@v1

- name: Restore NuGet packages
- name: Restore NuGet packages
run: nuget restore ${{env.SOLUTION_FILE_PATH}}

- name: Build
Expand Down
108 changes: 0 additions & 108 deletions .github/workflows/release-2022.yml

This file was deleted.

81 changes: 53 additions & 28 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@ jobs:

steps:
- uses: actions/checkout@v2

- name: Unshallow
run: git fetch --prune --unshallow

with:
fetch-depth: 0

- uses: actions/cache@v2
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.config') }}
restore-keys: |
${{ runner.os }}-nuget-
- uses: microsoft/variable-substitution@v1
with:
files: '.\Snyk.Common\appsettings.json'
Expand All @@ -55,54 +54,80 @@ jobs:
- name: Restore NuGet packages
run: nuget restore ${{env.SOLUTION_FILE_PATH}}

- name: Increment VSIX version
- name: Calculate next semantic version Git tag (vsix version)
id: vsix_version
uses: timheuer/vsix-version-stamp@v1
uses: ./.github/actions/next-git-tag -Verbose

- name: Set VSIX version for 2015-2019
uses: cezarypiatek/[email protected]
with:
manifest-file: ${{ env.VsixManifestPath }}

- name: Set up Git actions user
uses: fregante/setup-git-user@v1

- name: Commit new version
run: |
git commit -am 'increment new version'
git tag ${{ steps.vsix_version.outputs.version-number }}
git push origin main
git push origin main --tags
version: ${{ steps.vsix_version.outputs.next-tag }}
vsix-manifest-file: .\Snyk.VisualStudio.Extension\source.extension.vsixmanifest

- name: Set VSIX version for 2022
uses: cezarypiatek/[email protected]
with:
version: ${{ steps.vsix_version.outputs.next-tag }}
vsix-manifest-file: .\Snyk.VisualStudio.Extension.2022\source.extension.vsixmanifest

- name: Build
run: |
msbuild ${{env.SOLUTION_FILE_PATH}} /p:configuration=Release /p:DeployExtension=false /p:ZipPackageCompressionLevel=normal /v:m
shell: powershell

- name: Tests
run: vstest.console.exe **\*.Tests.dll

- name: Create Release

- name: Set up Git actions user
uses: fregante/setup-git-user@v1

- name: Create and push Git tag release
run: |
git tag ${{ steps.vsix_version.outputs.next-tag }}
git push origin main
git push origin main --tags
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.vsix_version.outputs.version-number }}
release_name: Release ${{ steps.vsix_version.outputs.version-number }}
tag_name: ${{ steps.vsix_version.outputs.next-tag }}
release_name: Release ${{ steps.vsix_version.outputs.next-tag }}
draft: false
prerelease: false
- name: Upload Release Asset
id: upload-release-asset

- name: Upload GitHub Release 2015-2019 Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: .\Snyk.VisualStudio.Extension\bin\Release\Snyk.VisualStudio.Extension.vsix
asset_name: Snyk_Vulnerability_Scanner-${{ steps.vsix_version.outputs.version-number }}.vsix
asset_name: Snyk_Vulnerability_Scanner-${{ steps.vsix_version.outputs.next-tag }}.vsix
asset_content_type: application/zip


- name: Upload GitHub Release 2022 Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: .\Snyk.VisualStudio.Extension.2022\bin\Release\Snyk.VisualStudio.Extension.vsix
asset_name: Snyk_Vulnerability_Scanner-${{ steps.vsix_version.outputs.next-tag }}-2022.vsix
asset_content_type: application/zip

- name: Publish 2015-2019 extension to Marketplace
uses: cezarypiatek/[email protected]
with:
extension-file: '.\Snyk.VisualStudio.Extension\bin\Release\Snyk.VisualStudio.Extension.vsix'
publish-manifest-file: '.\Snyk.VisualStudio.Extension\vs-publish.json'
personal-access-code: ${{ secrets.VS_PUBLISHER_ACCESS_TOKEN }}

- name: Publish 2022 extension to Marketplace
uses: cezarypiatek/[email protected]
with:
extension-file: '.\Snyk.VisualStudio.Extension.2022\bin\Release\Snyk.VisualStudio.Extension.vsix'
publish-manifest-file: '.\Snyk.VisualStudio.Extension.2022\vs-publish.json'
personal-access-code: ${{ secrets.VS_PUBLISHER_ACCESS_TOKEN }}

0 comments on commit aefb46b

Please sign in to comment.