Skip to content

Commit

Permalink
Centralize the project's version too
Browse files Browse the repository at this point in the history
  • Loading branch information
andyleejordan committed Sep 26, 2024
1 parent 9699f9f commit efb0b3e
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 211 deletions.
4 changes: 2 additions & 2 deletions .pipelines/PSScriptAnalyzer-Official.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ extends:
ob_outputDirectory: $(Build.SourcesDirectory)/out
steps:
- pwsh: |
[xml]$xml = Get-Content Engine/Engine.csproj
$version = $xml.SelectSingleNode(".//VersionPrefix")."#text"
[xml]$xml = Get-Content ./Directory.Build.props
$version = $xml.Project.PropertyGroup.ModuleVersion
Write-Output "##vso[task.setvariable variable=version;isOutput=true]$version"
name: package
displayName: Get version from project properties
Expand Down
2 changes: 2 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<Project>
<!-- See https://aka.ms/dotnet/msbuild/customize for more details on customizing your build -->
<PropertyGroup>
<ModuleVersion>1.22.0</ModuleVersion>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
</Project>
4 changes: 2 additions & 2 deletions Engine/Engine.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<VersionPrefix>1.22.0</VersionPrefix>
<VersionPrefix>$(ModuleVersion)</VersionPrefix>
<TargetFrameworks>net6;net462</TargetFrameworks>
<AssemblyName>Microsoft.Windows.PowerShell.ScriptAnalyzer</AssemblyName>
<AssemblyVersion>1.22.0</AssemblyVersion>
<AssemblyVersion>$(ModuleVersion)</AssemblyVersion>
<PackageId>Engine</PackageId>
<RootNamespace>Microsoft.Windows.PowerShell.ScriptAnalyzer</RootNamespace> <!-- Namespace needs to match Assembly name for ressource binding -->
<LangVersion>9.0</LangVersion>
Expand Down
2 changes: 1 addition & 1 deletion Engine/PSScriptAnalyzer.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Author = 'Microsoft Corporation'
RootModule = 'PSScriptAnalyzer.psm1'

# Version number of this module.
ModuleVersion = '1.22.0'
ModuleVersion = '{{ModuleVersion}}'

# ID used to uniquely identify this module
GUID = 'd6245802-193d-4068-a631-8863a4342a18'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<VersionPrefix>1.22.0</VersionPrefix>
<VersionPrefix>$(ModuleVersion)</VersionPrefix>
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>
<AssemblyVersion>1.22.0</AssemblyVersion>
<AssemblyVersion>$(ModuleVersion)</AssemblyVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
Expand Down
4 changes: 2 additions & 2 deletions Rules/Rules.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<VersionPrefix>1.22.0</VersionPrefix>
<VersionPrefix>$(ModuleVersion)</VersionPrefix>
<TargetFrameworks>net6;net462</TargetFrameworks>
<AssemblyName>Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules</AssemblyName>
<AssemblyVersion>1.22.0</AssemblyVersion>
<AssemblyVersion>$(ModuleVersion)</AssemblyVersion>
<PackageId>Rules</PackageId>
<RootNamespace>Microsoft.Windows.PowerShell.ScriptAnalyzer</RootNamespace> <!-- Namespace needs to match Assembly name for ressource binding -->
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> <!-- Needed in order for Pluralize.NET DLL to appear in bin folder - https://github.com/NuGet/Home/issues/4488 -->
Expand Down
198 changes: 0 additions & 198 deletions Utils/ReleaseMaker.psm1

This file was deleted.

14 changes: 10 additions & 4 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ $analyzerName = "PSScriptAnalyzer"

function Get-AnalyzerVersion
{
[xml]$xml = Get-Content $([io.path]::Combine($projectRoot,"Engine","Engine.csproj"))
$xml.SelectSingleNode(".//VersionPrefix")."#text"
[xml]$xml = Get-Content $([io.path]::Combine($projectRoot, "Directory.Build.props"))
$xml.Project.PropertyGroup.ModuleVersion
}

$analyzerVersion = Get-AnalyzerVersion
Expand Down Expand Up @@ -159,9 +159,15 @@ function Start-ScriptAnalyzerBuild
throw "Not in solution root"
}

# "Copy" the module file with the version placeholder replaced
$manifestContent = Get-Content -LiteralPath "$projectRoot\Engine\PSScriptAnalyzer.psd1" -Raw
$newManifestContent = $manifestContent -replace '{{ModuleVersion}}', $analyzerVersion
Set-Content -LiteralPath "$script:destinationDir\PSScriptAnalyzer.psd1" -Encoding utf8 -Value $newManifestContent

$itemsToCopyCommon = @(
"$projectRoot\Engine\PSScriptAnalyzer.psd1", "$projectRoot\Engine\PSScriptAnalyzer.psm1",
"$projectRoot\Engine\ScriptAnalyzer.format.ps1xml", "$projectRoot\Engine\ScriptAnalyzer.types.ps1xml"
"$projectRoot\Engine\PSScriptAnalyzer.psm1",
"$projectRoot\Engine\ScriptAnalyzer.format.ps1xml",
"$projectRoot\Engine\ScriptAnalyzer.types.ps1xml"
)

switch ($PSVersion)
Expand Down
24 changes: 24 additions & 0 deletions tools/updateVersion.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

param(
[Parameter(Mandatory)]
[semver]$Version,

[Parameter(Mandatory)]
[string]$Changes
)

git diff --staged --quiet --exit-code
if ($LASTEXITCODE -ne 0) {
throw "There are staged changes in the repository. Please commit or reset them before running this script."
}

$Path = "Directory.Build.props"
$f = Get-Content -Path $Path
$f = $f -replace '^(?<prefix>\s+<ModuleVersion>)(.+)(?<suffix></ModuleVersion>)$', "`${prefix}${Version}`${suffix}"
$f | Set-Content -Path $Path
git add $Path

git commit --edit --message v${Version}: $Changes"
"

0 comments on commit efb0b3e

Please sign in to comment.