-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Install, Update, Uninstall support
- Loading branch information
1 parent
bdf7820
commit 490f7ed
Showing
9 changed files
with
375 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
name: CI | ||
|
||
defaults: | ||
run: | ||
shell: pwsh | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
|
||
pull_request: | ||
branches: [ main ] | ||
|
||
release: | ||
types: [ published ] | ||
|
||
jobs: | ||
Build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: .NET Build | ||
run: dotnet build --configuration Release | ||
|
||
- name: Create module | ||
run: | | ||
New-Item module -ItemType Directory | ||
$settings = Import-PowerShellDataFile ./BuildSettings.psd1 | ||
Copy-Item @settings | ||
- name: Upload module | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: module | ||
path: ./module/ | ||
|
||
Test: | ||
needs: Build | ||
runs-on: windows-latest | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Download module | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: module | ||
path: C:\Users\runneradmin\Documents\PowerShell\Modules\AnyPackage.DotNet.Tool\ | ||
|
||
- name: Install AnyPackage module | ||
run: Install-Module AnyPackage -Force -AllowClobber | ||
|
||
- name: Test with Pester | ||
run: | | ||
$ht = Import-PowerShellDataFile PesterSettings.psd1 | ||
$config = New-PesterConfiguration $ht | ||
Invoke-Pester -Configuration $config | ||
Sign: | ||
needs: Test | ||
if: github.event_name == 'release' && github.event.action == 'published' | ||
runs-on: windows-latest | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Download module | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: module | ||
path: module | ||
|
||
- name: Import certificate | ||
env: | ||
CERTIFICATE_BASE64: ${{ secrets.CERTIFICATE_BASE64 }} | ||
CERTIFICATE_PASSWORD: ${{ secrets.CERTIFICATE_PASSWORD }} | ||
CERTIFICATE_PASSWORD_KEY_BASE64: ${{ secrets.CERTIFICATE_PASSWORD_KEY_BASE64 }} | ||
run: | | ||
[convert]::FromBase64String($env:CERTIFICATE_BASE64) | Set-Content -Path cert.pfx -AsByteStream | ||
$key = [convert]::FromBase64String($env:CERTIFICATE_PASSWORD_KEY_BASE64) | ||
$password = ConvertTo-SecureString $env:CERTIFICATE_PASSWORD -Key $key | ||
Import-PfxCertificate cert.pfx -Password $password -CertStoreLocation Cert:\CurrentUser\My | ||
- name: Sign files | ||
run: | | ||
$config = Import-PowerShellDataFile SignSettings.psd1 | ||
$config['Certificate'] = Get-ChildItem Cert:\CurrentUser\My -CodeSigningCert | ||
Set-Location .\module | ||
Set-AuthenticodeSignature @config | ||
- name: Create and sign catalog file | ||
run: | | ||
$config = Import-PowerShellDataFile SignSettings.psd1 | ||
$config['FilePath'] = 'AnyPackage.DotNet.Tool.cat' | ||
$config['Certificate'] = Get-ChildItem Cert:\CurrentUser\My -CodeSigningCert | ||
Set-Location .\module | ||
New-FileCatalog $config['FilePath'] -CatalogVersion 2 | ||
Set-AuthenticodeSignature @config | ||
- name: Upload module | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: module-signed | ||
path: ./module/ | ||
|
||
Publish: | ||
needs: Sign | ||
if: github.event_name == 'release' && github.event.action == 'published' | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Download module | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: module-signed | ||
path: '~/.local/share/powershell/Modules/AnyPackage.DotNet.Tool' | ||
|
||
- name: Install AnyPackage module | ||
run: Install-Module AnyPackage -Force -AllowClobber | ||
|
||
- name: Publish Module | ||
env: | ||
NUGET_KEY: ${{ secrets.NUGET_KEY }} | ||
run: Publish-Module -Name AnyPackage.DotNet.Tool -NuGetApiKey $env:NUGET_KEY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: "CodeQL" | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
schedule: | ||
- cron: '32 19 * * 5' | ||
|
||
jobs: | ||
analyze: | ||
name: Analyze | ||
runs-on: ubuntu-latest | ||
permissions: | ||
actions: read | ||
contents: read | ||
security-events: write | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
language: [ 'csharp' ] | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Initialize CodeQL | ||
uses: github/codeql-action/init@v2 | ||
with: | ||
languages: ${{ matrix.language }} | ||
|
||
- name: Autobuild | ||
uses: github/codeql-action/autobuild@v2 | ||
|
||
- name: Perform CodeQL Analysis | ||
uses: github/codeql-action/analyze@v2 | ||
with: | ||
category: "/language:${{matrix.language}}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@{ | ||
Path = @( | ||
'./src/code/bin/Release/netstandard2.0/AnyPackage.DotNet.ToolProvider.dll', | ||
'./src/AnyPackage.DotNet.Tool.psd1' | ||
) | ||
Destination = './module' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#Requires -Modules AnyPackage.DotNet.Tool | ||
|
||
Describe Find-Package { | ||
Context 'with -Prerelease parameter' { | ||
It 'should return prerelease versions' { | ||
Find-Package -Name PowerShell -Prerelease -WarningAction SilentlyContinue | | ||
Select-Object -ExpandProperty Version | | ||
Where-Object IsPrerelease -eq $true | | ||
Should -Not -BeNullOrEmpty | ||
} | ||
} | ||
|
||
Context 'with -Name parameter' { | ||
It 'single name' { | ||
Find-Package -Name powershell | | ||
Should -Not -BeNullOrEmpty | ||
} | ||
|
||
It 'multiple names' { | ||
Find-Package -Name powershell, microsoft.dotnet-interactive | | ||
Select-Object -Property Name -Unique | | ||
Should -HaveCount 2 | ||
} | ||
} | ||
|
||
Context 'with -Version parameter' { | ||
It 'should return value' { | ||
Find-Package -Name powershell -Version 7.4.1 | | ||
Should -Not -BeNullOrEmpty | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#Requires -Modules AnyPackage.DotNet.Tool | ||
|
||
Describe Get-Package { | ||
BeforeAll { | ||
dotnet tool install powerprepare.app --global | ||
dotnet tool install ib --global | ||
} | ||
|
||
AfterAll { | ||
dotnet tool uninstall powerprepare.app --global | ||
dotnet tool uninstall ib --global | ||
} | ||
|
||
Context 'with no parameters' { | ||
It 'should return results' { | ||
Get-Package | | ||
Should -Not -BeNullOrEmpty | ||
} | ||
} | ||
|
||
Context 'with -Name parameter' { | ||
It 'should return powerprepare.app' { | ||
Get-Package -Name powerprepare.app | | ||
Should -Not -BeNullOrEmpty | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#Requires -Modules AnyPackage.DotNet.Tool | ||
|
||
Describe Install-Package { | ||
AfterEach { | ||
dotnet tool uninstall powerprepare.app --global | ||
} | ||
|
||
Context 'with -Name parameter' { | ||
It 'should install' { | ||
{ Install-Package -Name powerprepare.app } | | ||
Should -Not -Throw | ||
} | ||
} | ||
|
||
Context 'with -Version parameter' { | ||
It 'should install' { | ||
{ Install-Package -Name powerprepare.app -Version '1.0.1' -ErrorAction Stop } | | ||
Should -Not -Throw | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#Requires -Modules AnyPackage.DotNet.Tool | ||
|
||
Describe Uninstall-Package { | ||
BeforeEach { | ||
dotnet tool install powerprepare.app --global | ||
} | ||
|
||
Context 'with -Name parameter' { | ||
It 'should uninstall' { | ||
{ Uninstall-Package -Name powerprepare.app } | | ||
Should -Not -Throw | ||
} | ||
} | ||
} |
Oops, something went wrong.