Skip to content

Commit

Permalink
Testing the PowerShell module and back to PS7.2 (#65)
Browse files Browse the repository at this point in the history
Fixed #66 #61
  • Loading branch information
svrooij authored May 7, 2024
1 parent d5488ed commit 538532c
Show file tree
Hide file tree
Showing 40 changed files with 1,796 additions and 408 deletions.
88 changes: 83 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:

jobs:
test:
name: 🛠️ Build and Test
name: 🛠️ Build and Test C#
runs-on: ubuntu-latest
permissions:
contents: read
Expand Down Expand Up @@ -61,11 +61,90 @@ jobs:
if: always()
run: dotnet format --verify-no-changes

testps:
name: 🛠️ Build and Test PowerShell
runs-on: ubuntu-latest
permissions:
contents: read
issues: read
checks: write
pull-requests: write
steps:
- name: 👨‍💻 Check-out code
uses: actions/checkout@v4

- name: 👨‍🔧 Setup .NET Core SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x

- name: 🔍 Enable problem matchers
run: echo "::add-matcher::.github/matchers/dotnet.json"

- name: 🦸‍♂️ Restore steriods
uses: actions/cache@v4
with:
path: ~/.nuget/packages
# Look to see if there is a cache hit for the corresponding requirements file
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget
- name: 🎒 Load packages
run: dotnet restore

- name: 🛠️ Build module
shell: pwsh
run:
dotnet build ./src/Svrooij.WinTuner.CmdLets/Svrooij.WinTuner.CmdLets.csproj --configuration Release --no-restore -p:Version="0.0.1-dev" -o ./dist/WinTuner

- name: 📦 Install Pester
shell: pwsh
run: Install-Module -Name Pester -Force -SkipPublisherCheck -Scope CurrentUser

- name: 🕵️ Import module and list commands
shell: pwsh
run: |
Import-Module ./dist/WinTuner/WinTuner.psd1
Get-Command -Module WinTuner
- name: 🧪 Run test
shell: pwsh
run: |
Import-Module Pester
Import-Module ./dist/WinTuner/WinTuner.psd1
$pesterConfig = [PesterConfiguration]@{
Output = @{
Verbosity = "Normal"
CIFormat = "Auto"
StackTraceVerbosity = "FirstLine"
}
TestResult = @{
Enabled = $true
OutputPath = "${{ github.workspace }}/testresults/TestResults.xml"
OutputFormat = "JUnitXml"
}
Run = @{
Path = "./tests/WinTuner.Cmdlets.Tests"
Exit = $true
}
Should = @{
ErrorAction = "Continue"
}
}
Invoke-Pester -Configuration $pesterConfig
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: ${{ github.workspace }}/testresults/*.xml

publish-nuget:
name: 📦 Publish WinTuner to nuget
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
needs: [test]
needs: [test, testps]
steps:
- name: 👨‍💻 Check-out code
uses: actions/checkout@v4
Expand Down Expand Up @@ -109,7 +188,7 @@ jobs:
name: 📦 Publish WinTuner to PowerShell Gallery
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
needs: [test]
needs: [test, testps]
steps:
- name: 👨‍💻 Check-out code
uses: actions/checkout@v4
Expand Down Expand Up @@ -149,12 +228,11 @@ jobs:
shell: pwsh
run: dotnet build ./src/Svrooij.WinTuner.CmdLets/Svrooij.WinTuner.CmdLets.csproj --configuration Release --no-restore -p:Version=$("${{ github.ref_name }}".Substring(1)) -o ./dist/WinTuner

- name: 🧪 Run tests (import module)
- name: 🧪 Import module
shell: pwsh
run: |
Import-Module ./dist/WinTuner/WinTuner.psd1
Get-Command -Module WinTuner
Get-Command -Module WinTuner | Select-Object -ExpandProperty Name | ForEach-Object { Get-Help -Name $_ -Full }
- name: 📦 Publish WinTuner to PowerShell Gallery
shell: pwsh
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,5 @@ dist

# LUT config file from Visual Studio
*.lutconfig

TestResults.xml
8 changes: 6 additions & 2 deletions src/Svrooij.WinTuner.CmdLets/Commands/DeployWtMsStoreApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public override async Task ProcessRecordAsync(CancellationToken cancellationToke
ValidateAuthenticationParameters();
if (ParameterSetName == nameof(SearchQuery))
{
#if NET8_0_OR_GREATER
ArgumentException.ThrowIfNullOrWhiteSpace(SearchQuery);
#endif
logger!.LogInformation("Searching package id for {searchQuery}", SearchQuery);
PackageId = await graphStoreAppUploader!.GetStoreIdForNameAsync(SearchQuery!, cancellationToken);
if (string.IsNullOrEmpty(PackageId))
Expand All @@ -72,13 +74,15 @@ public override async Task ProcessRecordAsync(CancellationToken cancellationToke
}

// At this moment the package ID should always be filled.
ArgumentException.ThrowIfNullOrWhiteSpace(PackageId);

#if NET8_0_OR_GREATER
ArgumentException.ThrowIfNullOrWhiteSpace(PackageId);
#endif
logger!.LogInformation("Uploading MSStore app {PackageId} to Intune", PackageId);
var graphServiceClient = CreateGraphServiceClient(httpClient!);
try
{
var app = await graphStoreAppUploader!.CreateStoreAppAsync(graphServiceClient, PackageId, cancellationToken);
var app = await graphStoreAppUploader!.CreateStoreAppAsync(graphServiceClient, PackageId!, cancellationToken);

logger!.LogInformation("Created MSStore app {PackageId} with id {appId}", PackageId, app!.Id);
WriteObject(app);
Expand Down
6 changes: 3 additions & 3 deletions src/Svrooij.WinTuner.CmdLets/Svrooij.WinTuner.CmdLets.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<AssemblyName>Svrooij.WinTuner.CmdLets</AssemblyName>
<LangVersion>10.0</LangVersion>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
Expand All @@ -14,8 +14,8 @@

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.11.2" />
<PackageReference Include="Svrooij.PowerShell.DependencyInjection" Version="1.1.0" />
<PackageReference Include="PowerShellStandard.Library" Version="5.1.1">
<PackageReference Include="Svrooij.PowerShell.DependencyInjection" Version="1.1.4" />
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.2.19">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>
Expand Down
Loading

0 comments on commit 538532c

Please sign in to comment.