-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetprojectversion.ps1
More file actions
71 lines (63 loc) · 2.05 KB
/
getprojectversion.ps1
File metadata and controls
71 lines (63 loc) · 2.05 KB
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
param (
[string]$Filename
)
try
{
$ErrorActionPreference = 'Stop';
$Error.Clear();
$verbose = $env:VERBOSE
$runnerPath = $env:GITHUB_WORKSPACE
# Search for the file recursively within the runner path
$File = Get-ChildItem -Path $runnerPath -Recurse -Filter $Filename -File | Select-Object -First 1
if ($verbose.ToLower() -eq 'verbose')
{
Write-Host "GetProjectVersion DEBUG"
Write-Host "Filename : $($Filename)"
Write-Host "RunnerPath : $($runnerPath)"
Write-Host "SourcePath : $($File.FullName)"
Write-Host "-----------------------------"
(Get-ChildItem -Path $runnerPath -Recurse).FullName
Write-Host "-----------------------------"
}
if (-not $File)
{
throw "File '$Filename' not found in $runnerPath"
}
switch ($File.Extension)
{
{ $_ -in '.csproj', '.props' }
{
$Project = [xml](Get-Content -Path $File.FullName);
if (($Project.SelectSingleNode('//PropertyGroup/Version')?.InnerText)?.Trim())
{
$Version = $Project.SelectSingleNode('//PropertyGroup/Version').InnerText.Trim()
}
else
{
$Version = $Project.SelectSingleNode('//PropertyGroup/VersionPrefix').InnerText.Trim()
}
}
'.psd1'
{
$Manifest = Test-ModuleManifest -Path $File.FullName -ErrorAction SilentlyContinue
$Version = $Manifest.Version.ToString()
}
default
{
throw "The extension, $($File.Extension) is not currently a supported type, please create an issue to address this"
}
}
if ($verbose.ToLower() -eq 'verbose')
{
Write-Host "Extension : $($File.Extension)"
Write-Host "Version : $($Version)"
}
# Set the output using environment files
$envFile = [System.IO.Path]::Combine($env:GITHUB_ENV)
Add-Content -Path $envFile -Value "VERSION=$Version"
}
catch
{
$_.InvocationInfo | Out-String
throw $_.Exception.Message;
}