-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPackage.ps1
More file actions
150 lines (124 loc) · 4.66 KB
/
Copy pathPackage.ps1
File metadata and controls
150 lines (124 loc) · 4.66 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
param(
[Parameter(Mandatory=$false)]
[string]$clean = "true",
[Parameter(Mandatory=$false)]
[string]$pack = "true",
[Parameter(Mandatory=$false)]
[string]$updateVersion = "true",
[Parameter(Mandatory=$false)]
[string]$forcePack = "false",
[Parameter(Mandatory=$false)]
[string]$test = "false",
[Parameter(Mandatory=$false)]
[string]$startingYear = "2024",
[Parameter(Mandatory=$false)]
[string]$specificVersion = $null
)
function Get-Version {
# Calculate the first part of the version
$part1 = [System.Convert]::ToUInt16([System.DateTime]::Now.Year - [System.Int32]::Parse($startingYear))
# Get the second part of the version
$part2 = [System.DateTime]::Now.ToString('yy')
# Get the third part of the version
$part3 = [System.DateTime]::Now.DayOfYear
# Calculate the fourth part of the version
$part4 = [System.Convert]::ToUInt16([System.DateTime]::Now.TimeOfDay.TotalMinutes / 15)
# Combine all parts into a version string
$version = "$part1.$part2.$part3.$part4"
return $version
}
Write-Host "Current path: $PWD"
Set-Location "$PWD"
$version = if ($specificVersion) { $specificVersion } else { Get-Version }
Write-Host "CONFIG: version = $version, clean = $clean, pack = $pack, forcePack = $forcePack, test = $test, startingYear = $startingYear
"
$hasCounts = $false
foreach($projName in "SourceCrafter.DependencyInjection.Tests,Benchmarks".Split(","))
{
Write-Host "[$item]: Project definition update
"
$projPath = "$PWD/$projName/$projName.csproj"
$projContent = [xml]$(Get-Content $projPath)
# Get all 'PackageReference' nodes
$refs = $($projContent).GetElementsByTagName('PackageReference').
Where({
$_.GetAttribute('Include').StartsWith('SourceCrafter.DependencyInjection') -and $_.GetAttribute('Version') -ne $version
})
if($refs.Count -gt 0){
$hasCounts = $true
$refs.Foreach({
Write-Output "
REFERENCE: Updating package: $($_.GetAttribute('Include')) to version $version"
$_.SetAttribute('Version', "[$version]")
Write-Output $_.OuterXml
})
$projContent.Save($projPath)
}
}
if($hasCounts -or $forcePack -eq 'true')
{
Write-Output "
PACKER: Test project references where updated
"
if(-not (Test-Path "$PWD/publish/"))
{
Write-Host "PACKER: Created packaging output folder
"
New-Item -ItemType Directory -Path "$PWD/publish/"
}
if($clean -eq "true")
{
Write-Information "PACKER: Removing packages"
Remove-Item -Path "$PWD/publish/*.*" -recurse
}
if($pack -eq 'true')
{
Write-Output "
PACKER: Initializing...
"
try
{
if(-not (dotnet nuget list source | Select-String -Pattern 'DILocalPackages'))
{
Write-Output '
PACKER: Creating local source "DILocalPackages"...
'
dotnet nuget add source "$PWD/publish" -n DILocalPackages
}
Write-Output '
PACKER: Restoring...
'
dotnet restore
Write-Host "PACKER: Packaging projects
"
dotnet pack $PWD/SourceCrafter.DependencyInjection/SourceCrafter.DependencyInjection.csproj -c Release -v n -p:PackageVersion=$version
dotnet pack $PWD/SourceCrafter.DependencyInjection.Metadata/SourceCrafter.DependencyInjection.Metadata.csproj -c Release -v n -p:PackageVersion=$version
dotnet pack $PWD/SourceCrafter.DependencyInjection.MsConfiguration/SourceCrafter.DependencyInjection.MsConfiguration.csproj -c Release -v n -p:PackageVersion=$version
dotnet pack $PWD/SourceCrafter.DependencyInjection.MsConfiguration.Metadata/SourceCrafter.DependencyInjection.MsConfiguration.Metadata.csproj -c Release -v n -p:PackageVersion=$version
}
catch
{
$exceptionString = $_.Exception.Message + " " + $_.InvocationInfo.PositionMessage
Write-Error $exceptionString
}
}
}
if($test -eq 'true')
{
Write-Output "
PACKER: Testing projects
"
if($pack -ne 'true')
{
if(dotnet nuget list source | Select-String -Pattern 'LocalPackages')
{
dotnet nuget add source $PWD/publish -n DILocalPackages
}
dotnet restore $PWD/SourceCrafter.DependencyInjection.Tests/SourceCrafter.DependencyInjection.Tests.csproj
}
if($clean -eq 'true')
{
dotnet clean $PWD/SourceCrafter.DependencyInjection.Tests/SourceCrafter.DependencyInjection.Tests.csproj -c Release
}
dotnet test $PWD/SourceCrafter.DependencyInjection.Tests/SourceCrafter.DependencyInjection.Tests.csproj -c Release
}