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
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"powershell.codeFormatting.whitespaceAfterSeparator": false,
"powershell.codeFormatting.whitespaceAroundOperator": false,
"powershell.codeFormatting.whitespaceBeforeOpenParen": false,
"powershell.codeFormatting.preset": "OTBS",

Check warning on line 7 in .vscode/settings.json

View workflow job for this annotation

GitHub Actions / Continuous Integration / Run Linters

Unknown word (OTBS) Suggestions: (orbs, ORBS, otis, OTIS, Otis)
"powershell.codeFormatting.trimWhitespaceAroundPipe": true,
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
Expand All @@ -16,5 +16,6 @@
"**/*.code-search": true,
"**/.ruby-lsp": true,
"Output/**": true
}
}
},
"snyk.advanced.autoSelectOrganization": true
}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Changelog

<!-- cspell:ignore parenthesization yess -->

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.1.0/),
Expand Down
4 changes: 3 additions & 1 deletion Examples/ModuleDependencies.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Handling Module Dependencies

<!-- cspell:ignore azcopy msiexec -->

`Install-Module` handles dependencies declared in a module manifest's `RequiredModules` section, but it only covers the PowerShell Gallery. PSDepend lets you declare dependencies from multiple sources — Gallery modules, Git repos, and file downloads — in one place.

This walkthrough demonstrates embedding a `requirements.psd1` in a module so dependencies are resolved automatically on import.
Expand All @@ -22,7 +24,7 @@ Invoke-PSDepend -Path $PSScriptRoot\Requirements.psd1 -Target $PSScriptRoot\Depe

Import-Module Posh-SSH

Function Test-PSDependExample {
function Test-PSDependExample {
Get-ChildItem $PSScriptRoot\Dependencies -Recurse -Depth 1 | Select-Object -ExpandProperty FullName
Get-Module | Select-Object Name, Path
}
Expand Down
2 changes: 1 addition & 1 deletion PSDepend/PSDepend.Format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</ListItem>
<ListItem>
<Label>Tags</Label>
<ScriptBlock>Try { ($_.Tags | Out-String ).trimend("`n")} Catch {$_.Tags} </ScriptBlock>
<ScriptBlock>Try { ($_.Tags | Out-String ).TrimEnd("`n")} Catch {$_.Tags} </ScriptBlock>
</ListItem>
</ListItems>
</ListEntry>
Expand Down
24 changes: 9 additions & 15 deletions PSDepend/PSDependScripts/Chocolatey.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<#
# cspell:ignore lessmsi
<#
.SYNOPSIS
Installs a package from a Chocolatey repository.

Expand Down Expand Up @@ -91,8 +92,7 @@ function Get-ChocoVersion {
# Strip prerelease/build metadata (e.g. 2.2.2-beta) before parsing
if ([System.Version]::TryParse(($rawVersion -replace '[-+].*$'), [ref]$parsedVersion)) {
$parsedVersion
}
else {
} else {
# Assume a modern CLI when the version cannot be determined
[System.Version]'2.0'
}
Expand Down Expand Up @@ -243,8 +243,7 @@ if (-not (Get-Command -Name 'choco.exe' -ErrorAction SilentlyContinue)) {
try {
Invoke-WebRequest -UseBasicParsing -Uri $ChocoInstallScriptUrl -OutFile $scriptPath
& $scriptPath
}
catch {
} catch {
throw "Unable to install Chocolatey from '$ChocoInstallScriptUrl'."
}
}
Expand Down Expand Up @@ -274,8 +273,7 @@ Write-Verbose "Getting package [$Name] version, if it is installed."
$existingVersion = (Get-ChocoInstalledPackage -Name $Name).Version
if ($existingVersion) {
Write-Verbose "Found package [$Name] installed with version [$existingVersion]."
}
else {
} else {
Write-Verbose "Package [$Name] not installed."
}

Expand All @@ -302,8 +300,7 @@ Write-Verbose "Getting latest package [$Name] version from source [$Source]."
$repositoryVersion = (Get-ChocoLatestPackage @repoParams).Version
if ($repositoryVersion) {
Write-Verbose "Found package [$Name] version [$repositoryVersion] on source [$Source]."
}
else {
} else {
Write-Verbose "Package [$Name] not found on source [$Source]. Nothing more can be done."
return # cannot continue
}
Expand All @@ -318,14 +315,12 @@ $haveLatest = if (
[System.Management.Automation.SemanticVersion]::TryParse([string]$existingVersion, [ref]$parsedExistingSemanticVersion)
) {
$parsedRepositorySemanticVersion -le $parsedExistingSemanticVersion
}
elseif (
} elseif (
[System.Version]::TryParse([string]$repositoryVersion, [ref]$parsedRepositoryVersion) -and
[System.Version]::TryParse([string]$existingVersion, [ref]$parsedExistingVersion)
) {
$parsedRepositoryVersion -le $parsedExistingVersion
}
else {
} else {
$false
}
if ($Version -eq 'latest' -and $haveLatest) {
Expand Down Expand Up @@ -353,7 +348,6 @@ if ($PSDependAction -contains 'Install') {
}

Invoke-ChocoInstallPackage @params
}
elseif ($PSDependAction -contains 'Test' -and $PSDependAction.count -eq 1) {
} elseif ($PSDependAction -contains 'Test' -and $PSDependAction.count -eq 1) {
return $false
}
6 changes: 3 additions & 3 deletions PSDepend/PSDependScripts/Command.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
}
}

# Run some aribtrary PowerShell code that assigns a variable and uses it in a string
# Run some arbitrary PowerShell code that assigns a variable and uses it in a string
# Output: Running a command on WJ-LAB
#>
[cmdletbinding()]
[CmdletBinding()]
param (
[PSTypeName('PSDepend.Dependency')]
[psobject[]]$Dependency,
[PSObject[]]$Dependency,

[switch]$FailOnError,

Expand Down
6 changes: 3 additions & 3 deletions PSDepend/PSDependScripts/DotnetSdk.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
}

# Simple syntax
# The .NET SDK will be installed with the latest verion from the LTS channel, globally.
# The .NET SDK will be installed with the latest version from the LTS channel, globally.

#>
[CmdletBinding()]
param(
[PSTypeName('PSDepend.Dependency')]
[psobject[]]
[PSObject[]]
$Dependency,

[ValidateSet('Test', 'Install', 'Import')]
Expand All @@ -60,7 +60,7 @@ param(

# Users can specify 'Global which will use the default global path of
# "$env:LocalAppData\Microsoft\dotnet" on Windows or "$env:HOME/.dotnet" elsewhere
# Since Global is the default behavior, we ingore the fact that the Target was set.
# Since Global is the default behavior, we ignore the fact that the Target was set.
$InstallDir = if ($Dependency.Target -and $Dependency.Target -ne 'Global') { $Dependency.Target }
$Version = $Dependency.Version
$Channel = if ($Dependency.DependencyName) { $Dependency.DependencyName } else { "release" }
Expand Down
9 changes: 5 additions & 4 deletions PSDepend/PSDependScripts/FileDownload.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<#
# cspell:ignore extensionless sqllite
<#
.SYNOPSIS
Download a file

Expand Down Expand Up @@ -35,18 +36,18 @@

# Downloads System.Data.SQLite.dll to C:\temp\sqlite.dll
#>
[cmdletbinding()]
[CmdletBinding()]
param(
[PSTypeName('PSDepend.Dependency')]
[psobject[]]
[PSObject[]]
$Dependency,

[ValidateSet('Test', 'Install')]
[string[]]$PSDependAction = @('Install')
)

function Parse-URLForFile {
[cmdletbinding()]
[CmdletBinding()]
param($URL)
# This will need work. Assume leaf is file. If CGI exists in leaf, assume it is after the file
$FileName = $URL.split('/')[-1]
Expand Down
7 changes: 4 additions & 3 deletions PSDepend/PSDependScripts/FileSystem.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<#
# cspell:ignore psams
<#
.SYNOPSIS
EXPERIMENTAL: Use Robocopy or Copy-Item for folder and file dependencies, respectively.

Expand Down Expand Up @@ -59,10 +60,10 @@
# Copy psams module to C:\ProjectX\psams

#>
[cmdletbinding()]
[CmdletBinding()]
param (
[PSTypeName('PSDepend.Dependency')]
[psobject[]]
[PSObject[]]
$Dependency,

[ValidateSet('Test', 'Install', 'Import')]
Expand Down
37 changes: 16 additions & 21 deletions PSDepend/PSDependScripts/Git.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<#
# cspell:ignore jdoe TrimEnd
<#
.SYNOPSIS
Clone a git repository

Expand Down Expand Up @@ -53,14 +54,14 @@

# Simple syntax
# First example shows cloning PSDeploy from ramblingcookiemonster's GitHub repo
# Second example shows clonging BuildHelpers from jdoe's internal GitLab account and checking out a specific commit
# Second example shows cloning BuildHelpers from jdoe's internal GitLab account and checking out a specific commit
# Both are cloned to the current path (e.g. .\<repo name>)
# This syntax assumes git as a source. The right hand side is the version (branch, commit, tags/<tag name>, etc.)
#>
[cmdletbinding()]
[CmdletBinding()]
param(
[PSTypeName('PSDepend.Dependency')]
[psobject[]]$Dependency,
[PSObject[]]$Dependency,

[switch]$Force,

Expand All @@ -84,16 +85,14 @@ if (-not $Name) {
if ($Name -match "^[a-zA-Z0-9]+/[a-zA-Z0-9_-]+$") {
$Name = "https://github.com/$Name.git"
}
$GitName = $Name.trimend('/').split('/')[-1] -replace "\.git$", ''
$GitName = $Name.TrimEnd('/').split('/')[-1] -replace "\.git$", ''
if ($Dependency.Target -and ($Target = (Get-Item $Dependency.Target -ErrorAction SilentlyContinue).FullName)) {
Write-Debug "Target resolved to $Target"
}
else {
} else {
if ($Dependency.Target) {
$Target = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Dependency.Target)
Write-Debug "Target $($Dependency.Target) does not exist yet, will be created"
}
else {
} else {
$Target = $PWD.Path
Write-Debug "Target defaulted to current dir: $Target"
}
Expand All @@ -111,8 +110,8 @@ if (-not (Test-Path $RepoPath)) {
if ( $PSDependAction -contains 'Test' -and $PSDependAction.count -eq 1) {
return $False
}
}
else { # Target exists
} else {
# Target exists
$GottaTest = $True
}

Expand All @@ -129,28 +128,25 @@ if (-not $Version) {
if ($GottaTest) {
Push-Location
Set-Location $RepoPath
$Branch = Invoke-ExternalCommand git -Arguments (Write-Output rev-parse --abbrev-ref HEAD) -Passthru
$Commit = Invoke-ExternalCommand git -Arguments (Write-Output rev-parse HEAD) -Passthru
$Branch = Invoke-ExternalCommand git -Arguments (Write-Output rev-parse --abbrev-ref HEAD) -PassThru
$Commit = Invoke-ExternalCommand git -Arguments (Write-Output rev-parse HEAD) -PassThru
Pop-Location
if (-not $Branch) {
Write-Warning "[$RepoPath] exists but does not appear to be a valid git repository. Skipping [$DependencyName]."
if ($PSDependAction -contains 'Test' -and $PSDependAction.count -eq 1) {
return $false
}
$GottaInstall = $False
}
elseif ($Version -eq $Branch -or $Version -eq $Commit) {
} elseif ($Version -eq $Branch -or $Version -eq $Commit) {
Write-Verbose "[$RepoPath] exists and is already at version [$Version]"
if ($PSDependAction -contains 'Test' -and $PSDependAction.count -eq 1) {
return $true
}
$GottaInstall = $False
}
elseif ($PSDependAction -contains 'Test' -and $PSDependAction.count -eq 1) {
} elseif ($PSDependAction -contains 'Test' -and $PSDependAction.count -eq 1) {
Write-Verbose "[$RepoPath] exists and is at branch [$Branch], commit [$Commit].`nWe don't currently support moving to the requested version [$Version]"
return $false
}
else {
} else {
Write-Verbose "[$RepoPath] exists and is at branch [$Branch], commit [$Commit].`nWe don't currently support moving to the requested version [$Version]"
$GottaInstall = $False
}
Expand All @@ -171,8 +167,7 @@ if ($GottaInstall -and !$ExtractProject) {
Write-Verbose -Message "Checking out [$Version] of [$Name] from [$RepoPath]"
Invoke-ExternalCommand git 'checkout', $Version
Pop-Location
}
elseif ($GottaInstall -and $ExtractProject) {
} elseif ($GottaInstall -and $ExtractProject) {
$OutPath = Join-Path ([System.IO.Path]::GetTempPath()) ([guid]::NewGuid().guid)
$RepoFolder = Join-Path -Path $OutPath -ChildPath $GitName

Expand Down
Loading
Loading