From 6b31f210ac923efb03816308cd129b8d434c397e Mon Sep 17 00:00:00 2001 From: Simon Lepel Date: Wed, 7 Sep 2022 09:52:34 +0200 Subject: [PATCH] improve error handling --- action.yml | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index 5b86bb2..2b43e72 100644 --- a/action.yml +++ b/action.yml @@ -54,16 +54,25 @@ runs: shell: bash run: | if [[ "${{ inputs.version }}" = "" ]]; then - valeVersion="$(curl -sL https://api.github.com/repos/errata-ai/vale/releases/latest | grep '"tag_name":' | cut -d \" -f 4 | cut -d v -f 2)" + valeVersionData=$(curl -sfL https://api.github.com/repos/errata-ai/vale/releases/latest) + if [[ "$valeVersionData" = "" ]]; then + echo "::error title=GitHub API Error::Could not retrieve the latest Vale version info from GitHub API." + exit 1 + fi + valeVersion="$(printf "$valeVersionData" | grep '"tag_name":' | cut -d \" -f 4 | cut -d v -f 2)" else valeVersion="${{ inputs.version }}" fi if ! [[ "$valeVersion" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo "::error title=invalid version::vale version '${valeVersion}' is not a valid semver version" + echo "::error title=Invalid Version::The Vale version '${valeVersion}' is not a valid semver version." exit 1 fi echo "::group::Vale Installation" - curl -sL https://github.com/errata-ai/vale/releases/download/v${valeVersion}/vale_${valeVersion}_Linux_64-bit.tar.gz -o vale.tar.gz + curl -sfL https://github.com/errata-ai/vale/releases/download/v${valeVersion}/vale_${valeVersion}_Linux_64-bit.tar.gz -o vale.tar.gz + if ! [[ -f vale.tar.gz ]]; then + echo "::error title=Vale Download failed::Downloading the latest Vale version failed." + exit 1 + fi mkdir -p ${RUNNER_TEMP}/bin tar -xvzf vale.tar.gz -C ${RUNNER_TEMP}/bin rm vale.tar.gz @@ -83,7 +92,12 @@ runs: shell: bash run: | echo "::group::Reviewdog Installation" - curl -sL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s -- -b ${RUNNER_TEMP}/bin + reviewdogScript=$(curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh) + if [[ "$reviewdogScript" = "" ]]; then + echo "::error title=Reviewdog Download failed::Downloading the Reviewdog script from GitHub failed." + exit 1 + fi + printf "$reviewdogScript" | sh -s -- -b ${RUNNER_TEMP}/bin echo "::endgroup::" - name: 🧑‍🏫 Run Vale with Reviewdog