Skip to content

Commit

Permalink
fix script and add test to download cli script
Browse files Browse the repository at this point in the history
  • Loading branch information
kerenr-jfrog committed Oct 1, 2024
1 parent 7a2a612 commit d5ba9dc
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
runs-on: windows-latest
env:
NEW_VERSION: '${{ github.ref_name }}'
MANIFEST_FILE_PATH: "JfrogVSExtension/source.extension.vsixmanifest"

steps:
- name: Checkout Code
Expand Down
23 changes: 20 additions & 3 deletions UnitTestJfrogVSExtension/PowerShellScriptTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@ public class PowerShellScriptTests

// use relative path (from base dir) in order to be able to run in other environments
public static string baseDir = AppDomain.CurrentDomain.BaseDirectory;
public static string scriptPath = Path.GetFullPath(Path.Combine(baseDir, @"..\..\..\scripts\UpdateVsixVersion.ps1"));
public static string updateVersionScriptPath = Path.GetFullPath(Path.Combine(baseDir, @"..\..\..\scripts\UpdateVsixVersion.ps1"));
public static string downloadCliScriptPath = Path.GetFullPath(Path.Combine(baseDir, @"..\..\..\scripts\DownloadJfrogCli.ps1"));
public static string vsixManifestMockPath = Path.GetFullPath(Path.Combine(baseDir, @"..\..\..\scripts\vsixmanifestMock"));

[TestMethod]
public void Test_UpdateVsixVersion_ValidVersion()
{
var envVars = new Dictionary<string, string>
{
{ "NEW_VERSION", "vs22-1.2.3" }, // Valid version
{ "MANIFEST_FILE_LOCATION", vsixManifestMockPath},
};

// script should succeed and return exit code 0
int exitCode = RunPowerShellScript(scriptPath, envVars);
int exitCode = RunPowerShellScript(updateVersionScriptPath, envVars);
Assert.AreEqual(0, exitCode);
}

Expand All @@ -37,10 +40,24 @@ public void Test_UpdateVsixVersion_InvalidVersion()
};

// script should fail and return exit code 1
int exitCode = RunPowerShellScript(scriptPath, envVars);
int exitCode = RunPowerShellScript(updateVersionScriptPath, envVars);
Assert.AreEqual(1, exitCode);
}


[TestMethod]
public void Test_DownloadJfrogCli()
{
var envVars = new Dictionary<string, string>
{
{ "JFROG_CLI_VERSION", "2.67.0" }
};

// script should succeed and return exit code 0
int exitCode = RunPowerShellScript(downloadCliScriptPath, envVars);
Assert.AreEqual(0, exitCode);
}

private int RunPowerShellScript(string scriptPath, Dictionary<string, string> envVars)
{
// Create a new process to run the PowerShell script
Expand Down
10 changes: 9 additions & 1 deletion scripts/UpdateVsixVersion.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$newVersion = $env:NEW_VERSION
$manifestFileLocation = "JfrogVSExtension/source.extension.vsixmanifest"
$manifestFileLocation = Join-Path (Get-Location).Path $env:MANIFEST_FILE_LOCATION

# Validate the NEW_VERSION format: "vs22-x.x.x"
if ($newVersion -match "^vs22-(\d+\.\d+\.\d+)$") {
Expand All @@ -10,6 +10,14 @@ if ($newVersion -match "^vs22-(\d+\.\d+\.\d+)$") {
exit 1
}

if (-not $env:MANIFEST_FILE_LOCATION){
Write-Error "Error: MANIFEST_FILE_LOCATION environment variable is not set."
exit 1
} elseif (-not (Test-Path $env:MANIFEST_FILE_LOCATION)){
Write-Error "The file specified in MANIFEST_FILE_LOCATION does not exist."
exit 1
}

# Load the manifest file and update the version
[xml]$manifest = Get-Content -Path $manifestFileLocation
$manifest.PackageManifest.Metadata.Identity.Version = $newVersion
Expand Down
25 changes: 25 additions & 0 deletions scripts/vsixmanifestMock
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="JFrogVSExtension.c07afb03-9f9a-45e2-8e6f-78442325bb24" Version="0.0.0" Language="en-US" Publisher="JFrog" />
<DisplayName>JFrog V2</DisplayName>
<Description xml:space="preserve">Visual Studio extension to integrate with JFrog Xray for scanning solution components. </Description>
<Icon>Resources\Icon.png</Icon>
<PreviewImage>Resources\PreviewImage.png</PreviewImage>
</Metadata>
<Installation>
<InstallationTarget Version="[17.0,18.0)" Id="Microsoft.VisualStudio.Community">
<ProductArchitecture>amd64</ProductArchitecture>
</InstallationTarget>
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="[4.5,)" />
</Dependencies>
<Prerequisites>
<Prerequisite Id="Microsoft.VisualStudio.Component.CoreEditor" Version="[15.0,)" DisplayName="Visual Studio core editor" />
</Prerequisites>
<Assets>
<Asset Type="Microsoft.VisualStudio.ToolboxControl" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
</Assets>
</PackageManifest>

0 comments on commit d5ba9dc

Please sign in to comment.