Skip to content

Commit

Permalink
Updated pipeline to auto set version (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
Taron-art authored Feb 7, 2025
1 parent ab78072 commit 14dcea7
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 5 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0

# Install the .NET Core workload
- name: Install .NET Core
uses: actions/setup-dotnet@v4
Expand All @@ -32,7 +32,12 @@ jobs:
# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v2


- name: Update version in code
shell: pwsh
run: |
src/updateVersion.ps1 ${{ github.ref_name }}
# Execute all unit tests in the solution
- name: Execute unit tests
run: dotnet test src -c Release -p:Platform=x64
Expand Down
4 changes: 2 additions & 2 deletions src/SolutionInfo.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Reflection;
using System.Runtime.CompilerServices;

[assembly: AssemblyVersion("0.7.0.0")]
[assembly: AssemblyFileVersion("0.7.0.0")]
[assembly: AssemblyVersion("0.0.0")]
[assembly: AssemblyFileVersion("0.0.0")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Processes Priority Manager")]
[assembly: AssemblyCopyright("Copyright © 2025")]
Expand Down
2 changes: 1 addition & 1 deletion src/pm_affinityservice/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pm_affinityservice"
version = "0.7.0"
version = "0.0.0"
edition = "2021"

[package.metadata.winres]
Expand Down
60 changes: 60 additions & 0 deletions src/updateVersion.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
param(
[Parameter(Mandatory=$true, position=0)][string]$version
)
$ErrorActionPreference = "Stop"

function Validate-Version {
param(
[string]$version
)
if ($version -match '^v\d+\.\d+\.\d+$') {
return $true
} else {
return $false
}
}

function Update-SolutionInfo {
param(
[string]$version,
[string]$scriptDir
)
$solutionInfoPath = Join-Path -Path $scriptDir -ChildPath "SolutionInfo.cs"
$content = Get-Content $solutionInfoPath
$content = $content -replace 'AssemblyVersion\(".*"\)', "AssemblyVersion(`"$version`")"
$content = $content -replace 'AssemblyFileVersion\(".*"\)', "AssemblyFileVersion(`"$version`")"
Set-Content -Path $solutionInfoPath -Value $content
}

function Update-CargoToml {
param(
[string]$version,
[string]$scriptDir
)
$cargoTomlPath = Join-Path -Path $scriptDir -ChildPath "Cargo.toml"
$content = Get-Content $cargoTomlPath

$inPackageSection = $false
$newContent = $content | ForEach-Object {
if ($_ -match '^\[package\]') {
$inPackageSection = $true
}
if ($inPackageSection -and $_ -match '^version = ".*"$') {
$_ = "version = `"$version`""
$inPackageSection = $false
}
$_
}
Set-Content -Path $cargoTomlPath -Value $newContent
}

$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path

if (Validate-Version -version $version) {
$versionNumber = $version -replace '^v', ''
Update-SolutionInfo -version $versionNumber -scriptDir $scriptDir
Update-CargoToml -version $versionNumber -scriptDir (Join-Path $scriptDir pm_affinityservice)
Write-Host "Versions updated to $versionNumber"
} else {
throw "Invalid version format. Please use format v1.2.3"
}

0 comments on commit 14dcea7

Please sign in to comment.