Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Improvements to api error reporting in scripts #6

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions bash/create_deployment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function call_api {
-H "Umbraco-Cloud-Api-Key: $apiKey" \
-H "Content-Type: application/json" \
-d "{\"commitMessage\":\"$commitMessage\"}")

responseCode=${response: -3}
content=${response%???}

Expand All @@ -36,12 +37,20 @@ function call_api {
return
fi
fi

## Let errors bubble forward
echo "Unexpected API Response Code: $responseCode"
echo "---Response Start---"
echo $content
echo "---Response End---"
errorResponse=$content
echo "Unexpected API Response Code: $responseCode - More details below"
# Check if the input is valid JSON
echo "$errorResponse" | jq . > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "--- Response RAW ---\n"
echo $errorResponse
else
echo "--- Response JSON formatted ---\n"
echo $errorResponse | jq .
fi
echo "\n---Response End---"
exit 1
}

Expand Down
18 changes: 14 additions & 4 deletions bash/get_changes_by_id.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,20 @@ function get_changes {
remoteChanges="yes"
return
fi
echo "---Response Start---"
echo $filePath
echo -e "\n---Response End---"
echo "Unexpected response - see above"

## Let errors bubble forward
errorResponse=$filePath
echo "Unexpected API Response Code: $responseCode - More details below"
# Check if the input is valid JSON
cat "$errorResponse" | jq . > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "--- Response RAW ---"
cat "$errorResponse"
else
echo "--- Response JSON formatted ---"
cat "$errorResponse" | jq .
fi
echo "---Response End---"
exit 1
}

Expand Down
16 changes: 12 additions & 4 deletions bash/get_deployment_status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,18 @@ function call_api {
fi

## Let errors bubble forward
echo "Unexpected API Response Code: $responseCode"
echo "---Response Start---"
echo $content
echo "---Response End---"
errorResponse=$content
echo "Unexpected API Response Code: $responseCode - More details below"
# Check if the input is valid JSON
echo "$errorResponse" | jq . > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "--- Response RAW ---\n"
echo $errorResponse
else
echo "--- Response JSON formatted ---\n"
echo $errorResponse | jq .
fi
echo "\n---Response End---"
exit 1
}

Expand Down
18 changes: 13 additions & 5 deletions bash/get_latest_deployment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,20 @@ function call_api {

return
fi
## Let errors bubble forward
echo "Unexpected API Response Code: $responseCode"
echo "---Response Start---"
echo $response
echo "---Response End---"

## Let errors bubble forward
errorResponse=$response
echo "Unexpected API Response Code: $responseCode - More details below"
# Check if the input is valid JSON
echo "$errorResponse" | jq . > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "--- Response RAW ---\n"
echo $errorResponse
else
echo "--- Response JSON formatted ---\n"
echo $errorResponse | jq .
fi
echo "\n---Response End---"
exit 1
}

Expand Down
17 changes: 13 additions & 4 deletions bash/start_deployment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,20 @@ function call_api {
fi

## Let errors bubble forward
echo "Unexpected API Response Code: $responseCode"
echo "---Response Start---"
echo $content
echo "---Response End---"
errorResponse=$content
echo "Unexpected API Response Code: $responseCode - More details below"
# Check if the input is valid JSON
echo "$errorResponse" | jq . > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "--- Response RAW ---\n"
echo $errorResponse
else
echo "--- Response JSON formatted ---\n"
echo $errorResponse | jq .
fi
echo "\n---Response End---"
exit 1

}

call_api
Expand Down
26 changes: 22 additions & 4 deletions bash/upload_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ if [[ -z "$baseUrl" ]]; then
baseUrl="https://api.cloud.umbraco.com"
fi

if [[ -z "$filePath" ]]; then
echo "filePath is empty"
exit 1
fi

if [[ ! -f "$filePath" ]]; then
echo "filePath does not contain a file"
exit 1
fi

### Endpoint docs
# https://docs.umbraco.com/umbraco-cloud/set-up/project-settings/umbraco-cicd/umbracocloudapi#upload-zip-source-file
#
Expand All @@ -32,10 +42,18 @@ function call_api {
fi

## Let errors bubble forward
echo "Unexpected API Response Code: $responseCode"
echo "---Response Start---"
echo $content
echo "---Response End---"
errorResponse=$content
echo "Unexpected API Response Code: $responseCode - More details below"
# Check if the input is valid JSON
echo "$errorResponse" | jq . > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "--- Response RAW ---\n"
echo $errorResponse
else
echo "--- Response JSON formatted ---\n"
echo $errorResponse | jq .
fi
echo "\n---Response End---"
exit 1
}

Expand Down
23 changes: 21 additions & 2 deletions powershell/Add-DeploymentPackage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ param(
[Parameter(Position=1)]
[string]
$DeploymentId,

[Parameter(Position=2)]
[string]
$ApiKey,
Expand All @@ -20,11 +20,24 @@ param(
$BaseUrl = "https://api.cloud.umbraco.com"
)


### Endpoint docs
# https://docs.umbraco.com/umbraco-cloud/set-up/project-settings/umbraco-cicd/umbracocloudapi#upload-zip-source-file
#
$url = "$BaseUrl/v1/projects/$ProjectId/deployments/$DeploymentId/package"

# test if file is present
if (-not $filePath) {
Write-Host "filePath is empty"
exit 1
}

if (-not (Test-Path -Path $filePath -PathType Leaf)) {
Write-Host "filePath does not contain a file"
exit 1
}
# end test

$fieldName = 'file'
$contentType = 'application/zip'
$umbracoHeader = @{ 'Umbraco-Cloud-Api-Key' = $ApiKey }
Expand Down Expand Up @@ -58,6 +71,12 @@ try {
catch
{
Write-Host "---Error---"
Write-Host $_
Write-Host $_.Exception.Message
if ($_.Exception.Response -ne $null) {
$responseStream = $_.Exception.Response.GetResponseStream()
$reader = New-Object System.IO.StreamReader($responseStream)
$responseBody = $reader.ReadToEnd()
Write-Host "Response Body: $responseBody"
}
exit 1
}
8 changes: 7 additions & 1 deletion powershell/Get-ChangesById.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ try {
}
catch {
Write-Host "---Error---"
Write-Host $_
Write-Host $_.Exception.Message
if ($_.Exception.Response -ne $null) {
$responseStream = $_.Exception.Response.GetResponseStream()
$reader = New-Object System.IO.StreamReader($responseStream)
$responseBody = $reader.ReadToEnd()
Write-Host "Response Body: $responseBody"
}
exit 1
}
8 changes: 7 additions & 1 deletion powershell/Get-LatestDeployment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ try{
}
catch {
Write-Host "---Error---"
Write-Host $_
Write-Host $_.Exception.Message
if ($_.Exception.Response -ne $null) {
$responseStream = $_.Exception.Response.GetResponseStream()
$reader = New-Object System.IO.StreamReader($responseStream)
$responseBody = $reader.ReadToEnd()
Write-Host "Response Body: $responseBody"
}
exit 1
}
8 changes: 7 additions & 1 deletion powershell/New-Deployment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ try {
}
catch {
Write-Host "---Error---"
Write-Host $_
Write-Host $_.Exception.Message
if ($_.Exception.Response -ne $null) {
$responseStream = $_.Exception.Response.GetResponseStream()
$reader = New-Object System.IO.StreamReader($responseStream)
$responseBody = $reader.ReadToEnd()
Write-Host "Response Body: $responseBody"
}
exit 1
}
8 changes: 7 additions & 1 deletion powershell/Start-Deployment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ try {
}
catch {
Write-Host "---Error---"
Write-Host $_
Write-Host $_.Exception.Message
if ($_.Exception.Response -ne $null) {
$responseStream = $_.Exception.Response.GetResponseStream()
$reader = New-Object System.IO.StreamReader($responseStream)
$responseBody = $reader.ReadToEnd()
Write-Host "Response Body: $responseBody"
}
exit 1
}
8 changes: 7 additions & 1 deletion powershell/Test-DeploymentStatus.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ function Request-Deployment-Status ([INT]$run){
catch
{
Write-Host "---Error---"
Write-Host $_
Write-Host $_.Exception.Message
if ($_.Exception.Response -ne $null) {
$responseStream = $_.Exception.Response.GetResponseStream()
$reader = New-Object System.IO.StreamReader($responseStream)
$responseBody = $reader.ReadToEnd()
Write-Host "Response Body: $responseBody"
}
exit 1
}
}
Expand Down