Skip to content

Commit

Permalink
Invokegh (#759)
Browse files Browse the repository at this point in the history
Test pre-requisites in WorkflowInitialize and give warnings if git or GH
isn't installed, by attempting to display version numbers.
Also remove the mechanism of hiding the real exception in invoke-gh and
invoke-git to display this error in that function

---------

Co-authored-by: freddydk <freddydk@users.noreply.github.com>
  • Loading branch information
freddydk and freddydk authored Oct 7, 2023
1 parent 6bbfb2b commit 3a24826
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
17 changes: 16 additions & 1 deletion Actions/AL-Go-TestRepoHelper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,22 @@ function Test-JsonFile {
Test-JsonStr -org -jsonStr (Get-Content -Path $jsonFile -Raw -Encoding UTF8) -settingsDescription $settingsFile -type $type
}

function Test-ALGoRepository {
function TestRunnerPrerequisites {
try {
invoke-gh version
}
catch {
Write-Host "::Warning::GitHub CLI is not installed"
}
try {
invoke-git version
}
catch {
Write-Host "::Warning::Git is not installed"
}
}

function TestALGoRepository {
Param(
[string] $baseFolder = $ENV:GITHUB_WORKSPACE
)
Expand Down
17 changes: 5 additions & 12 deletions Actions/Github-Helper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -309,18 +309,16 @@ function invoke-gh {
$arguments = "$command "
foreach($parameter in $remaining) {
if ("$parameter".IndexOf(" ") -ge 0 -or "$parameter".IndexOf('"') -ge 0) {
if ($parameter.length -gt 15000) {
$parameter = "$($parameter.Substring(0,15000))...`n`n**Truncated due to size limits!**"
}
$arguments += """$($parameter.Replace('"','\"'))"" "
}
else {
$arguments += "$parameter "
}
}
try {
cmdDo -command gh -arguments $arguments -silent:$silent -returnValue:$returnValue -inputStr $inputStr
}
catch [System.Management.Automation.MethodInvocationException] {
throw "It looks like GitHub CLI is not installed. Please install GitHub CLI from https://cli.github.com/"
}
cmdDo -command gh -arguments $arguments -silent:$silent -returnValue:$returnValue -inputStr $inputStr
}
}

Expand All @@ -344,12 +342,7 @@ function invoke-git {
$arguments += "$parameter "
}
}
try {
cmdDo -command git -arguments $arguments -silent:$silent -returnValue:$returnValue -inputStr $inputStr
}
catch [System.Management.Automation.MethodInvocationException] {
throw "It looks like Git is not installed. Please install Git from https://git-scm.com/download"
}
cmdDo -command git -arguments $arguments -silent:$silent -returnValue:$returnValue -inputStr $inputStr
}
}

Expand Down
4 changes: 3 additions & 1 deletion Actions/WorkflowInitialize/WorkflowInitialize.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ try {

Write-Big -str "a$verstr"

Test-ALGoRepository
TestALGoRepository

DownloadAndImportBcContainerHelper

TestRunnerPrerequisites

import-module (Join-Path -path $PSScriptRoot -ChildPath "..\TelemetryHelper.psm1" -Resolve)
$telemetryScope = CreateScope -eventId $eventId
if ($telemetryScope) {
Expand Down
2 changes: 1 addition & 1 deletion Tests/WorkflowInitialize.Test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Describe "WorkflowInitialize Action Tests" {
Set-Content -Path (Join-Path $githubFolder 'AL-Go-Settings.json') -Value $repoSettings -Encoding UTF8
Set-Content -Path (Join-Path $ALGoFolder 'settings.json') -Value $projectSettings -Encoding UTF8
Set-Content -Path (Join-Path $Project1ALGoFolder 'settings.json') -Value $project1Settings -Encoding UTF8
Test-ALGoRepository -baseFolder $tempDir
TestALGoRepository -baseFolder $tempDir
}
finally {
Remove-Item -Path $tempDir -Recurse -Force
Expand Down

0 comments on commit 3a24826

Please sign in to comment.