forked from Sitecore/docker-images
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Update-Documentation.ps1
76 lines (61 loc) · 3.37 KB
/
Update-Documentation.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
$ErrorActionPreference = "STOP"
$ProgressPreference = "SilentlyContinue"
Import-Module (Join-Path $PSScriptRoot "\modules\SitecoreImageBuilder") -Force
function Update-Section
{
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[ValidateScript( { Test-Path $_ -PathType "Leaf" })]
[string]$Path
,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$Name
,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$Content
)
$targetContent = Get-Content -Path $Path
$sectionStart = "[//]: # `"start: {0}`"" -f $Name
$sectionEnd = "[//]: # `"end: {0}`"" -f $Name
$start = $targetContent | Select-String -SimpleMatch $sectionStart | Select-Object -ExpandProperty LineNumber
$end = $targetContent | Select-String -SimpleMatch $sectionEnd | Select-Object -ExpandProperty LineNumber
if ($null -eq $start)
{
throw ("Could not find start section '{0}' in '{1}'." -f $sectionStart, $Path)
}
if ($null -eq $end)
{
throw ("Could not find end section '{0}' in '{1}'." -f $sectionEnd, $Path)
}
$before = $targetContent | Select-Object -First $start
$body = "`r`n{0}" -f $Content
$after = $targetContent | Select-Object -Skip ($end - 1)
$before, $body, $after | Out-File -FilePath $Path -Force
}
$specs = @()
(Get-Item (Join-Path $PSScriptRoot "\windows")), (Get-Item (Join-Path $PSScriptRoot "\linux")) | ForEach-Object {
$specs += SitecoreImageBuilder\Get-BuildSpecifications -Path $_.Fullname
Update-Section `
-Path (Join-Path $PSScriptRoot "\IMAGES.md") `
-Name ("current {0}" -f $_.BaseName) `
-Content ((SitecoreImageBuilder\Get-CurrentImagesMarkdown -Path $_.Fullname) | Out-String)
}
$dockerFileCount = $specs | Select-Object -Property DockerFilePath -Unique | Measure-Object | Select-Object -ExpandProperty Count
$tagCount = $specs | Select-Object -Property Tag -Unique | Measure-Object | Select-Object -ExpandProperty Count
$repositoryCount = ( $specs | Foreach-Object { Write-Output (($_.Tag -split ":") | Select-Object -First 1) } | Select-Object -Unique).Count
$deprecatedCount = $specs | Where-Object { $_.Deprecated } | Select-Object -Property Tag -Unique | Measure-Object | Select-Object -ExpandProperty Count
$defaultVersion = (SitecoreImageBuilder\Get-LatestSupportedVersion)
$style = "flat-square"
$stats = ("[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg?style={0})](https://opensource.org/licenses/MIT)" -f $style)
$stats += (" ![{0}](https://img.shields.io/badge/{0}-{1}-{2}.svg?style={3})" -f "Repositories", $repositoryCount, "blue", $style)
$stats += (" ![{0}](https://img.shields.io/badge/{0}-{1}-{2}.svg?style={3})" -f "Tags", $tagCount, "blue", $style)
$stats += (" ![{0}](https://img.shields.io/badge/{0}-{1}-{2}.svg?style={3})" -f "Deprecated", $deprecatedCount, "lightgrey", $style)
$stats += (" ![{0}](https://img.shields.io/badge/{0}-{1}-{2}.svg?style={3})" -f "Dockerfiles", $dockerFileCount, "blue", $style)
$stats += (" ![{0}](https://img.shields.io/badge/Default%20version-{1}%20on%20{2}/{3}-blue?style=flat-square)`n" -f "Default version", $defaultVersion.Sitecore, $defaultVersion.WindowsServerCore, $defaultVersion.NanoServer, "blue", $style)
Update-Section `
-Path (Join-Path $PSScriptRoot "\README.md") `
-Name "stats" `
-Content $stats