GithubHelp home page GithubHelp logo

sarafian / semverps Goto Github PK

View Code? Open in Web Editor NEW
8.0 3.0 2.0 55 KB

PowerShell module to work with Semantic Versioning http://semver.org/

License: GNU General Public License v3.0

C# 54.39% PowerShell 45.61%

semverps's Introduction

Build status SemVerPS@PowerShell Gallery

SemVerPS

SemVerPS is a PowerShell module to work with Semantic Version utilizing the .net implementation from Max Hauser's SemVer repository.

Core editions only

For reasons discussed in #8, the module works only with the Core edition with a minimum version 7.0. For the desktop edition make sure you install version 1.0.

Find-Module -Name SemVerPS -MaximumVersion 1.0|Install-Module

Usage

Use the ConvertTo-SemVer to convert strings to semantic version objects. For example:

ConvertTo-SemVer -Version "1.0.0"
Major      : 1
Minor      : 0
Patch      : 0
Prerelease : 
Build      : 
ConvertTo-SemVer -Version "1.0.1-alpha+1" -Strict
Major      : 1
Minor      : 0
Patch      : 1
Prerelease : alpha
Build      : 1

Use the Test-SemVer to test if a string or an semantic version is stable or prerelease. For example:

Test-SemVer -InputObject "1.0.0"
#True

Test-SemVer -InputObject "1.0.0" -Stable
#True

Test-SemVer -InputObject "1.0.0-alpha+1" -PreRelease alpha
#True

Often there is a need to attach a semantic version notation to an object or a list of objects. Use the Add-SemVerMember to add a member where the semantic version value is derived either from an expression or a script block. By default the semantic version is add to a property named SemVer but this can be changed by defining the Property parameter. For example:

[pscustomobject]@{Name="example-1.0.0"}|Add-SemVerMember -Expression 'Name.Replace("example-","")' -PassThru
[pscustomobject]@{Name="example-1.0.0"}|Add-SemVerMember -ScriptBlock {$_.Name.Replace("example-","")} -PassThru -Name "AnotherProperty"
Name          SemVer
----          ------
example-1.0.0 1.0.0


Name          AnotherProperty
----          ---------------
example-1.0.0 1.0.0


As an extension of the Test-SemVer, use the Limit-SemVer to filter objects based on semantic version conditions. Each object can be in the form of a string, or a semantic version instance or an object that has been enhanced with Add-SemVerMember. For example:

$versions=@(
    "1.0.0"
    "1.0.0-alpha+1"
)
$versions|Limit-SemVer -Stable
$versions|Limit-SemVer -Prerelease alpha
1.0.0

1.0.0-alpha+1
$objectsWithVersions=@(
    "example-1.0.0"
    "example-1.0.0-alpha+1"
)|Foreach-Object {
    [pscustomobject]@{Name=$_}| Add-SemVerMember -Expression 'Name.Replace("example-","")' -PassThru  
}
$objectsWithVersions
$objectsWithVersions|Limit-SemVer -Stable
$objectsWithVersions|Limit-SemVer -Prerelease alpha
Name          SemVer
----          ------
example-1.0.0 1.0.0

Name                  SemVer
----                  ------
example-1.0.0-alpha+1 1.0.0-alpha+1

Cmdlets

  • Add-SemVerMember
  • Convert-SemVer
  • Test-SemVer
  • Limit-SemVer

semverps's People

Contributors

sarafian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

skyguy94 dealeron

semverps's Issues

SemVerPS 1.1 on Windows PowerShell ends with Unable to find type [Semver.SemVersion]

Below is Windows PowerShell 5.1 on a recent Windows 10 having .NET Framework 4.8 installed. SemVerPS 1.0 works.

PS C:\WINDOWS\system32> $PSVersionTable
Name                           Value                                                                                                                                                        
----                           -----                                                                                                                                                        
PSVersion                      5.1.19041.1151                                                                                                                                               
PSEdition                      Desktop                                                                                                                                                      
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                      
BuildVersion                   10.0.19041.1151                                                                                                                                              
CLRVersion                     4.0.30319.42000                                                                                                                                              
WSManStackVersion              3.0                                                                                                                                                          
PSRemotingProtocolVersion      2.3                                                                                                                                                          
SerializationVersion           1.1.0.1                                                                                                                                                      

PS C:\WINDOWS\system32> Uninstall-Module -Name SemVerPS
PS C:\WINDOWS\system32> Install-Module -Name SemVerPS -Repository PSGallery -MaximumVersion 1.0
PS C:\WINDOWS\system32> Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.0\CS\SemVersion.cs"
PS C:\WINDOWS\system32> ConvertTo-SemVer -Version "1.0.0+alpha"

Major      : 1
Minor      : 0
Patch      : 0
Prerelease : 
Build      : alpha

Below is a restarted Windows PowerShell 5.1 session on a recent Windows 10 having .NET Framework 4.8 installed. A new PowerShell process to avoid a lingering SemVer class/type loaded. SemVerPS 1.1 throws various errors

PS C:\WINDOWS\system32> $PSVersionTable

Name                           Value                                                                                                                                                        
----                           -----                                                                                                                                                        
PSVersion                      5.1.19041.1151                                                                                                                                               
PSEdition                      Desktop                                                                                                                                                      
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                      
BuildVersion                   10.0.19041.1151                                                                                                                                              
CLRVersion                     4.0.30319.42000                                                                                                                                              
WSManStackVersion              3.0                                                                                                                                                          
PSRemotingProtocolVersion      2.3                                                                                                                                                          
SerializationVersion           1.1.0.1                                                                                                                                                      

PS C:\WINDOWS\system32> Uninstall-Module -Name SemVerPS
PS C:\WINDOWS\system32> Install-Module -Name SemVerPS -Repository PSGallery 
PS C:\WINDOWS\system32> Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs"

Add-Type : c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(410) : Warning as Error: Invalid number
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(409) : 
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(410) : >>> #pragma warning disable CA1062 // Validate arguments of public methods
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(411) :             // If other is null, CompareByPrecedence() returns 1
At line:1 char:1
+ Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SemVerPS\1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception
    + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
 
Add-Type : c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(413) : Warning as Error: Invalid number
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(412) :             return CompareComponent(Build, other.Build);
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(413) : >>> #pragma warning restore CA1062 // Validate arguments of public methods
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(414) :         }
At line:1 char:1
+ Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SemVerPS\1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception
    + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
 
Add-Type : c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(558) : Warning as Error: Invalid number
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(557) : 
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(558) : >>> #pragma warning disable CA2225 // Operator overloads have named alternates
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(559) :         /// <summary>
At line:1 char:1
+ Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SemVerPS\1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception
    + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
 
Add-Type : c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(568) : Warning as Error: Invalid number
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(567) :         public static implicit operator SemVersion(string version)
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(568) : >>> #pragma warning restore CA2225 // Operator overloads have named alternates
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(569) :         {
At line:1 char:1
+ Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SemVerPS\1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception
    + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
 
Add-Type : c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(309) : 'Semver.SemVersion.Major.get' must declare a body because it is not marked abstract or extern. 
Automatically implemented properties must define both get and set accessors.
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(308) :         /// </value>
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(309) : >>>         public int Major { get; }
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(310) : 
At line:1 char:1
+ Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SemVerPS\1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception
    + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
 
Add-Type : c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(317) : 'Semver.SemVersion.Minor.get' must declare a body because it is not marked abstract or extern. 
Automatically implemented properties must define both get and set accessors.
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(316) :         /// </value>
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(317) : >>>         public int Minor { get; }
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(318) : 
At line:1 char:1
+ Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SemVerPS\1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception
    + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
 
Add-Type : c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(325) : 'Semver.SemVersion.Patch.get' must declare a body because it is not marked abstract or extern. 
Automatically implemented properties must define both get and set accessors.
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(324) :         /// </value>
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(325) : >>>         public int Patch { get; }
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(326) : 
At line:1 char:1
+ Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SemVerPS\1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception
    + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
 
Add-Type : c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(333) : 'Semver.SemVersion.Prerelease.get' must declare a body because it is not marked abstract or extern. 
Automatically implemented properties must define both get and set accessors.
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(332) :         /// </value>
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(333) : >>>         public string Prerelease { get; }
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(334) : 
At line:1 char:1
+ Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SemVerPS\1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception
    + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
 
Add-Type : c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(341) : 'Semver.SemVersion.Build.get' must declare a body because it is not marked abstract or extern. 
Automatically implemented properties must define both get and set accessors.
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(340) :         /// </value>
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(341) : >>>         public string Build { get; }
c:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\CS\Semver.cs(342) : 
At line:1 char:1
+ Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SemVerPS\1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception
    + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
 
Add-Type : Cannot add type. Compilation errors occurred.
At line:1 char:1
+ Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SemVerPS\1 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Add-Type], InvalidOperationException
    + FullyQualifiedErrorId : COMPILER_ERRORS,Microsoft.PowerShell.Commands.AddTypeCommand
 

PS C:\WINDOWS\system32> ConvertTo-SemVer -Version "1.0.0+alpha"
Unable to find type [Semver.SemVersion].
At C:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.1\Public\ConvertTo-SemVer.ps1:15 char:17
+     [OutputType([Semver.SemVersion[]])]
+                 ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Semver.SemVersion:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

For what it is worth, same machine the later code block works without problems on a PowerShell 7.1.4. But I think you remember why we need Windows PowerShell :-)

If you don't have time to look into it, can you share some highlights/problems on what changed between 1.0 and 1.1?
Thanks

Import-Module SemVerPS fails due to invalid module file

Hey, I was testing SemVerPS module after installation and powershell cannot load it due to a invalid module.

Steps to reproduce:

  • Install-Module SemVerPS -Scope All
  • Close PS shell
  • Open new PS shell
  • Execute:
Import-Module SemVerPS -Verbose
#VERBOSE: Skipping the Version folder 1.0.0 under Module C:\Program Files\WindowsPowerShell\Modules\semverps as it does not have a valid module manifest file

How to fix it:

Edit ModuleVersion property under SemVerPS.psd1 to match with the folder version: C:\Program Files\WindowsPowerShell\Modules\SemVerPS\1.0.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.