From d0c429c8a12ddb80bc36e836a09e9e7225cb4dfd Mon Sep 17 00:00:00 2001 From: Tobias Genannt Date: Mon, 13 Sep 2021 09:09:24 +0200 Subject: [PATCH 1/2] Check if remote branch exists before checkout --- build.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/build.sh b/build.sh index e980411..8b12c12 100755 --- a/build.sh +++ b/build.sh @@ -118,6 +118,14 @@ NETBOX_PATH="${NETBOX_PATH-.netbox}" # Fetching the NetBox source ### if [ "${2}" != "--push-only" ] && [ -z "${SKIP_GIT}" ]; then + REMOTE_EXISTS=$(git ls-remote --heads --tags "${URL}" "${NETBOX_BRANCH}" | wc -l) + if [ "${REMOTE_EXISTS}" != "1" ]; then + echo "❌ Remote branch '${NETBOX_BRANCH}' not found in '${URL}'; Nothing to do" + if [ -n "${GH_ACTION}" ]; then + echo "::set-output name=skipped::true" + fi + exit 0 + fi echo "🌐 Checking out '${NETBOX_BRANCH}' of NetBox from the url '${URL}' into '${NETBOX_PATH}'" if [ ! -d "${NETBOX_PATH}" ]; then $DRY git clone -q --depth 10 -b "${NETBOX_BRANCH}" "${URL}" "${NETBOX_PATH}" From c4d545a2565047461f0d1e2e9ba816f0a66bd50e Mon Sep 17 00:00:00 2001 From: Tobias Genannt Date: Mon, 13 Sep 2021 22:50:06 +0200 Subject: [PATCH 2/2] Improved check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Christian Mäder --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 8b12c12..f33a2d1 100755 --- a/build.sh +++ b/build.sh @@ -119,7 +119,7 @@ NETBOX_PATH="${NETBOX_PATH-.netbox}" ### if [ "${2}" != "--push-only" ] && [ -z "${SKIP_GIT}" ]; then REMOTE_EXISTS=$(git ls-remote --heads --tags "${URL}" "${NETBOX_BRANCH}" | wc -l) - if [ "${REMOTE_EXISTS}" != "1" ]; then + if [ "${REMOTE_EXISTS}" == "0" ]; then echo "❌ Remote branch '${NETBOX_BRANCH}' not found in '${URL}'; Nothing to do" if [ -n "${GH_ACTION}" ]; then echo "::set-output name=skipped::true"