-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
bump-system-dependencies.ps1
90 lines (69 loc) · 2.04 KB
/
bump-system-dependencies.ps1
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
# Update one project packages
function UpdatePackages {
param (
$project
)
$currentDirectoy = Get-Location
$return = $false
$dir = Split-Path $project
Write-Host 'Set-Location' $dir
Set-Location $dir
# Get outdated packages
$packageLineList = dotnet list package --outdated --include-prerelease
foreach($line in $packageLineList) {
Write-Host $line
$match = $line -match '>\s(System.\S*)\s*\S*\s*\S*\s*(\S*)'
if (!$match) {
# the line doesn't contain a package information, continue
continue
}
# update an outdated package
$added = dotnet add package $Matches.1 --version $Matches.2
Write-Host $Matches.1 'version' $Matches.2 $added
if ($LASTEXITCODE -ne 0) {
# error while updating the package
Write-Error "dotnet add $project package $Matches.1 --version $Matches.2 exit with code $LASTEXITCODE"
Write-Host $added
break
}
$return = $true
}
Set-Location $currentDirectoy
return $return
}
# get branches names
$dest = "master"
if (Test-Path env:DEST_BRANCH) {
$dest = $env:DEST_BRANCH
}
$src = "fix/dependencies"
if (Test-Path env:SRC_BRANCH) {
$src = $env:SRC_BRANCH
}
Write-Host "src:$src dest: $dest"
# Restore dependencies
dotnet restore
# Get all project list in the solution
$projectList = dotnet sln list
$updated = $false
foreach($path in $projectList) {
if ($path -eq "Project(s)" -or $path -eq "----------") {
# The line doesn't contain a path, continue
continue
}
# Update project dependencies
$projectUpdated = UpdatePackages -project $path
if ($LASTEXITCODE -ne 0) {
#The update fail, exit
exit $LASTEXITCODE
}
$updated = $updated -or $projectUpdated
}
if (!$updated) {
# No packages to update found, exit
Write-Host "nothing to update"
exit 0
}
# Try build the solution with new packages
Write-Host "dotnet build -c Release"
dotnet build -c Release