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: 5 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This repository contains a PowerShell module used for documenting life cycle workflows in Entra ID.

All PowerShell code in this repository should be compatible with PowerShell 7.1 or later, and should follow best practices for PowerShell development, including using proper naming conventions, commenting code, and writing unit tests where possible.

The module is published to powershellgallery.com.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
8 changes: 8 additions & 0 deletions .github/release-please-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
"packages": {
".": {
"release-type": "simple"
}
}
}
2 changes: 2 additions & 0 deletions .github/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
releaseType: simple
handleGHRelease: true
1 change: 1 addition & 0 deletions .github/workflows/psscriptanalyzer-expected-results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
63 changes: 63 additions & 0 deletions .github/workflows/psscriptanalyzer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Run PowerShell Script Analyzer

on:
pull_request:

jobs:
build-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
fetch-depth: 2
ref: ${{ github.event.pull_request.head.ref }}
- name: PowerShell Script Analyzer
shell: pwsh
run: |
Install-Module PSScriptAnalyzer -Scope CurrentUser -Force -Confirm:$false
$ExpectedResults = @()
$file = "./.github/workflows/psscriptanalyzer-expected-results.json"
if((Test-Path $file)) {
$ExpectedResults = Get-Content $file | ConvertFrom-Json
} else {
Write-Host "No psscriptanalyzer-expected-results.json file found, assuming no expected results. File: $file"
}

$Results = Get-ChildItem -Recurse -Include *.psd1 |
ForEach-Object {Invoke-ScriptAnalyzer -Path ($_.FullName | Split-Path -Parent) -Recurse -ExcludeRule @(
"PSAvoidTrailingWhitespace"
"PSUseToExportFieldsInManifest"
"PSAvoidUsingWriteHost"
)} |
Where-Object ScriptName -notlike "*.tests.*" # Ignore test files, as these do all kinds of crazy things that trigger warnings

$IssuesFound = $false
$Results |
Where-Object {!($ExpectedResults | Where-Object RuleName -eq $_.RuleName | Where-Object ScriptName -eq $_.ScriptName | Where-Object Line -eq $_.Line)} |
ForEach-Object -Begin {"=================================`nThe following results were found that were not expected, and must either be fixed or added to psscriptanalyzer-expected-results.json:`n"} -Process {
$IssuesFound = $true
"$($PSStyle.Foreground.Yellow)============== " + $_.Severity + " ==============$($PSStyle.Reset)"
$_.ScriptName + " (Line " + $_.Line + "):"
$_.Message
""
"If this issue is acceptable, add the following entry to psscriptanalyzer-expected-results.json:`n"
[ordered] @{RuleName=$_.RuleName; ScriptName=$_.ScriptName; Line=$_.Line} | ConvertTo-Json -Depth 3
""

} -End {}

$ExpectedResults |
Where-Object {!($Results | Where-Object RuleName -eq $_.RuleName | Where-Object ScriptName -eq $_.ScriptName | Where-Object Line -eq $_.Line)} |
ForEach-Object -Begin {"=================================`nThe following results were expected, but not found, and should therefore be removed from psscriptanalyzer-expected-results.json:`n"} -Process {
$IssuesFound = $true
[ordered] @{RuleName=$_.RuleName; ScriptName=$_.ScriptName; Line=$_.Line} | ConvertTo-Json -Depth 3
""
} -End {"================================="}

if($IssuesFound) {
throw "PowerShell Script Analyzer found unexpected results."
}
36 changes: 36 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Publish Module
permissions:
contents: read

on:
push:
tags:
- v*.*.*

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Publish Module to PowerShell Gallery
shell: pwsh
run: |
$psd1 = Get-ChildItem -Recurse -Include *.psd1
$RequiredModules = [ScriptBlock]::Create((Get-Content -Raw $psd1.FullName)).Invoke().RequiredModules
if($RequiredModules) {
$RequiredModules | ForEach-Object {
Write-Host "Installing required module - $($_)"
Install-Module -Name $_ -Force -Confirm:$false
}
}

$psd1 |
ForEach-Object {
Test-ModuleManifest $_.FullName

$ModulePath = Split-Path -Parent $_.FullName
$ModuleName = $_.BaseName
Write-Host "Publishing module $ModuleName"
Publish-Module -Path $ModulePath -NuGetApiKey '${{ secrets.POWERSHELLGALLERY_API_KEY }}' -Verbose
}
106 changes: 106 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: ReleasePlease
on:
repository_dispatch:
types: [create-pull-request]
pull_request:
push:
branches: [ "main" ]

permissions:
pull-requests: write
contents: write

jobs:

update-readme:
if: github.event_name == 'pull_request'
name: Update psd1 and documentation
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
fetch-depth: 2
ref: ${{ github.event.pull_request.head.ref }}
- name: Update documentation.md and psd1 version
shell: pwsh
run: |
$Path = ".\Documentation.md"

# Load platyPS module for generating markdown documentation
Install-Module platyPS -Scope CurrentUser -Confirm:$false -Force
Import-Module platyPS

# Locate the module manifest file
$psd1 = Get-ChildItem -Recurse -Include *.psd1
$count = ($psd1 | Measure-Object).Count
if($count -ne 1) {
Write-Error "Wrong number of psd1 files found ($count)"
exit 1
}

# Import the module
$RequiredModules = [ScriptBlock]::Create((Get-Content -Raw $psd1.FullName)).Invoke().RequiredModules
if($RequiredModules) {
$RequiredModules | ForEach-Object {
Write-Host "Installing required module $_"
Install-Module -Name $_ -Scope CurrentUser -Confirm:$false -Force
}
}
$ModulePath = $psd1.FullName | Split-Path -Parent
$Module = Import-Module $ModulePath -Verbose -Force -PassThru

# Update the psd1 file with the release-please version and public cmdlets
$releasePleaseVersion = $null
if((Test-Path ".release-please-manifest.json")) {
$releasePleaseVersion = (Get-Content ".release-please-manifest.json" | ConvertFrom-Json -AsHashTable)."."
if($releasePleaseVersion -notlike "*.*.*") {
Write-Error "Invalid release-please version '($releasePleaseVersion)' found"
exit 1
}

# Replace the ModuleVersion line in the psd1 file
(Get-Content $psd1.FullName |
ForEach-Object {if($_ -like "*ModuleVersion*=*"){" ModuleVersion = '$releasePleaseVersion'"} else {$_}} |
ForEach-Object {if($_ -like "*CmdletsToExport*'`*'*" -or $_ -like "*CmdletsToExport*@(*)*"){" CmdletsToExport = @('{0}')" -f ($module.ExportedFunctions.Keys -join "','")} else {$_}} |
Out-String).Trim() |
Set-Content $psd1.FullName
}

# Generate README.md
{
"# Documentation for module $($Module.Name)"
""
$Module.Description
""
"| Metadata | Information |"
"| --- | --- |"
"| Version | {0} |" -f ($releasePleaseVersion ?? $Module.Version)
if($Module.RequiredModules) {"| Required modules | $($Module.RequiredModules) |"}
if($Module.Author) {"| Author | $($Module.Author) |"}
if($Module.CompanyName) {"| Company name | $($Module.CompanyName) |"}
if($Module.PowerShellVersion) {"| PowerShell version | $($Module.PowerShellVersion) |"}
""

New-MarkdownHelp -Module $Module.Name -OutputFolder "$($ENV:RUNNER_TEMP)/generateddocs" -Force -NoMetadata |
Get-Content |
ForEach-Object {$_ -replace "^#","##"} |
ForEach-Object {$_ -replace "{{ Fill [\w\s]+ Description }}"}
}.Invoke() | Out-File -FilePath $Path -Encoding utf8 -Force
- name: Push back to PR
shell: pwsh
run: |
# Commit and push the changes back to the PR
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git add --all
git commit --signoff -m "chore: Update generated content"
git push origin ${{ github.event.pull_request.head.ref }}
release-please:
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- uses: googleapis/release-please-action@16a9c90856f42705d54a6fda1823352bdc62cf38 # v4.4.0
with:
token: ${{ secrets.POSTMAN_PAT }}
config-file: .github/release-please-config.json
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
LifecycleWorkflowsReport.md
3 changes: 3 additions & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
".": "0.0.1"
}
78 changes: 78 additions & 0 deletions Documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Documentation for module LCWMermaidGenerator

A module for simplifying the process of getting an access token from Entra ID

| Metadata | Information |
| --- | --- |
| Version | 0.0.1 |
| Author | Marius Solbakken Mellum |
| Company name | Fortytwo Technologies AS |
| PowerShell version | 7.1 |

## Invoke-LCWMermaidGenerator

### SYNOPSIS
{{ Fill in the Synopsis }}

### SYNTAX

```
Invoke-LCWMermaidGenerator [[-ReportPath] <String>] [-ProgressAction <ActionPreference>] [<CommonParameters>]
```

### DESCRIPTION


### EXAMPLES

#### Example 1
```powershell
PS C:\> {{ Add example code here }}
```

{{ Add example description here }}

### PARAMETERS

#### -ReportPath


```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 0
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

#### -ProgressAction


```yaml
Type: ActionPreference
Parameter Sets: (All)
Aliases: proga

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

#### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).

### INPUTS

#### None
### OUTPUTS

#### System.Object
### NOTES

### RELATED LINKS
3 changes: 3 additions & 0 deletions Example.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Import-Module "./LCWMermaidGenerator" -Force

Invoke-LCWMermaidGenerator
Loading