Update ZNConnectivityTest.ps1 #48
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Powershell - Update Readme.md | |
on: | |
push: | |
paths: | |
- "**.ps1" | |
pull_request: | |
paths: | |
- "**.ps1" | |
workflow_dispatch: | |
jobs: | |
## Sync repo and build | |
Sync_Repo_and_Build: | |
name: Create folder/files in demo/ | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Github repository | |
uses: actions/checkout@v2 | |
- name: Check to see if documentation.json exists | |
shell: pwsh | |
run: | | |
Add-Type -AssemblyName System.Web | |
$excludedFolders = @('.github') | |
$mainFolders = Get-ChildItem -Directory "./" | Where-Object {$_.Name -notin $excludedFolders} | |
$basePath = "." | |
Get-Content "$($basePath)/.github/templates/header.md" -Encoding UTF8 | Out-File "$($basePath)/README.md" | |
function Add-LineFileInfo { | |
param($readmePath, $file, $relativePath, $prefix = " ") | |
# Check for synopsis | |
if ((Get-Help $file.Fullname).Synopsis) { | |
$description = (Get-Help $file.Fullname).Synopsis | |
$description | |
} else {$description = ""} | |
## Add descriptionf | |
#$encodedURL = [System.Web.HttpUtility]::UrlEncode((Join-Path $relativePath $file.Name)) | |
$encodedURL = "$($relativePath)/$($file.Name)".Replace(' ','%20') | |
Add-Content -Path $readmePath -Value "$($prefix)**[$($file.Name)]($encodedURL)** - $($description)`n" | |
} | |
## iterate through main folders | |
ForEach ($folder in $mainFolders) { | |
$singleScripts = @() | |
Write-Host $folder | |
Add-Content -Path "$($basePath)/README.md" -Value "`n<br>`n`n## $($folder.name)" ## Build headers from main directory | |
$subfolders = Get-ChildItem $folder.FullName -Exclude "images" -Directory | |
#| Where-Object { ((Get-ChildItem $_.FullName -Directory -Exclude "images").Count -gt 0) -or ((Get-ChildItem $_.FullName -Recurse -File -Filter '*.ps1').Count -gt 1) } | |
ForEach ($subfolder in $subfolders) { | |
Write-Host " $($subfolder.Name)" | |
## Check if has other sub folders with more than one script | |
if ((Get-ChildItem $subfolder.FullName -Recurse -File -Filter '*.ps1').Count -gt 1 ) { | |
$files = Get-ChildItem $subfolder.FullName -File -Filter '*.ps1' -Recurse | |
Add-Content -Path "$($basePath)/README.md" -Value "`n<details>`n<summary>$($subfolder.baseName) ($($files.Count))</summary>`n" | |
ForEach ($file in $files) { | |
Write-Host " $($file.Name)" | |
Add-LineFileInfo -readmePath "$($basePath)/README.md" -file $file -relativePath "$($folder)/$($subfolder.BaseName)" -prefix " " | |
} | |
Add-Content -Path "$($basePath)/README.md" -Value "`n</details>`n`n" | |
} | |
## If subfolder only has one script, add it to the others. | |
else { | |
$singleScripts += [PSCustomObject]@{ | |
file = Get-ChildItem $subfolder.FullName -File -Filter '*.ps1' -Recurse | |
relativePath = "$($folder.Name)/$($subfolder.Name)" | |
prefix = $subfolder.Name | |
} | |
} | |
} | |
# add scripts | |
ForEach($script in $singleScripts) { | |
Add-LineFileInfo -readmePath "$($basePath)/README.md" -file $script.file -relativePath $script.relativePath -prefix "<br>$($script.prefix) - " | |
} | |
# if files in current directory | |
if ((Get-ChildItem $folder.FullName -Filter '*.ps1' -File).Count -gt 0) { | |
$files = Get-ChildItem $folder.FullName -Filter '*.ps1' -File | |
ForEach($file in $files) { | |
Write-Host " $($file.Name)" | |
Add-LineFileInfo -readmePath "$($basePath)/README.md" -file $file -relativePath "$($folder.Name)" | |
} | |
} | |
} | |
## Add Contributing body | |
Add-Content "$($basePath)/README.md" -Value (Get-Content "$($basePath)/.github/templates/contributing.md" -Encoding UTF8) | |
## Generate Time | |
Add-Content -Path "$($basePath)/README.md" -Value "`n<br><br>`n![generated_image](https://img.shields.io/badge/generated%20date-$((Get-Date).ToString().Replace(' ','%20'))-blue)" | |
## Configure github user settings | |
- name: Configure Github Settings | |
run: | | |
git config user.name github-actions | |
git config user.email [email protected] | |
## Check for changes prior to pushing | |
- name: Check for changes | |
run: git status | |
## Add files for changes | |
- name: Stage changed files | |
run: git add . | |
## Commit changes | |
- name: Commit changed files | |
run: git commit -m "Updating README.md" | |
## push updates | |
- name: Push changes | |
run: git push |