Skip to content

Commit

Permalink
fix: 🐛
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Augustin <dev@andreas-augustin.org>
  • Loading branch information
AndreasAugustin committed Mar 18, 2024
1 parent 624156f commit 90dc31a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ jobs:
| source_repo_ssh_private_key | `[optional]` private ssh key for the source repository. [see](#private-template-repository) | `false` | |
| pr_branch_name_prefix | `[optional]` the prefix of branches created by this action | `false` | `chore/template_sync` |
| pr_title | `[optional]` the title of PRs opened by this action. Must be already created. | `false` | `upstream merge template repository` |
| pr_body | `[optional]` the body of PRs opened by this action. | `false` | `Merge ${SOURCE_REPO_PATH} ${TEMPLATE_GIT_HASH}` |
| pr_body | `[optional]` the body of PRs opened by this action. | `false` | `Merge ${SOURCE_REPO} ${TEMPLATE_GIT_HASH}` |
| pr_labels | `[optional]` comma separated list. [pull request labels][pr-labels]. | `false` | `sync_template` |
| pr_reviewers | `[optional]` comma separated list of pull request reviewers. | `false` | |
| pr_commit_msg | `[optional]` commit message in the created pull request | `false` | `chore(template): merge template changes :up:` |
Expand Down
43 changes: 26 additions & 17 deletions src/sync_template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,29 @@ TEMPLATE_REMOTE_GIT_HASH=$(git ls-remote "${SOURCE_REPO}" HEAD | awk '{print $1}
SHORT_TEMPLATE_GIT_HASH=$(git rev-parse --short "${TEMPLATE_REMOTE_GIT_HASH}")

export TEMPLATE_GIT_HASH=${SHORT_TEMPLATE_GIT_HASH}
export NEW_BRANCH="${PR_BRANCH_NAME_PREFIX}_${TEMPLATE_GIT_HASH}"
# : "${PR_BODY:="Merge ${SOURCE_REPO_PATH} ${TEMPLATE_GIT_HASH}"}"
PR_TITLE_TMP="${PR_TITLE:-"upstream merge template repository"}"
export PR_BRANCH="${PR_BRANCH_NAME_PREFIX}_${TEMPLATE_GIT_HASH}"
: "${PR_BODY:="Merge ${SOURCE_REPO} ${TEMPLATE_GIT_HASH}"}"
: "${PR_TITLE:-"upstream merge template repository"}"

debug "TEMPLATE_GIT_HASH ${TEMPLATE_GIT_HASH}"
debug "NEW_BRANCH ${NEW_BRANCH}"
info "PR_BODY ${PR_BODY}"
# info "PR_BODY_TMP ${PR_BODY_TMP}"
# for some reasons the substitution is not working as expected
# so we substitute manually
# shellcheck disable=SC2016
PR_BODY=${PR_BODY//'${TEMPLATE_GIT_HASH}'/"${TEMPLATE_GIT_HASH}"}
# shellcheck disable=SC2016
PR_BODY=${PR_BODY//'${SOURCE_REPO}'/"${SOURCE_REPO}"}
# shellcheck disable=SC2016
PR_BODY=${PR_BODY//'${PR_BRANCH}'/"${PR_BRANCH}"}

# shellcheck disable=SC2016
# PR_BODY=${PR_BODY//'${TEMPLATE_GIT_HASH}'/"${TEMPLATE_GIT_HASH}"}
# PR_BODY=${PR_BODY//'${SOURCE_REPO}'/"${SOURCE_REPO}"}
# info "SOURCE_REPO ${SOURCE_REPO}"
# export TMP="${PR_BODY}"
# info "TMP ${TMP}"
PR_TITLE=${PR_TITLE//'${TEMPLATE_GIT_HASH}'/"${TEMPLATE_GIT_HASH}"}
# shellcheck disable=SC2016
PR_TITLE=${PR_TITLE//'${SOURCE_REPO}'/"${SOURCE_REPO}"}
# shellcheck disable=SC2016
PR_TITLE=${PR_TITLE//'${PR_BRANCH}'/"${PR_BRANCH}"}

debug "TEMPLATE_GIT_HASH ${TEMPLATE_GIT_HASH}"
debug "PR_BRANCH ${PR_BRANCH}"
debug "PR_BODY ${PR_BODY}"

# Check if the Ignore File exists inside .github folder or if it doesn't exist at all
if [[ -f ".github/${TEMPLATE_SYNC_IGNORE_FILE_PATH}" || ! -f "${TEMPLATE_SYNC_IGNORE_FILE_PATH}" ]]; then
Expand All @@ -85,6 +93,7 @@ function set_github_action_outputs() {
echo "::group::set gh action outputs"

local pr_branch=$1

info "set github action outputs"

if [[ -z "${GITHUB_RUN_ID}" ]]; then
Expand Down Expand Up @@ -371,7 +380,7 @@ function prechecks() {
warn "skipping prechecks because we force push and pr"
return 0
fi
check_branch_remote_existing "${NEW_BRANCH}"
check_branch_remote_existing "${PR_BRANCH}"

check_if_commit_already_in_hist_graceful_exit "${TEMPLATE_REMOTE_GIT_HASH}"

Expand All @@ -385,8 +394,8 @@ function checkout_branch_and_pull() {

echo "::group::checkout branch and pull"

debug "create new branch from default branch with name ${NEW_BRANCH}"
git checkout -b "${NEW_BRANCH}"
debug "create new branch from default branch with name ${PR_BRANCH}"
git checkout -b "${PR_BRANCH}"
debug "pull changes from template"

pull_source_changes "${SOURCE_REPO}" "${GIT_REMOTE_PULL_PARAMS}"
Expand Down Expand Up @@ -449,7 +458,7 @@ function push_prepare_pr_create_pr() {
echo "::group::push changes and create PR"

cmd_from_yml "prepush"
push "${NEW_BRANCH}" "${IS_FORCE_PUSH_PR}"
push "${PR_BRANCH}" "${IS_FORCE_PUSH_PR}"
cmd_from_yml "prepr"
if [ "$IS_FORCE_PUSH_PR" == true ] ; then
create_or_edit_pr "${PR_TITLE}" "${PR_BODY}" "${UPSTREAM_BRANCH}" "${PR_LABELS}" "${PR_REVIEWERS}"
Expand All @@ -470,4 +479,4 @@ commit

push_prepare_pr_create_pr

set_github_action_outputs "${NEW_BRANCH}"
set_github_action_outputs "${PR_BRANCH}"

0 comments on commit 90dc31a

Please sign in to comment.