Skip to content

Commit

Permalink
fix(#476): 🐛 output variable edge cases (#479)
Browse files Browse the repository at this point in the history
* fix(#476): 🐛 issue with empty output variable

* fix: 🐛
  • Loading branch information
AndreasAugustin committed Mar 2, 2024
1 parent baac1d8 commit ab4153b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@ jobs:
| ------ | ----------- |
| pr_branch | The name of the branch used for the pull request |

**Remarks** Please consider following edge cases

* **pr_branch**
* If PR branch already exists (e.g. after a 2nd run) the action won't update the branch but will still output the branch name
* If the remote repository already contains the source repository changes the action will exit and the output variable will be undefined
* If there are no changes the action will exit and the output variable will be undefined

### Docker

There are docker images available. Please checkout [How to use docker](docs/DOCKER.md) for details.
Expand Down
24 changes: 13 additions & 11 deletions src/sync_template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,24 @@ debug "new Git HASH ${NEW_TEMPLATE_GIT_HASH}"

echo "::group::Check new changes"

function set_github_action_outputs() {
echo "::group::set gh action outputs"
if [[ -z "${GITHUB_RUN_ID}" ]]; then
info "env var 'GITHUB_RUN_ID' is empty -> no github action workflow"
else
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter
echo "pr_branch=${NEW_BRANCH}" >> "$GITHUB_OUTPUT"
fi
echo "::endgroup::"
}


function check_branch_remote_existing() {
git ls-remote --exit-code --heads origin "${NEW_BRANCH}" || BRANCH_DOES_NOT_EXIST=true

if [[ "${BRANCH_DOES_NOT_EXIST}" != true ]]; then
warn "Git branch '${NEW_BRANCH}' exists in the remote repository"
set_github_action_outputs
exit 0
fi
}
Expand Down Expand Up @@ -240,15 +253,4 @@ fi

echo "::endgroup::"

function set_github_action_outputs() {
echo "::group::set gh action outputs"
if [[ -z "${GITHUB_RUN_ID}" ]]; then
info "env var 'GITHUB_RUN_ID' is empty -> no github action workflow"
else
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter
echo "pr_branch=${NEW_BRANCH}" >> "$GITHUB_OUTPUT"
fi
echo "::endgroup::"
}

set_github_action_outputs

0 comments on commit ab4153b

Please sign in to comment.