Skip to content

Commit

Permalink
feat(setup): add resilience in case of missing environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
rlespinasse committed Oct 26, 2024
1 parent 478159f commit 476464f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 12 additions & 7 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 476464f

Please sign in to comment.