Skip to content

Commit

Permalink
(GH-8) Finished implementing command
Browse files Browse the repository at this point in the history
  • Loading branch information
gep13 committed Nov 21, 2018
1 parent 9d85009 commit d663257
Show file tree
Hide file tree
Showing 2 changed files with 178 additions and 1 deletion.
80 changes: 79 additions & 1 deletion Tasks/push/push.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,85 @@ param()
Trace-VstsEnteringInvocation $MyInvocation

try {
Write-Host "Would run choco push here..."
$chocoInstallLocation = [Environment]::GetEnvironmentVariable("ChocolateyInstall", "Machine")
if(-not (Test-Path $chocoInstallLocation)) {
Write-Output "Environment variable 'ChocolateyInstall' was not found in the system variables. Attempting to find it in the user variables..."
$chocoInstallLocation = [Environment]::GetEnvironmentVariable("ChocolateyInstall", "User")
}

$chocoExe = "$chocoInstallLocation\choco.exe"

if (-not (Test-Path $chocoExe)) {
throw "Chocolatey was not found."
}

[string]$operation = Get-VstsInput -Name 'operation' -Require
[string]$workingDirectory = Get-VstsInput -Name 'workingDirectory' -Require
[string]$source = Get-VstsInput -Name 'source' -Default 'https://push.chocolatey.org/'
[string]$apikey = Get-VstsInput -Name 'apikey'
[bool]$force = Get-VstsInput -Name 'force' -AsBool -Default $false
[string]$timeout = Get-VstsInput -Name 'timeout'
[bool]$debug = Get-VstsInput -Name 'debug' -AsBool -Default $false
[bool]$verbose = Get-VstsInput -Name 'verbose' -AsBool -Default $false
[bool]$trace = Get-VstsInput -Name 'trace' -AsBool -Default $false
[string]$extraArguments = Get-VstsInput -Name 'extraArguments'

$chocolateyVersion = & $chocoExe --version
Write-Output "Running Chocolatey Version: $chocolateyVersion"

$chocolateyArguments = @()

if($source) {
Write-Output "Adding --source to arguments"
$chocolateyArguments += @("--source", $source)
}

if($apikey) {
Write-Output "Adding --apikey to arguments"
$chocolateyArguments += @("--apikey", $apikey)
}

if($force) {
Write-Output "Adding --force to arguments"
$chocolateyArguments += @("--force", "")
}

if($timeout) {
Write-Output "Adding -t to arguments"
$chocolateyArguments += @("-t", $timeout)
}

if($debug) {
Write-Output "Adding --debug to arguments"
$chocolateyArguments += @("--debug", "")
}

if($verbose) {
Write-Output "Adding --verbose to arguments"
$chocolateyArguments += @("--verbose", "")
}

if($trace) {
Write-Output "Adding --trace to arguments"
$chocolateyArguments += @("--trace", "")
}

if($extraArguments) {
Write-Output "Adding extra arguments"
$chocolateyArguments += @($extraArguments, "")
}

Set-Location $workingDirectory

if($operation -eq "single") {
[string]$nupkgFileName = Get-VstsInput -Name 'nupkgFileName' -Require
& $chocoExe push $nupkgFileName $($chocolateyArguments)
} else {
$nupkgFiles = Get-ChildItem "*.nupkg"
foreach($nupkgFile in $nupkgFiles) {
& $chocoExe push $nupkgFile $($chocolateyArguments)
}
}
} catch {
Write-VstsTaskError $_.Exception.Message
throw
Expand Down
99 changes: 99 additions & 0 deletions Tasks/push/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,105 @@
},
"minimumAgentVersion": "1.83.0",
"instanceNameFormat": "Chocolatey Push",
"inputs": [
{
"name": "operation",
"type": "radio",
"label": "How many nupkg files?",
"required": true,
"defaultValue": "single",
"helpMarkDown": "Choose whether to pus a single nupkg file, or multiple.",
"options": {
"single": "One nupkg file",
"multiple": "Multiple nupkg files"
}
},
{
"name": "workingDirectory",
"type": "string",
"label": "Working Directory",
"defaultValue": "",
"required": true,
"helpMarkDown": "The location of the nupkg file(s)."
},
{
"name": "nupkgFileName",
"type": "string",
"label": "Nupkg File Name.",
"defaultValue": "",
"required": true,
"helpMarkDown": "The file name of the Nupkg File that should be pushed.",
"visibleRule": "operation=single"
},
{
"name": "source",
"type": "string",
"label": "Source",
"defaultValue": "https://push.chocolatey.org/",
"required": false,
"helpMarkDown": "The source to push the nupkg(s) to."
},
{
"name": "apikey",
"type": "string",
"label": "API Key",
"defaultValue": "",
"required": false,
"helpMarkDown": "The API Key that should be used to push the nupkg(s) to specified source."
},
{
"name": "force",
"type": "boolean",
"label": "Force.",
"defaultValue": "false",
"required": false,
"helpMarkDown": "Force the operation to continue."
},
{
"name": "timeout",
"type": "string",
"label": "Timeout",
"defaultValue": "",
"required": false,
"helpMarkDown": "The time, in seconds, to allow a package push to occur before timing out."
},
{
"name": "debug",
"type": "boolean",
"label": "Show debug messaging.",
"defaultValue": "false",
"required": false,
"helpMarkDown": "",
"groupname": "advanced"
},
{
"name": "verbose",
"type": "boolean",
"label": "Show verbose messaging.",
"defaultValue": "false",
"required": false,
"helpMarkDown": "Very verbose messaging, avoid using under normal circumstances.",
"groupname": "advanced"
},
{
"name": "trace",
"type": "boolean",
"label": "Show trace messaging.",
"defaultValue": "false",
"required": false,
"helpMarkDown": "Very, very verbose trace messaging. Avoid except when needing super low-level .NET Framework debugging.",
"groupname": "advanced"
},
{
"name": "extraArguments",
"type": "string",
"label": "Extra Arguments",
"defaultValue": "",
"required": false,
"helpMarkDown": "Additional Chocolatey Arguments that are not catered for above.",
"groupname": "advanced"
}
],
"execution": {
"PowerShell3": {
"target": "$(currentDirectory)\\push.ps1",
Expand Down

0 comments on commit d663257

Please sign in to comment.