-
Notifications
You must be signed in to change notification settings - Fork 0
/
AUTO_RECURSIVE_PACKAGE_PUSHER.ps1
76 lines (61 loc) · 2.68 KB
/
AUTO_RECURSIVE_PACKAGE_PUSHER.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
Clear-Host;
#$Destinations = @('BaGet','NuGet')
$Path = "C:\ACT\Releases\"
$Filter = "*.nupkg"
$AllPackages = Read-Host -Prompt "Push All New Packages (Y / N): "
# CRAP CODE BUT IT WORKS JUST DONT TYPE ;)
$DestinationName = Read-Host -Prompt "Type the Destination Name: "
#if ($Destinations.Contains($DestinationName)) { Write-Host "Invalid Destination (Check Line 4)" Write-Host Script End }
if ($AllPackages -eq "y") {
$directories = Get-ChildItem $path -Directory -Recurse
foreach ($directory in $directories)
{
#Write-Output $directory.FullName;
if ($directory.FullName.Contains("Release"))
{
if (!$directory.FullName.Contains("Debug"))
{
# $fullPath = Get-ChildItem -File -Filter *.nupkg -Path $directory.FullName | Sort CreationTime -Descending | Select-Object -First 1
$latest = Get-ChildItem -Path $directory.FullName -Filter $Filter | Sort-Object LastAccessTime -Descending | Select-Object -First 1
if ($latest.FullName -ne $null)
{
$FileNameToSend = $latest.FullName
if ($DestinationName -eq "baget") { PushToDestination $DestinationName $FileNameToSend }
elseif ($DestinationName -eq "nuget") { PushToDestination $DestinationName $FileNameToSend }
else
{
Write-Host "Error Odd..."
}
}
}
}
}
}
else
{
}
Write-Host Script End;
function PushToDestination {
Param
(
[Parameter(Mandatory=$true, Position=0)]
[string] $Destination,
[Parameter(Mandatory=$true, Position=1)]
[string] $PackageName
)
Write-Host "Pushing $($PackageName) To $($Destination)"
if ($Destination -eq "baget")
{
# PUT YOUR API KEY HERE
$APIBAGET = ""
$CommandBaGet = "nuget push $($PackageName) -Source http://localhost:5000/v3/index.json -ApiKey $($APIBAGET)"
Invoke-Expression $CommandBaGet
}
else # ($Destination -eq "nuget")
{
# PUT YOUR API KEY HERE
'nuget setApiKey ""', 'nuget push "$PackageName" -Source https://api.nuget.org/v3/index.json' | Invoke-Expression
}
Write-Host Script End;
}