Skip to content

Commit

Permalink
Improve error message in Update AL Go System Files (#1205)
Browse files Browse the repository at this point in the history
Improve error message in Update AL Go System Files

Fixes #1204
  • Loading branch information
aholstrup1 authored Sep 13, 2024
1 parent a2a51be commit 90a52fe
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions Actions/CheckForUpdates/CheckForUpdates.HelperFunctions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,14 @@ function DownloadTemplateRepository {

# Construct API URL
$apiUrl = $templateUrl.Split('@')[0] -replace "^(https:\/\/github\.com\/)(.*)$", "$ENV:GITHUB_API_URL/repos/`$2"
$branch = $templateUrl.Split('@')[1]

Write-Host "TemplateUrl: $templateUrl"
Write-Host "TemplateSha: $($templateSha.Value)"
Write-Host "DownloadLatest: $downloadLatest"

if ($downloadLatest) {
# Get Branches from template repository
$response = InvokeWebRequest -Headers $headers -Uri "$apiUrl/branches?per_page=100" -retry
$branchInfo = ($response.content | ConvertFrom-Json) | Where-Object { $_.Name -eq $branch }
if (!$branchInfo) {
throw "$templateUrl doesn't exist"
}
$templateSha.Value = $branchInfo.commit.sha
# Get latest commit SHA from the template repository
$templateSha.Value = GetLatestTemplateSha -headers $headers -apiUrl $apiUrl -templateUrl $templateUrl
Write-Host "Latest SHA for $($templateUrl): $($templateSha.Value)"
}
$archiveUrl = "$apiUrl/zipball/$($templateSha.Value)"
Expand All @@ -47,6 +41,32 @@ function DownloadTemplateRepository {
return $tempName
}

function GetLatestTemplateSha {
Param(
[hashtable] $headers,
[string] $apiUrl,
[string] $templateUrl
)
$branch = $templateUrl.Split('@')[1]

try {
$response = InvokeWebRequest -Headers $headers -Uri "$apiUrl/branches?per_page=100" -retry
$branchInfo = ($response.content | ConvertFrom-Json) | Where-Object { $_.Name -eq $branch }
} catch {
if ($_.Exception.Message -like "*401*") {
throw "Failed to update AL-Go System Files. Make sure that the personal access token, defined in the secret called GhTokenWorkflow, is not expired and it has permission to update workflows. (Error was $($_.Exception.Message))"
} else {
throw $_.Exception.Message
}
}

if (!$branchInfo) {
throw "$templateUrl doesn't exist"
}

return $branchInfo.commit.sha
}

function ModifyCICDWorkflow {
Param(
[Yaml] $yaml,
Expand Down

0 comments on commit 90a52fe

Please sign in to comment.