Unverified Commit cc303ab1 authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

fix Publisher Workflow to successfully create new branches (#3117)

The publisher tool was unable to create new branches because it
attempted to determine if the current commit was on main. However, this
didn't work! Since main was never checked out (ever) in the repo, there
was no ref to look for. This fixes the issue in (perhaps not the best)
way by simply checking out main first.

The logic was also refactored to have dry run and non-dry run behave in
a way that is closer to identical.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
parent 7a307666
Loading
Loading
Loading
Loading
+41 −32
Original line number Diff line number Diff line
@@ -51,21 +51,30 @@ if [[ "${DRY_RUN}" == "true" ]]; then
fi
echo "release_branch=${branch_name}" >"${output_file}"

if [[ "${DRY_RUN}" == "true" ]]; then
    git push --force origin "HEAD:refs/heads/${branch_name}"
else
commit_sha=$(git rev-parse --short HEAD)
# the git repo is in a weird state because **main has never been checked out**!
# This prevents the `git branch --contains` from working because there is no _local_ ref for main
git checkout main
git checkout "${commit_sha}"
if ! git ls-remote --exit-code --heads origin "${branch_name}"; then
  # The release branch does not exist.
  # We need to make sure that the commit SHA that we are releasing is on `main`.
  git fetch origin main
  echo "Branches: "
  git branch --contains "${commit_sha}"
  git show origin/main | head -n 1
  if git branch --contains "${commit_sha}" | grep main; then
    # We can then create the release branch and set the current commit as its tip
    if [[ "${DRY_RUN}" == "true" ]]; then
      git push --force origin "HEAD:refs/heads/${branch_name}"
    else
      git checkout -b "${branch_name}"
      git push origin "${branch_name}"
    fi
  else
    echo "You must choose a commit from main to create a new release branch!"
    exit 1
  fi
    fi
else
  echo "Patch release ${branch_name} already exists"
fi