Skip to content

Commit

Permalink
Merge pull request #9 from chris-peterson/auto-discover-modules
Browse files Browse the repository at this point in the history
Make module path optional
  • Loading branch information
pcgeek86 authored Aug 17, 2021
2 parents 99981d1 + 006dac0 commit 9c3349b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ For example, if you named your secret `PS_GALLERY_KEY`:

```
- name: Publish Module to PowerShell Gallery
uses: pcgeek86/publish-powershell-module-action@v19
uses: pcgeek86/publish-powershell-module-action@v20
id: publish-module
with:
modulePath: YOURMODULENAME
NuGetApiKey: ${{ secrets.PS_GALLERY_KEY }}
```

## Assumptions

* You're writing a PowerShell script module (not a compiled module)
* Your module is contained within a subfolder of your GitHub repository
* Your module manifest's name is consistent with its parent directory
6 changes: 3 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: Publish PowerShell Module
description: Publishes a PowerShell module to the PowerShell Gallery.
inputs:
modulePath:
description: The filesystem path to the module to import into the environment.
required: true
NuGetApiKey:
description: The NuGet API Key for PowerShell Gallery, with permission to push this module.
required: true
modulePath:
description: The filesystem path to the module to publish. If not provided, all directories that contains a .psd1 are published.
required: false
outputs:
successfullyPublished: # id of output
description: Whether or not the publish command was successful
Expand Down
16 changes: 13 additions & 3 deletions entrypoint.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
#!/usr/bin/env pwsh
$ErrorActionPreference = 'Stop'

Write-Host "Publishing module ($env:INPUT_MODULEPATH) to PowerShell Gallery"
$Modules = $null
if ([string]::IsNullOrWhiteSpace($env:INPUT_MODULEPATH)) {
$Modules = Get-ChildItem -Recurse -Filter '*.psd1' |
Select-Object -Unique -ExpandProperty Directory
} else {
$Modules = @($env:INPUT_MODULEPATH)
}

Publish-Module -Path $env:INPUT_MODULEPATH -NuGetApiKey $env:INPUT_NUGETAPIKEY
Write-Host 'Finished publishing module to PowerShell Gallery'
$Modules | ForEach-Object {
Write-Host "Publishing '$_' to PowerShell Gallery"

Publish-Module -Path $_ -NuGetApiKey $env:INPUT_NUGETAPIKEY
Write-Host "'$_' published to PowerShell Gallery"
}

0 comments on commit 9c3349b

Please sign in to comment.