-
Notifications
You must be signed in to change notification settings - Fork 0
97 lines (87 loc) · 3.72 KB
/
Copy pathrelease-please.yml
File metadata and controls
97 lines (87 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
with:
fetch-depth: 2
ref: ${{ github.event.pull_request.head.ref }}
- name: Update readme.md and psd1 version
shell: pwsh
run: |
$Path = ".\README.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
}
# Update the psd1 file with the release-please version
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 {$_}} |
Out-String).Trim() |
Set-Content $psd1.FullName
}
# Import the module
$ModulePath = $psd1.FullName | Split-Path -Parent
$Module = Import-Module $ModulePath -Verbose -Force -PassThru
# Generate README.md
{
"# Documentation for module $($Module.Name)"
""
$Module.Description
""
"| Metadata | Information |"
"| --- | --- |"
"| Version | $($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 -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@a37ac6e4f6449ce8b3f7607e4d97d0146028dc0b # v4.1.0
with:
token: ${{ secrets.PAT }}
release-type: simple