Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,36 @@ jobs:
runs-on: windows-latest

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

- name: Setup dotnet
id: setup-dotnet
uses: actions/setup-dotnet@v5
with:
global-json-file: src/global.json

- name: Setup wix
run: |
dotnet.exe tool install --global wix --version 6.0.0 --verbosity diag
dotnet.exe tool install --global wix --version 6.0.2 --verbosity diag

wix.exe extension add WixToolset.UI.wixext/6.0.0 --global
wix.exe extension add WixToolset.UI.wixext/6.0.2 --global
wix.exe extension list --global

- name: Generate version property
id: version
run: |
$pattern = '^v(((\d+\.\d+\.\d+\.\d+)(?:-[a-z]+\.\d+)?)-(\d+-g.+))'
$tag = git.exe describe --tags --long
$version = [version]::new($tag.Split('-')[0].TrimStart('v'))
$version = [System.Text.RegularExpressions.Regex]::Match($tag, $pattern).Groups[3].Value
$fullVersion = [System.Text.RegularExpressions.Regex]::Match($tag, $pattern).Groups[2].Value
$gitCommitInfo = [System.Text.RegularExpressions.Regex]::Match($tag, $pattern).Groups[4].Value
$informationalVersion = '{0}+{1}' -f $fullVersion,$gitCommitInfo

echo "version=$version" >> $env:GITHUB_OUTPUT
echo "fullVersion=$fullVersion" >> $env:GITHUB_OUTPUT
echo "informationalVersion=$informationalVersion" >> $env:GITHUB_OUTPUT

- name: Run tests
run: dotnet.exe test .\src\PSDataProtection.sln --configuration Release --runtime win-x64
Expand Down Expand Up @@ -100,7 +112,7 @@ jobs:

- name: Publish release
if: github.ref_type == 'tag'
run: gh.exe release create v${{ steps.version.outputs.version }} --title v${{ steps.version.outputs.version }} --notes 'PowerShell data protection module.' ps-data-protection.msi
run: gh.exe release create v${{ steps.version.outputs.fullVersion }} --title v${{ steps.version.outputs.fullVersion }} --notes 'PowerShell data protection module.' ps-data-protection.msi
env:
# Requires a personal access token with a fine-grained permission of contents:read/write.
GH_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
16 changes: 9 additions & 7 deletions src/PSDataProtection/PSDataProtection.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.PowerShell.5.1.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="9.0.5" PrivateAssets="All" />
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="10.0.0" PrivateAssets="All" />
</ItemGroup>

<PropertyGroup>
Expand All @@ -27,16 +27,18 @@
</ItemGroup>

<Target Name="GetVersionFromGit">
<Exec Command="git.exe describe --tags --long" WorkingDirectory="$(MSBuildProjectDirectory)" ConsoleToMSBuild="true" StandardOutputImportance="Low">
<Exec Command="git.exe describe --tags --long" WorkingDirectory="$(MSBuildProjectDirectory)" ConsoleToMsBuild="true" StandardOutputImportance="Low">
<Output TaskParameter="ConsoleOutput" PropertyName="GitTag" />
</Exec>

<PropertyGroup>
<PatternGitTag>^v((.+)-(\d+)-g(.+))</PatternGitTag>
<AssemblyVersion>$([System.Text.RegularExpressions.Regex]::Match($(GitTag), $(PatternGitTag)).Groups[2].Value)</AssemblyVersion>
<FileVersion>$([System.Text.RegularExpressions.Regex]::Match($(GitTag), $(PatternGitTag)).Groups[2].Value)</FileVersion>
<Version>$([System.Text.RegularExpressions.Regex]::Match($(GitTag), $(PatternGitTag)).Groups[2].Value)</Version>
<InformationalVersion>$([System.Text.RegularExpressions.Regex]::Match($(GitTag), $(PatternGitTag)).Groups[1].Value)</InformationalVersion>
<PatternGitTag>^v(((\d+\.\d+\.\d+\.\d+)(?:-[a-z]+\.\d+)?)-(\d+-g.+))</PatternGitTag>
<AssemblyVersion>$([System.Text.RegularExpressions.Regex]::Match($(GitTag), $(PatternGitTag)).Groups[3].Value)</AssemblyVersion>
<FileVersion>$([System.Text.RegularExpressions.Regex]::Match($(GitTag), $(PatternGitTag)).Groups[3].Value)</FileVersion>
<Version>$([System.Text.RegularExpressions.Regex]::Match($(GitTag), $(PatternGitTag)).Groups[3].Value)</Version>
<FullVersion>$([System.Text.RegularExpressions.Regex]::Match($(GitTag), $(PatternGitTag)).Groups[2].Value)</FullVersion>
<GitCommitInfo>$([System.Text.RegularExpressions.Regex]::Match($(GitTag), $(PatternGitTag)).Groups[4].Value)</GitCommitInfo>
<InformationalVersion>$(FullVersion)+$(GitCommitInfo)</InformationalVersion>
</PropertyGroup>

<Message Text="*** InformationalVersion $(InformationalVersion)" Importance="high" />
Expand Down
15 changes: 3 additions & 12 deletions src/Tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,19 @@ namespace Tests;

public sealed class IntegrationTests : IDisposable
{
private readonly Runspace runSpace;
private readonly PowerShell powerShell;

public IntegrationTests()
{
var initialSessionState = InitialSessionState.Create();
var initialSessionState = InitialSessionState.CreateDefault2();

var entry1 = new SessionStateCmdletEntry("New-DataProtectionSecret", typeof(NewDataProtectionSecretCommand), null);
initialSessionState.Commands.Add(entry1);

var entry2 = new SessionStateCmdletEntry("Read-DataProtectionSecret", typeof(ReadDataProtectionSecretCommand), null);
initialSessionState.Commands.Add(entry2);

this.runSpace = RunspaceFactory.CreateRunspace(initialSessionState);
this.powerShell = PowerShell.Create();

this.runSpace.Open();
this.powerShell.Runspace = this.runSpace;
this.powerShell = PowerShell.Create(initialSessionState);
}

public static TheoryData<string, DataProtectionScope> NewDataProtectionSecretArguments() => new()
Expand Down Expand Up @@ -182,9 +177,5 @@ public void SecureStringAsObjectInPipelineShouldPass(string data, DataProtection
}

/// <inheritdoc />
public void Dispose()
{
this.powerShell.Dispose();
this.runSpace.Dispose();
}
public void Dispose() => this.powerShell.Dispose();
}
15 changes: 3 additions & 12 deletions src/Tests/ParameterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,19 @@ namespace Tests;

public sealed class ParameterTests : IDisposable
{
private readonly Runspace runSpace;
private readonly PowerShell powerShell;

public ParameterTests()
{
var initialSessionState = InitialSessionState.Create();
var initialSessionState = InitialSessionState.CreateDefault2();

var entry1 = new SessionStateCmdletEntry("New-DataProtectionSecret", typeof(NewDataProtectionSecretCommand), null);
initialSessionState.Commands.Add(entry1);

var entry2 = new SessionStateCmdletEntry("Read-DataProtectionSecret", typeof(ReadDataProtectionSecretCommand), null);
initialSessionState.Commands.Add(entry2);

this.runSpace = RunspaceFactory.CreateRunspace(initialSessionState);
this.powerShell = PowerShell.Create();

this.runSpace.Open();
this.powerShell.Runspace = this.runSpace;
this.powerShell = PowerShell.Create(initialSessionState);
}

[Fact]
Expand Down Expand Up @@ -120,9 +115,5 @@ public void ReadDataProtectionSecretWithInvalidScopeShouldThrow()
}

/// <inheritdoc />
public void Dispose()
{
this.powerShell.Dispose();
this.runSpace.Dispose();
}
public void Dispose() => this.powerShell.Dispose();
}
4 changes: 2 additions & 2 deletions src/Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="Microsoft.PowerShell.5.1.ReferenceAssemblies" Version="1.0.0" />
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="9.0.5" />
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="10.0.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
7 changes: 7 additions & 0 deletions src/global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"sdk": {
"version": "10.0.100",
"rollForward": "latestFeature",
"allowPrerelease": true
}
}