From 6306cb80ad79fca6ac9717161f924617f1a71ce5 Mon Sep 17 00:00:00 2001 From: freddydk Date: Fri, 26 Jan 2024 08:20:39 +0100 Subject: [PATCH 1/6] Give better error message if GitHub CLI or GIT isn't installed --- ...ReferenceDocumentation.HelperFunctions.ps1 | 2 +- Actions/Github-Helper.psm1 | 24 +++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Actions/BuildReferenceDocumentation/BuildReferenceDocumentation.HelperFunctions.ps1 b/Actions/BuildReferenceDocumentation/BuildReferenceDocumentation.HelperFunctions.ps1 index 2b398d95f..b88a25129 100644 --- a/Actions/BuildReferenceDocumentation/BuildReferenceDocumentation.HelperFunctions.ps1 +++ b/Actions/BuildReferenceDocumentation/BuildReferenceDocumentation.HelperFunctions.ps1 @@ -24,7 +24,7 @@ & /usr/bin/env sudo pwsh -command "& chmod +x $ENV:aldocPath" } Write-Host "Installing/Updating docfx" - CmdDo -command dotnet -arguments @("tool","update","-g docfx") + CmdDo -command dotnet -arguments @("tool","update","-g docfx") -messageIfCmdNotFound "dotnet not found. Please install it from https://dotnet.microsoft.com/download" } return $ENV:aldocPath } diff --git a/Actions/Github-Helper.psm1 b/Actions/Github-Helper.psm1 index a3209c85a..c0a82df3e 100644 --- a/Actions/Github-Helper.psm1 +++ b/Actions/Github-Helper.psm1 @@ -237,7 +237,8 @@ function CmdDo { [string] $arguments = "", [switch] $silent, [switch] $returnValue, - [string] $inputStr = "" + [string] $inputStr = "", + [string] $messageIfCmdNotFound = "" ) $oldNoColor = "$env:NO_COLOR" @@ -282,14 +283,27 @@ function CmdDo { Write-Host $message } if ($returnValue) { - $message.Replace("`r","").Split("`n") + $message.Replace("`r", "").Split("`n") } } else { - $message += "`n`nExitCode: "+$p.ExitCode + "`nCommandline: $command $arguments" + $message += "`n`nExitCode: " + $p.ExitCode + "`nCommandline: $command $arguments" throw $message } } + catch [System.ComponentModel.Win32Exception] { + if ($_.Exception.NativeErrorCode -eq 2) { + if ($messageIfCmdNotFound) { + throw $messageIfCmdNotFound + } + else { + throw "Command $command not found, you might need to install that command." + } + } + else { + throw $_ + } + } finally { try { [Console]::OutputEncoding = $oldEncoding } catch {} $env:NO_COLOR = $oldNoColor @@ -319,7 +333,7 @@ function invoke-gh { $arguments += "$parameter " } } - cmdDo -command gh -arguments $arguments -silent:$silent -returnValue:$returnValue -inputStr $inputStr + cmdDo -command gh -arguments $arguments -silent:$silent -returnValue:$returnValue -inputStr $inputStr -messageIfCmdNotFound "Github CLI not found. Please install it from https://cli.github.com/" } } @@ -343,7 +357,7 @@ function invoke-git { $arguments += "$parameter " } } - cmdDo -command git -arguments $arguments -silent:$silent -returnValue:$returnValue -inputStr $inputStr + cmdDo -command git -arguments $arguments -silent:$silent -returnValue:$returnValue -inputStr $inputStr -messageIfCmdNotFound "Git not found. Please install it from https://git-scm.com/downloads" } } From 84e152433a06bea67f3ab320299566a62d81fcb3 Mon Sep 17 00:00:00 2001 From: freddydk Date: Fri, 26 Jan 2024 08:22:21 +0100 Subject: [PATCH 2/6] release note --- RELEASENOTES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index a7412b2a4..232e65cf7 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -7,6 +7,7 @@ Note that when using the preview version of AL-Go for GitHub, we recommend you U ### Issues - Support release branches that start with releases/ +- Issue 870 Improve Error Handling when CLI is missing ### Build modes AL-Go ships with Default, Translated and Clean mode out of the box. Now you can also define custom build modes in addition to the ones shipped with AL-Go. This allows you to define your own build modes, which can be used to build your apps in different ways. By default, a custom build mode will build the apps similarly to the Default mode but this behavior can be overridden in e.g. script overrides in your repository. From 7c098e4b4043c8f684fb7b8184ab3b638fc46df3 Mon Sep 17 00:00:00 2001 From: freddydk Date: Fri, 26 Jan 2024 08:23:49 +0100 Subject: [PATCH 3/6] throw --- Actions/AL-Go-Helper.ps1 | 2 +- Actions/Github-Helper.psm1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Actions/AL-Go-Helper.ps1 b/Actions/AL-Go-Helper.ps1 index 6b4fc4dc1..2c4d596de 100644 --- a/Actions/AL-Go-Helper.ps1 +++ b/Actions/AL-Go-Helper.ps1 @@ -2261,7 +2261,7 @@ function RetryCommand { catch { $retryCount++ if ($retryCount -eq $MaxRetries) { - throw $_ + throw } else { Write-Host "Retrying after $RetryDelaySeconds seconds..." diff --git a/Actions/Github-Helper.psm1 b/Actions/Github-Helper.psm1 index c0a82df3e..633dff752 100644 --- a/Actions/Github-Helper.psm1 +++ b/Actions/Github-Helper.psm1 @@ -301,7 +301,7 @@ function CmdDo { } } else { - throw $_ + throw } } finally { From 4a0e2655659e080ed421536277046b577cd5f96b Mon Sep 17 00:00:00 2001 From: freddydk Date: Fri, 26 Jan 2024 08:46:34 +0100 Subject: [PATCH 4/6] update doc --- Scenarios/UpdateAlGoSystemFiles.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Scenarios/UpdateAlGoSystemFiles.md b/Scenarios/UpdateAlGoSystemFiles.md index 77dbca415..c08a06048 100644 --- a/Scenarios/UpdateAlGoSystemFiles.md +++ b/Scenarios/UpdateAlGoSystemFiles.md @@ -10,6 +10,7 @@ 1. To update the AL-Go system files using the Update AL-Go System Files workflow, you need to provide a secret called GHTOKENWORKFLOW containing a Personal Access Token with permissions to modify workflows 1. In a browser, navigate to [New personal access token](https://github.com/settings/tokens/new) and create a new **personal access token**. Name it, set the expiration date and check the **workflow option** in the list of **scopes**. ![newPAT](https://github.com/microsoft/AL-Go/assets/10775043/1ab9978a-37e8-423a-8f8e-5c0203f7ae00) +1. Note that the above applies to **classic** tokens only. If you are creating a **Fine-grained** token, you need to specify which repositories to include and assign **Read and Write** permissions to **Contents**, **Pull Requests** and **Workflows**. 1. Generate the token and **copy it to the clipboard**. You won’t be able to see the token again. 1. On github.com, open **Settings** in your project and select **Secrets**. Choose the New repository secret button and create a secret called GHTOKENWORKFLOW and paste the personal access token in the value field and choose **Add secret**. ![PAT](https://github.com/microsoft/AL-Go/assets/10775043/7dcccca3-ec43-47ba-bffb-795332c890ad) From 64e6e647ac09b07750a62ff247862162c99f8cb8 Mon Sep 17 00:00:00 2001 From: freddydk Date: Fri, 26 Jan 2024 08:47:15 +0100 Subject: [PATCH 5/6] update doc --- Scenarios/UpdateAlGoSystemFiles.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Scenarios/UpdateAlGoSystemFiles.md b/Scenarios/UpdateAlGoSystemFiles.md index 77dbca415..c08a06048 100644 --- a/Scenarios/UpdateAlGoSystemFiles.md +++ b/Scenarios/UpdateAlGoSystemFiles.md @@ -10,6 +10,7 @@ 1. To update the AL-Go system files using the Update AL-Go System Files workflow, you need to provide a secret called GHTOKENWORKFLOW containing a Personal Access Token with permissions to modify workflows 1. In a browser, navigate to [New personal access token](https://github.com/settings/tokens/new) and create a new **personal access token**. Name it, set the expiration date and check the **workflow option** in the list of **scopes**. ![newPAT](https://github.com/microsoft/AL-Go/assets/10775043/1ab9978a-37e8-423a-8f8e-5c0203f7ae00) +1. Note that the above applies to **classic** tokens only. If you are creating a **Fine-grained** token, you need to specify which repositories to include and assign **Read and Write** permissions to **Contents**, **Pull Requests** and **Workflows**. 1. Generate the token and **copy it to the clipboard**. You won’t be able to see the token again. 1. On github.com, open **Settings** in your project and select **Secrets**. Choose the New repository secret button and create a secret called GHTOKENWORKFLOW and paste the personal access token in the value field and choose **Add secret**. ![PAT](https://github.com/microsoft/AL-Go/assets/10775043/7dcccca3-ec43-47ba-bffb-795332c890ad) From 83a328ee204c51fac41a00ec301ba69cf34bf02d Mon Sep 17 00:00:00 2001 From: freddydk Date: Fri, 26 Jan 2024 08:49:42 +0100 Subject: [PATCH 6/6] remove doc --- Scenarios/UpdateAlGoSystemFiles.md | 1 - 1 file changed, 1 deletion(-) diff --git a/Scenarios/UpdateAlGoSystemFiles.md b/Scenarios/UpdateAlGoSystemFiles.md index c08a06048..77dbca415 100644 --- a/Scenarios/UpdateAlGoSystemFiles.md +++ b/Scenarios/UpdateAlGoSystemFiles.md @@ -10,7 +10,6 @@ 1. To update the AL-Go system files using the Update AL-Go System Files workflow, you need to provide a secret called GHTOKENWORKFLOW containing a Personal Access Token with permissions to modify workflows 1. In a browser, navigate to [New personal access token](https://github.com/settings/tokens/new) and create a new **personal access token**. Name it, set the expiration date and check the **workflow option** in the list of **scopes**. ![newPAT](https://github.com/microsoft/AL-Go/assets/10775043/1ab9978a-37e8-423a-8f8e-5c0203f7ae00) -1. Note that the above applies to **classic** tokens only. If you are creating a **Fine-grained** token, you need to specify which repositories to include and assign **Read and Write** permissions to **Contents**, **Pull Requests** and **Workflows**. 1. Generate the token and **copy it to the clipboard**. You won’t be able to see the token again. 1. On github.com, open **Settings** in your project and select **Secrets**. Choose the New repository secret button and create a secret called GHTOKENWORKFLOW and paste the personal access token in the value field and choose **Add secret**. ![PAT](https://github.com/microsoft/AL-Go/assets/10775043/7dcccca3-ec43-47ba-bffb-795332c890ad)