Skip to content

Commit eae4279

Browse files
author
Asaf Agami
authored
fix: version in release workflow is wrong for marketplace (#232)
1 parent da32a0b commit eae4279

6 files changed

Lines changed: 47 additions & 32 deletions

File tree

.github/workflows/build-project.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,34 @@ on:
66
solution-file-path:
77
required: true
88
type: string
9+
outputs:
10+
version:
11+
description: 'next Git tag in semver format'
12+
value: ${{ jobs.build.outputs.version }}
913
jobs:
1014
build:
1115
runs-on: windows-2022
1216
defaults:
1317
run:
1418
working-directory: ${{ github.workspace }}
1519
environment: snyk-msbuild-envs
20+
outputs:
21+
version: ${{ steps.vsix_version.outputs.next-tag }}
1622
steps:
1723
- uses: actions/checkout@v2
24+
- name: Calculate next semantic version Git tag (vsix version)
25+
id: vsix_version
26+
uses: ./.github/actions/next-git-tag
27+
- name: Set VSIX version for 2015-2019
28+
uses: cezarypiatek/VsixVersionAction@1.0
29+
with:
30+
version: ${{ steps.vsix_version.outputs.next-tag }}
31+
vsix-manifest-file: .\Snyk.VisualStudio.Extension\source.extension.vsixmanifest
32+
- name: Set VSIX version for 2022
33+
uses: cezarypiatek/VsixVersionAction@1.0
34+
with:
35+
version: ${{ steps.vsix_version.outputs.next-tag }}
36+
vsix-manifest-file: .\Snyk.VisualStudio.Extension.2022\source.extension.vsixmanifest
1837
- name: Check if secrets exist
1938
env:
2039
Secret: ${{ secrets.SNYK_CODE_API_ENDPOINT_URL }}

.github/workflows/release.yml

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
- name: Tests
4242
run: vstest.console.exe **\*.Tests.dll /TestCaseFilter:"FullyQualifiedName!=Xunit.Instances.VisualStudio&integration!=true" #exclude integration tests and the psuedo-tests that launch a VS instance
4343
release:
44-
needs: run-integration-tests
44+
needs: [build-project, run-integration-tests]
4545
runs-on: windows-2022
4646
defaults:
4747
run:
@@ -59,28 +59,12 @@ jobs:
5959
with:
6060
name: build-artifacts
6161

62-
- name: Calculate next semantic version Git tag (vsix version)
63-
id: vsix_version
64-
uses: ./.github/actions/next-git-tag
65-
66-
- name: Set VSIX version for 2015-2019
67-
uses: cezarypiatek/VsixVersionAction@1.0
68-
with:
69-
version: ${{ steps.vsix_version.outputs.next-tag }}
70-
vsix-manifest-file: .\Snyk.VisualStudio.Extension\source.extension.vsixmanifest
71-
72-
- name: Set VSIX version for 2022
73-
uses: cezarypiatek/VsixVersionAction@1.0
74-
with:
75-
version: ${{ steps.vsix_version.outputs.next-tag }}
76-
vsix-manifest-file: .\Snyk.VisualStudio.Extension.2022\source.extension.vsixmanifest
77-
7862
- name: Set up Git actions user
7963
uses: fregante/setup-git-user@v1
8064

8165
- name: Create and push Git tag release
8266
run: |
83-
git tag ${{ steps.vsix_version.outputs.next-tag }}
67+
git tag ${{ needs.build-project.outputs.version }}
8468
git push origin main
8569
git push origin main --tags
8670
@@ -90,8 +74,8 @@ jobs:
9074
env:
9175
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9276
with:
93-
tag_name: ${{ steps.vsix_version.outputs.next-tag }}
94-
release_name: Release ${{ steps.vsix_version.outputs.next-tag }}
77+
tag_name: ${{ needs.build-project.outputs.version }}
78+
release_name: Release ${{ needs.build-project.outputs.version }}
9579
draft: false
9680
prerelease: false
9781

@@ -102,7 +86,7 @@ jobs:
10286
with:
10387
upload_url: ${{ steps.create_release.outputs.upload_url }}
10488
asset_path: .\Snyk.VisualStudio.Extension\bin\Release\Snyk.VisualStudio.Extension.vsix
105-
asset_name: Snyk_Vulnerability_Scanner-${{ steps.vsix_version.outputs.next-tag }}.vsix
89+
asset_name: Snyk_Vulnerability_Scanner-${{ needs.build-project.outputs.version }}.vsix
10690
asset_content_type: application/zip
10791

10892
- name: Upload GitHub Release 2022 Asset
@@ -112,7 +96,7 @@ jobs:
11296
with:
11397
upload_url: ${{ steps.create_release.outputs.upload_url }}
11498
asset_path: .\Snyk.VisualStudio.Extension.2022\bin\Release\Snyk.VisualStudio.Extension.vsix
115-
asset_name: Snyk_Vulnerability_Scanner-${{ steps.vsix_version.outputs.next-tag }}-2022.vsix
99+
asset_name: Snyk_Vulnerability_Scanner-${{ needs.build-project.outputs.version }}-2022.vsix
116100
asset_content_type: application/zip
117101

118102
- name: Publish 2015-2019 extension to Marketplace

Snyk.Code.Library/Service/SnykCodeService.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,9 @@ public string GetSnykCodeErrorMessage(Exception sourceException)
8282
Logger.Error(sourceException, "Failed to obtain Snyk Code error message");
8383
Logger.Error(e, string.Empty);
8484

85-
if (false == sourceException.Message.IsNullOrEmpty())
86-
{
87-
return sourceException.Message;
88-
}
89-
else {
90-
return $"Error: {sourceException.ToString()}";
91-
}
85+
return !sourceException.Message.IsNullOrEmpty()
86+
? sourceException.Message
87+
: $"Error {sourceException}";
9288
}
9389
}
9490

Snyk.Common/CollectionExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
public static class CollectionExtensions
1010
{
1111
/// <summary>
12-
/// Check is collection is empty (items count is 0).
12+
/// Check is collection is empty (items count is 0) or null.
1313
/// </summary>
1414
/// <param name="collection">Source collection for check.</param>
1515
/// <returns>True if collection is empty.</returns>
16-
public static bool IsNullOrEmpty<T>(this IEnumerable<T> collection) => collection == null || collection.Count() == 0;
16+
public static bool IsNullOrEmpty<T>(this IEnumerable<T> collection) => collection == null || !collection.Any();
1717
}
1818
}

Snyk.Common/StringExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,7 @@ public static string ReplaceFirst(this string source, string oldValue, string ne
5050

5151
return source.Substring(0, index) + newValue + source.Substring(index + oldValue.Length);
5252
}
53+
54+
public static bool IsNullOrEmpty(this string target) => string.IsNullOrEmpty(target);
5355
}
5456
}

Snyk.VisualStudio.Extension.Shared/UI/Notifications/NotificationService.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
namespace Snyk.VisualStudio.Extension.Shared.UI.Notifications
22
{
3+
using Snyk.Common;
34
using Snyk.VisualStudio.Extension.Shared.Service;
45

56
/// <summary>
67
/// Snyk VS notification service.
78
/// </summary>
89
public class NotificationService
910
{
11+
private const int MaxErrorLength = 300;
1012
private VsInfoBarService infoBarService;
1113

1214
private NotificationService(ISnykServiceProvider serviceProvider) => this.infoBarService = new VsInfoBarService(serviceProvider);
@@ -22,6 +24,18 @@ public class NotificationService
2224
/// Show error info bar with provided message.
2325
/// </summary>
2426
/// <param name="message">Message to show.</param>
25-
public void ShowErrorInfoBar(string message) => this.infoBarService.ShowErrorInfoBar(message);
27+
public void ShowErrorInfoBar(string message)
28+
{
29+
if (message.IsNullOrEmpty()) // Calling ShowErrorInfoBar with empty message will cause exception.
30+
{
31+
message = "Unknown error";
32+
}
33+
else if (message.Length > MaxErrorLength)
34+
{
35+
message = message.Substring(0, MaxErrorLength) + "...";
36+
}
37+
38+
this.infoBarService.ShowErrorInfoBar(message);
39+
}
2640
}
2741
}

0 commit comments

Comments
 (0)