-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0c7c81f
Showing
11 changed files
with
396 additions
and
0 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,111 @@ | ||
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: Upload module | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: module | ||
path: ./src/ | ||
|
||
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.ModuleFast\ | ||
|
||
- 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: 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 .\src | ||
Set-AuthenticodeSignature @config | ||
- name: Create and sign catalog file | ||
run: | | ||
$config = Import-PowerShellDataFile SignSettings.psd1 | ||
$config['FilePath'] = 'AnyPackage.ModuleFast.cat' | ||
$config['Certificate'] = Get-ChildItem Cert:\CurrentUser\My -CodeSigningCert | ||
Set-Location .\src | ||
New-FileCatalog $config['FilePath'] -CatalogVersion 2 | ||
Set-AuthenticodeSignature @config | ||
- name: Upload module | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: module-signed | ||
path: ./src/ | ||
|
||
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.ModuleFast' | ||
|
||
- name: Install AnyPackage module | ||
run: Install-Module AnyPackage -Force -AllowClobber | ||
|
||
- name: Publish Module | ||
env: | ||
NUGET_KEY: ${{ secrets.NUGET_KEY }} | ||
run: Publish-Module -Name AnyPackage.ModuleFast -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: PSScriptAnalyzer | ||
|
||
defaults: | ||
run: | ||
shell: pwsh | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
schedule: | ||
- cron: '22 1 * * 3' | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
permissions: | ||
contents: read | ||
security-events: write | ||
name: PSScriptAnalyzer | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install AnyPackage and ConvertToSARIF | ||
run: Install-Module AnyPackage, ConvertToSARIF -Force -AllowClobber | ||
|
||
- name: Run PSScriptAnalyzer | ||
run: | | ||
Import-Module AnyPackage, ConvertToSARIF | ||
Invoke-ScriptAnalyzer -Path . -Recurse | ConvertTo-SARIF -FilePath results.sarif | ||
- name: Upload SARIF results file | ||
uses: github/codeql-action/upload-sarif@v2 | ||
with: | ||
sarif_file: results.sarif |
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,5 @@ | ||
{ | ||
"cSpell.words": [ | ||
"Nieto" | ||
] | ||
} |
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,17 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## [Unreleased] | ||
|
||
## [0.1.0] - 2024-01-27 | ||
|
||
### Added | ||
|
||
- Initial release | ||
|
||
[Unreleased]: https://github.com/anypackage/modulefast/compare/v0.1.0...HEAD | ||
[0.1.0]: https://github.com/anypackage/modulefast/releases/tag/v0.1.0 |
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 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Thomas Nieto | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,8 @@ | ||
@{ | ||
Run = @{ | ||
Exit = $true | ||
} | ||
Output = @{ | ||
Verbosity = 'Detailed' | ||
} | ||
} |
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,25 @@ | ||
# AnyPackage.ModuleFast | ||
|
||
AnyPackage.ModuleFast is an AnyPackage provider that facilitates installing PowerShell modules and their dependencies quickly. | ||
|
||
## Install AnyPackage.ModuleFast | ||
|
||
```PowerShell | ||
Install-PSResource AnyPackage.ModuleFast | ||
``` | ||
|
||
## Import AnyPackage.ModuleFast | ||
|
||
```PowerShell | ||
Import-Module AnyPackage.ModuleFast | ||
``` | ||
|
||
## Sample usages | ||
|
||
### Install a package | ||
|
||
```PowerShell | ||
Install-Package Az | ||
``` | ||
|
||
## Known Issues |
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,5 @@ | ||
@{ | ||
FilePath = @('AnyPackage.ModuleFast.psd1', 'AnyPackage.ModuleFast.psm1') | ||
TimeStampServer = 'http://timestamp.sectigo.com' | ||
HashAlgorithm = 'SHA256' | ||
} |
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 @@ | ||
@{ | ||
RootModule = 'AnyPackage.ModuleFast.psm1' | ||
ModuleVersion = '0.1.0' | ||
CompatiblePSEditions = @('Desktop', 'Core') | ||
GUID = '95ea8d7f-586e-42e1-83b2-2688f02d42e9' | ||
Author = 'Thomas Nieto' | ||
Copyright = '(c) 2024 Thomas Nieto. All rights reserved.' | ||
Description = 'ModuleFast provider for AnyPackage.' | ||
PowerShellVersion = '5.1' | ||
RequiredModules = @( | ||
@{ ModuleName = 'AnyPackage'; ModuleVersion = '0.5.1' }, | ||
@{ ModuleName = 'ModuleFast'; ModuleVersion = '0.1.2' }) | ||
FunctionsToExport = @() | ||
CmdletsToExport = @() | ||
AliasesToExport = @() | ||
PrivateData = @{ | ||
AnyPackage = @{ | ||
Providers = 'ModuleFast' | ||
} | ||
PSData = @{ | ||
Tags = @('AnyPackage', 'Provider', 'ModuleFast', 'Windows') | ||
LicenseUri = 'https://github.com/anypackage/modulefast/blob/main/LICENSE' | ||
ProjectUri = 'https://github.com/anypackage/modulefast' | ||
} | ||
} | ||
HelpInfoURI = 'https://go.anypackage.dev/help' | ||
} |
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,123 @@ | ||
# Copyright (c) Thomas Nieto - All Rights Reserved | ||
# You may use, distribute and modify this code under the | ||
# terms of the MIT license. | ||
|
||
using module AnyPackage | ||
using namespace AnyPackage.Provider | ||
using namespace NuGet.Versioning | ||
using namespace System.Management.Automation | ||
|
||
[PackageProvider('ModuleFast')] | ||
class ModuleFastProvider : PackageProvider, IInstallPackage { | ||
[void] InstallPackage([PackageRequest] $request) { | ||
$installModuleFast = @{ } | ||
|
||
if ($request.DynamicParameters.Destination) { | ||
$installModuleFast['Destination'] = $request.DynamicParameters.Destination | ||
} | ||
|
||
if ($request.DynamicParameters.ThrottleLimit) { | ||
$installModuleFast['ThrottleLimit'] = $request.DynamicParameters.ThrottleLimit | ||
} | ||
|
||
if ($request.DynamicParameters.CILockFilePath) { | ||
$installModuleFast['CILockFilePath'] = $request.DynamicParameters.CILockFilePath | ||
} | ||
|
||
if ($request.DynamicParameters.Update) { | ||
$installModuleFast['Update'] = $request.DynamicParameters.Update | ||
} | ||
|
||
if ($request.DynamicParameters.NoPathUpdate) { | ||
$installModuleFast['NoPathUpdate'] = $request.DynamicParameters.NoPathUpdate | ||
} | ||
|
||
if ($request.DynamicParameters.NoPSModulePathUpdate) { | ||
$installModuleFast['NoPSModulePathUpdate'] = $request.DynamicParameters.NoPSModulePathUpdate | ||
} | ||
|
||
if ($request.Source) { | ||
$installModuleFast['Source'] = $request.Source | ||
} | ||
|
||
$spec = '' | ||
|
||
if ($request.Prerelease) { | ||
$spec += '!' | ||
} | ||
|
||
$spec += $request.Name | ||
|
||
if ($request.Version) { | ||
$spec += ":$($request.Version)" | ||
} | ||
|
||
Install-ModuleFast $spec @installModuleFast -ErrorAction Stop -PassThru | | ||
Write-Package -Request $request | ||
} | ||
|
||
[object] GetDynamicParameters([string] $commandName) { | ||
return $(switch ($commandName) { | ||
'Install-Package' { [InstallPackageDynamicParameters]::new() } | ||
default { $null } | ||
}) | ||
} | ||
} | ||
|
||
class InstallPackageDynamicParameters { | ||
[Parameter()] | ||
[string] $Destination | ||
|
||
[Parameter()] | ||
[int] $ThrottleLimit | ||
|
||
[Parameter()] | ||
[string] $CILockFilePath | ||
|
||
[Parameter()] | ||
[switch] $Update | ||
|
||
[Parameter()] | ||
[switch] $NoPathUpdate | ||
|
||
[Parameter()] | ||
[switch] $NoPSModulePathUpdate | ||
} | ||
|
||
[guid] $id = '853fb009-a8f3-4ecf-9f72-9f81e0c32144' | ||
[PackageProviderManager]::RegisterProvider($id, [ModuleFastProvider], $MyInvocation.MyCommand.ScriptBlock.Module) | ||
|
||
$MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = { | ||
[PackageProviderManager]::UnregisterProvider($id) | ||
} | ||
|
||
function Write-Package { | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(ValueFromPipelineByPropertyName)] | ||
[string] | ||
$Name, | ||
|
||
[Parameter(ValueFromPipelineByPropertyName)] | ||
[string] | ||
$ModuleVersion, | ||
|
||
[Parameter(ValueFromPipelineByPropertyName)] | ||
[string] | ||
$Location, | ||
|
||
[Parameter(ValueFromPipelineByPropertyName)] | ||
[string] | ||
$Guid, | ||
|
||
[Parameter(Mandatory)] | ||
[PackageRequest] | ||
$Request | ||
) | ||
|
||
process { | ||
$source = [PackageSourceInfo]::new($Location, $Location, $Request.ProviderInfo) | ||
$package = [PackageInfo]::new($Name, $Version, $source, '', $null, @{ Guid = $Guid }, $Request.ProviderInfo) | ||
$Request.WritePackage($package) | ||
} | ||
} |
Oops, something went wrong.