From 4bcbcb73e1121f3a957a913b62e51fbeacb71043 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Thu, 2 Dec 2021 13:29:42 +0100 Subject: [PATCH] .github: Be fork friendly when checking target branches We want to check if target branch exists on the repo on which the action is being run and will get the PR in the end, not on repo with which the SDK came. It's useful for testing github actions on personal forks. --- .../coreos-overlay/.github/workflows/common.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sdk_container/src/third_party/coreos-overlay/.github/workflows/common.sh b/sdk_container/src/third_party/coreos-overlay/.github/workflows/common.sh index d0fa870462..86b54cb327 100644 --- a/sdk_container/src/third_party/coreos-overlay/.github/workflows/common.sh +++ b/sdk_container/src/third_party/coreos-overlay/.github/workflows/common.sh @@ -32,11 +32,18 @@ function get_ebuild_filename() { } function prepare_git_repo() { + local our_remote_url + git config user.name "${BUILDBOT_USERNAME}" git config user.email "${BUILDBOT_USEREMAIL}" git reset --hard HEAD git fetch origin git checkout -B "${BASE_BRANCH}" "origin/${BASE_BRANCH}" + our_remote_url=$(git remote get-url origin) + + # setup overlay repo inside SDK too (be fork friendly) + git -C "${SDK_OUTER_SRCDIR}/third_party/coreos-overlay" remote add our_remote "${our_remote_url}" + git -C "${SDK_OUTER_SRCDIR}/third_party/coreos-overlay" fetch our_remote } # caller needs to set pass a parameter as a branch name to be created. @@ -48,7 +55,7 @@ function checkout_branches() { git -C "${SDK_OUTER_SRCDIR}/scripts" checkout -B "${BASE_BRANCH}" "github/${BASE_BRANCH}" git -C "${SDK_OUTER_SRCDIR}/third_party/portage-stable" checkout -B "${BASE_BRANCH}" "github/${BASE_BRANCH}" - if git -C "${SDK_OUTER_SRCDIR}/third_party/coreos-overlay" show-ref "remotes/github/${TARGET_BRANCH}"; then + if git -C "${SDK_OUTER_SRCDIR}/third_party/coreos-overlay" show-ref "remotes/our_remote/${TARGET_BRANCH}"; then echo "Target branch already exists. exit."; return 1 fi