@@ -209,6 +209,48 @@ function Get-Version {
209209 }
210210}
211211
212+ <#
213+ . SYNOPSIS
214+ Validates the given version string.
215+ #>
216+ function Test-VersionIsValid {
217+ param (
218+ [Parameter (Mandatory )]
219+ [ValidateSet ([RepoNames ])]
220+ [string ]$RepositoryName ,
221+
222+ [Parameter (Mandatory )]
223+ [string ]$Version
224+ )
225+ if (! $Version.StartsWith (" v" )) {
226+ throw " Version should start with 'v' prefix!"
227+ }
228+
229+ $SemanticVersion = [semver ]$Version.Substring (1 )
230+ switch ($RepositoryName ) {
231+ " vscode-powershell" {
232+ $Date = Get-Date
233+ if ($SemanticVersion.Major -ne $Date.Year ) {
234+ throw " Major version should be the current year!"
235+ }
236+ if ($SemanticVersion.Minor -ne $Date.Month ) {
237+ throw " Minor version should be the current month!"
238+ }
239+ if ($SemanticVersion.PreReleaseLabel ) {
240+ if ($SemanticVersion.PreReleaseLabel -ne " preview" ) {
241+ throw " Suffix should only be 'preview'!"
242+ }
243+ }
244+ }
245+ " PowerShellEditorServices" {
246+ if ($SemanticVersion.PreReleaseLabel ) {
247+ throw " Version shouldn't have a pre-release label!"
248+ }
249+ }
250+ }
251+ return $true
252+ }
253+
212254<#
213255. SYNOPSIS
214256 Updates the CHANGELOG file with PRs merged since the last release.
@@ -224,9 +266,8 @@ function Update-Changelog {
224266 [ValidateSet ([RepoNames ])]
225267 [string ]$RepositoryName ,
226268
227- # TODO: Validate version style for each repo.
228269 [Parameter (Mandatory )]
229- [ValidateScript ({ $_ .StartsWith ( " v " ) })]
270+ [ValidateScript ({ Test-VersionIsValid - RepositoryName $RepositoryName - Version $_ })]
230271 [string ]$Version
231272 )
232273
0 commit comments