diff --git a/README.md b/README.md index af21a9c7..3ab5bf8e 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/sync_template.sh b/src/sync_template.sh index 8f5f815a..a474dd38 100644 --- a/src/sync_template.sh +++ b/src/sync_template.sh @@ -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 } @@ -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