Skip to content

Commit 5358498

Browse files
feat: add Initialize-PSModule action with README and main script
1 parent d5b1020 commit 5358498

3 files changed

Lines changed: 167 additions & 0 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Initialize-PSModule
2+
3+
An action that is used to prepare the runner for PSModule framework.
4+
5+
This GitHub Action is a part of the [PSModule framework](https://github.com/PSModule). It is recommended to use the [Process-PSModule workflow](https://github.com/PSModule/Process-PSModule) to automate the whole process of managing the PowerShell module.
6+
7+
## Specifications and practices
8+
9+
Initialize-PSModule follows:
10+
11+
- [SemVer 2.0.0 specifications](https://semver.org)
12+
- [GitHub Flow specifications](https://docs.github.com/en/get-started/using-github/github-flow)
13+
- [Continuous Delivery practices](https://en.wikipedia.org/wiki/Continuous_delivery)
14+
15+
... and supports the following practices in the PSModule framework:
16+
17+
- [DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself)
18+
19+
## How it works
20+
21+
The Initialize-PSModule action will prepare the runner for the PSModule framework by installing the following dependencies:
22+
23+
| Module | Description |
24+
| --- | --- |
25+
| GitHub | Used to interact with the GitHub API and GitHub Action workflow commands. |
26+
| PSScriptAnalyzer | Used to lint and format PowerShell code. |
27+
| PSSemVer | Used to create an object for the semantic version numbers. Has functionality to compare, and bump versions. |
28+
| Pester | Used for testing PowerShell code. |
29+
| Utilities | Used by all actions, contains common function and classes. |
30+
| platyPS | Used to generate Markdown documentation from PowerShell code. |
31+
| powershell-yaml | Used to parse and serialize YAML files, typically for reading configuration files. |
32+
33+
## Usage
34+
35+
### Inputs
36+
37+
| Name | Description | Required | Default |
38+
| - | - | - | - |
39+
| `Debug` | Enable debug output. | `false` | `'false'` |
40+
| `Verbose` | Enable verbose output. | `false` | `'false'` |
41+
| `Version` | Specifies the version of the GitHub module to be installed. Accepts an exact version or a NuGet version range (for example '[1.2.0, 2.0.0)'). | `false` | |
42+
| `Prerelease` | Allow prerelease versions if available. | `false` | `'false'` |
43+
| `WorkingDirectory` | The working directory where the script runs. | `false` | `${{ github.workspace }}` |
44+
45+
## Example
46+
47+
The action can be used in a workflow to prepare the runner for the PSModule framework by adding it at the start of the workflow.
48+
49+
```yaml
50+
name: Process-PSModule
51+
52+
on: [push]
53+
54+
jobs:
55+
Process-PSModule:
56+
name: Process module
57+
runs-on: ubuntu-latest
58+
steps:
59+
- name: Checkout Code
60+
uses: actions/checkout@v4
61+
62+
- name: Initialize environment
63+
uses: PSModule/Initialize-PSModule@main
64+
```
65+
66+
## Permissions
67+
68+
The action does not require any permissions.
69+
70+
## Compatibility
71+
72+
The action is compatible with the following configurations:
73+
74+
| OS | Shell |
75+
| --- | --- |
76+
| windows-latest | pwsh |
77+
| macos-latest | pwsh |
78+
| ubuntu-latest | pwsh |
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Initialize-PSModule (by PSModule)
2+
description: Prepare runner for the PSModule framework.
3+
author: PSModule
4+
branding:
5+
icon: loader
6+
color: gray-dark
7+
8+
inputs:
9+
Debug:
10+
description: Enable debug output.
11+
required: false
12+
default: 'false'
13+
Verbose:
14+
description: Enable verbose output.
15+
required: false
16+
default: 'false'
17+
Version:
18+
description: Specifies the version of the GitHub module to be installed. Accepts an exact version or a NuGet version range (for example '[1.2.0, 2.0.0)').
19+
required: false
20+
Prerelease:
21+
description: Allow prerelease versions if available.
22+
required: false
23+
default: 'false'
24+
WorkingDirectory:
25+
description: The working directory where the script will run from.
26+
required: false
27+
default: ${{ github.workspace }}
28+
29+
runs:
30+
using: composite
31+
steps:
32+
- name: Initialize-PSModule
33+
uses: PSModule/GitHub-Script@8083ec1f733f00357ee4d0db0c6056686e483bc0 # v1.9.0
34+
with:
35+
Debug: ${{ inputs.Debug }}
36+
Prerelease: ${{ inputs.Prerelease }}
37+
Verbose: ${{ inputs.Verbose }}
38+
Version: ${{ inputs.Version }}
39+
WorkingDirectory: ${{ inputs.WorkingDirectory }}
40+
Script: |
41+
# Initialize-PSModule
42+
${{ github.action_path }}/src/main.ps1
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#Requires -Modules GitHub
2+
3+
[CmdletBinding()]
4+
param()
5+
6+
$requiredModules = @{
7+
Utilities = @{}
8+
Retry = @{}
9+
'powershell-yaml' = @{}
10+
PSSemVer = @{}
11+
Pester = @{}
12+
PSScriptAnalyzer = @{}
13+
PlatyPS = @{}
14+
MarkdownPS = @{}
15+
Hashtable = @{}
16+
# 'Microsoft.PowerShell.PlatyPS' = @{
17+
# Prerelease = $true
18+
# }
19+
}
20+
21+
$requiredModules.GetEnumerator() | Sort-Object | ForEach-Object {
22+
$name = $_.Key
23+
$settings = $_.Value
24+
LogGroup "Installing prerequisite: [$name]" {
25+
$Count = 5
26+
$Delay = 10
27+
for ($i = 1; $i -le $Count; $i++) {
28+
try {
29+
Install-PSResource -Name $name -TrustRepository -Repository PSGallery @settings
30+
break
31+
} catch {
32+
if ($i -eq $Count) {
33+
throw $_
34+
}
35+
Start-Sleep -Seconds $Delay
36+
}
37+
}
38+
Write-Output "Installed module: [$name]"
39+
Get-PSResource -Name $name | Select-Object * | Out-String
40+
41+
Write-Output 'Module commands:'
42+
Get-Command -Module $name | Out-String
43+
}
44+
}
45+
46+
Get-InstalledPSResource -Verbose:$false | Sort-Object -Property Name |
47+
Format-Table -Property Name, Version, Prerelease, Repository -AutoSize | Out-String

0 commit comments

Comments
 (0)