-
Notifications
You must be signed in to change notification settings - Fork 7
/
update-readme-summary-table.ps1
executable file
·165 lines (130 loc) · 5.4 KB
/
update-readme-summary-table.ps1
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<# Workspace ONE Script Importer
.SYNOPSIS
This Powershell script builds the index tables that feeds into the https://developer.omnissa.com portal
.NOTES
Created: August, 2024
Created by: Richard Croft
Contributors: Phil Helmling
Organization: Omnissa, LLC
Github: https://github.com/euc-oss/euc-samples
.DESCRIPTION
This script builds the index tables that feeds into the https://developer.omnissa.com portal. The tables are written as Markdown into the /docs folder. There is one table per area:
* Access-Samples
* Android-Samples
* App-Volumes-Samples
* Horizon-Samples
* Intelligence-Samples
* UAG-Samples
* UEM-Samples
* UEM-Samples/Scripts
* UEM-Samples/Sensors
#>
function Get-TextBetweenTwoStrings ([string]$startPattern, [string]$endPattern, [string]$filePath){
# Get content from the input file
$fileContent = Get-Content -Path $filePath -Raw
# Regular expression (Regex) of the given start and end patterns
$pattern = '(?is){0}(.*?){1}' -f [regex]::Escape($startPattern), [regex]::Escape($endPattern)
# Perform the Regex operation and output
return [regex]::Match($fileContent,$pattern).Groups[1].Value.ToString()
}
function Get-Description ([string]$filePath){
$fileContent = Get-Content -Path $filePath
$d = $fileContent | Select-String -Pattern 'Description: ' -Raw -ErrorAction SilentlyContinue
if($d){$description = $d.Substring($d.LastIndexOf('Description: ')+13) -replace '[#]' -replace '"',"" -replace "'",""}else{$Description = $null}
return $description
}
function ReplaceMarkdownTableContent {
param(
[string]$filePath,
[string[]]$tableData
)
$newContent = $null
$content = Get-Content $filePath
$index = ($content | Select-String -Pattern "\| --- \| --- \| ---:\|").LineNumber
if ($index) {
$newContent = $content[0..($index - 1)]
$newContent += $tableData | ForEach-Object { $_ }
Set-Content $filePath -Value $newContent
} else {
Write-Warning "Pattern '| --- | --- | ---:|' not found in the file {0}." -f $filePath
}
}
function ReplaceScriptSensorMarkdownTableContent {
param(
[string]$filePath,
[string[]]$tableData
)
$newContent = $null
$content = Get-Content $filePath
$index = ($content | Select-String -Pattern "\| --- \| --- \| --- \| ---:\|").LineNumber
if ($index) {
$newContent = $content[0..($index - 1)]
$newContent += $tableData | ForEach-Object { $_ }
Set-Content $filePath -Value $newContent
} else {
Write-Warning "Pattern '| --- | --- | --- | ---:|' not found in the file {0}." -f $filePath
}
}
$current_path = (Get-Location).Path
$repo = "https://github.com/euc-oss/euc-samples"
$repopath = "$repo/tree/main"
function updateMainIndexes {
$paths = @("Access-Samples",
"Android-Samples",
"App-Volumes-Samples",
"Horizon-Samples",
"Intelligence-Samples",
"UAG-Samples",
"UEM-Samples")
$startPattern = '<!-- Summary Start -->'
$endPattern = '<!-- Summary End -->'
# find README.md files under each sample directory
foreach ($p in $paths) {
$results = @()
$files = Get-ChildItem -Path $p -Recurse -Include 'readme.md' -File
foreach ($f in $files) {
#Write-Host("Working on $f") -ForegroundColor Green
$match = Get-TextBetweenTwoStrings -startPattern $startPattern -endPattern $endPattern -filePath $f.FullName
$summary = $match.Trim()
$fulldirname = $f.DirectoryName
$newpath = $fulldirname.Replace($current_path,"")
$dirname = $f.Directory.Name
$URI = $repopath,$newpath -join ""
$link = [uri]::EscapeUriString($URI)
$results += "| $dirname | $summary | [Link]($link) |"
}
#Write the results to the index file after the table header, replacing everything previous
$docpath = "docs/$p/index.md"
$file = Get-ChildItem -Path $docpath
ReplaceMarkdownTableContent $file $results
}
}
function updateSensorScriptIndexes {
$paths = @("Scripts",
"Sensors")
# find README.md files under each sample directory
foreach ($p in $paths) {
$results = @()
$ExcludedTemplates = "import_script_samples|template*|import_sensor_samples|get_enrollment_sid_32_64|check_matching_sid_sensor|readme|README"
$files = Get-ChildItem -Path "UEM-Samples/$p" -Recurse -File | Where-Object Name -NotMatch $ExcludedTemplates
foreach ($f in $files) {
$match = Get-Description -filePath $f.FullName
$summary = $match.Trim()
$fname = $f.Name
$fullName = $f.FullName
$dirname = $f.Directory.Name
$newpath = $fullName.Replace($current_path,"")
$URI = $repopath,$newpath -join ""
$link = [uri]::EscapeUriString($URI)
$results += "| $dirname | $fname | $summary | [$fname]($link) |"
}
#Write the results to the index file after the table header, replacing everything previous
$docpath = "docs/UEM-Samples/$p-index.md"
$file = Get-ChildItem -Path $docpath
ReplaceScriptSensorMarkdownTableContent $file $results
}
}
# Update main indexes
updateMainIndexes
# Update Scripts and Sensor indexes
updateSensorScriptIndexes