-
Notifications
You must be signed in to change notification settings - Fork 221
Expand file tree
/
Copy pathWriteToModuleReadMe.ps1
More file actions
23 lines (22 loc) · 1.08 KB
/
WriteToModuleReadMe.ps1
File metadata and controls
23 lines (22 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string] $ReadMePath,
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string] $FieldName,
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string] $NewFieldValue
)
$ErrorActionPreference = "Stop"
# Read readme.md.
$ReadMeContent = Get-Content $ReadMePath -Delimiter "### Versioning"
if ($ReadMeContent.Length -eq 2) {
# Convert versioning section to yaml.
$UpdatedVersionSection = "### Versioning" + $ReadMeContent[1]
$VersioningSection = $ReadMeContent[1].Replace("``", "").Replace("yaml", "") | ConvertFrom-Yaml
$FieldValue = $VersioningSection[$FieldName]
$RegexPattern = "$FieldName`:\s*$FieldValue"
$UpdatedVersionSection = $UpdatedVersionSection -replace $RegexPattern, "$FieldName`: $NewFieldValue"
$ReadMeContent[0] = $ReadMeContent[0].Trim()
$ReadMeContent[1] = $UpdatedVersionSection.Trim()
Set-Content -Path $ReadMePath -Value $ReadMeContent
}