From 476464fbddb51b3c6481dd7bf7059885d0a366d0 Mon Sep 17 00:00:00 2001 From: Romain Lespinasse Date: Sat, 26 Oct 2024 21:41:34 +0200 Subject: [PATCH] feat(setup): add resilience in case of missing environment variables --- action.yml | 2 ++ setup.sh | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/action.yml b/action.yml index c931661..158a0b7 100644 --- a/action.yml +++ b/action.yml @@ -63,6 +63,8 @@ runs: env: INPUT_DRYRUN: ${{ inputs.dry-run }} INPUT_WITHOUTPREFIX: ${{ inputs.without-prefix }} + REPOSITORY_NAME: ${{ env.RT_GITHUB_REPOSITORY_NAME_PART }} + REF_POINT: ${{ env.RT_GITHUB_REF_NAME }} - name: Semantic Release id: semantic-release uses: cycjimmy/semantic-release-action@v4 diff --git a/setup.sh b/setup.sh index bf7136f..062f8b5 100755 --- a/setup.sh +++ b/setup.sh @@ -4,23 +4,28 @@ if [ -z "$GITHUB_ACTION_PATH" ]; then GITHUB_ACTION_PATH=. fi -echo "+ Create package.json file" +echo "Create package.json file" echo '{"description": "","private": true,"version": "0.0.0","release":{}}' >package.json # shellcheck disable=SC2094 -cat <<<"$(jq --arg name "${RT_GITHUB_REPOSITORY_NAME_PART}" '. += {name: $name}' package.json)" >package.json +cat <<<"$(jq --arg name "${REPOSITORY_NAME}" '. += {name: $name}' package.json)" >package.json if [ "${INPUT_DRYRUN}" == "true" ]; then - echo "+ Setup current branch as releasable (dry-run mode)" - # shellcheck disable=SC2094 - cat <<<"$(jq --arg branch "${RT_GITHUB_REF_NAME}" '.release += {branches: [$branch]}' package.json)" >package.json + if [ -n "${REF_POINT}" ]; then + echo " - Setup current branch as releasable (dry-run mode)" + # shellcheck disable=SC2094 + cat <<<"$(jq --arg branch "${REF_POINT}" '.release += {branches: [$branch]}' package.json)" >package.json + else + echo " Fallback to releasable branches since not current branch is found (dry-run mode)" + cat <<<"$(jq --argjson branches "$(<"${GITHUB_ACTION_PATH}"/branches.json)" '.release += {branches: $branches}' package.json)" >package.json + fi else - echo "+ Setup releasable branches" + echo " - Setup releasable branches" # shellcheck disable=SC2094 cat <<<"$(jq --argjson branches "$(<"${GITHUB_ACTION_PATH}"/branches.json)" '.release += {branches: $branches}' package.json)" >package.json fi if [ "${INPUT_WITHOUTPREFIX}" == "true" ]; then - echo "+ Remove prefix from released version" + echo " - Remove prefix from released version" # shellcheck disable=SC2094 cat <<<"$(jq '.release += {tagFormat: "${version}"}' package.json)" >package.json fi