From 192b06392ad30d583134226bf681144bda074355 Mon Sep 17 00:00:00 2001 From: Tomas Dabasinskas Date: Mon, 4 Oct 2021 17:53:43 +0300 Subject: [PATCH] Improve GITHUB_API_URL default value handling (#2031) * Improve GITHUB_API_URL default value handling GitHub Actions [already has](https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables) `GITHUB_API_URL` environment variable which contains GitHub API URL. We should be smart about overriding it and, if it exist and already has value, we should not override it. * Strip slash from GITHUB_API_URL * Update linter.sh * Update linter.sh * make shfmt happy Co-authored-by: Lukas Gravley --- lib/linter.sh | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index a6fb1a02..cb271265 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -64,12 +64,20 @@ source /action/lib/functions/worker.sh # Source the function script(s) ########### # GLOBALS # ########### +# GitHub API root url +if [ -n "$GITHUB_CUSTOM_API_URL" ]; then + GITHUB_API_URL="${GITHUB_CUSTOM_API_URL}" +elif [ -z "$GITHUB_API_URL" ]; then + GITHUB_API_URL="https://api.github.com" +fi +# Remove trailing slash if present +GITHUB_API_URL="${GITHUB_API_URL%/}" + # Default Vars -DEFAULT_RULES_LOCATION='/action/lib/.automation' # Default rules files location -LINTER_RULES_PATH="${LINTER_RULES_PATH:-.github/linters}" # Linter rules directory -GITHUB_API_URL="${GITHUB_CUSTOM_API_URL:-"https://api.github.com"}" # GitHub API root url -VERSION_FILE='/action/lib/functions/linterVersions.txt' # File to store linter versions -export VERSION_FILE # Workaround SC2034 +DEFAULT_RULES_LOCATION='/action/lib/.automation' # Default rules files location +LINTER_RULES_PATH="${LINTER_RULES_PATH:-.github/linters}" # Linter rules directory +VERSION_FILE='/action/lib/functions/linterVersions.txt' # File to store linter versions +export VERSION_FILE # Workaround SC2034 ############### # Rules files #