Skip to content

Commit

Permalink
Fix entrypointCreatePrivateFork so actions are enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
gtjoseph committed Mar 6, 2024
1 parent 5458536 commit 5064c18
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/CreatePrivateFork.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ jobs:
src_repo: ${{inputs.src_repo}}
dst_repo: ${{inputs.dst_repo}}
github_token: ${{secrets.ASTERISKTEAM_PAT}}

UpdateControlData:
needs: CreatePrivateFork
uses: ./.github/workflows/UpdateControlData.yml
with:
repo: ${{inputs.dst_repo}}
Expand Down
66 changes: 38 additions & 28 deletions scripts/entrypointCreatePrivateFork.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,47 @@ set -e

export GITHUB_TOKEN=${INPUT_GITHUB_TOKEN}
export GH_TOKEN=${INPUT_GITHUB_TOKEN}
export GIT_TOKEN=${INPUT_GITHUB_TOKEN}

SCRIPT_DIR=${GITHUB_WORKSPACE}/$(basename ${GITHUB_ACTION_REPOSITORY})/scripts
REPO_DIR=${GITHUB_WORKSPACE}/$(basename ${INPUT_SRC_REPO})
REPO_DIR=${GITHUB_WORKSPACE}/$(basename ${INPUT_DST_REPO})


cd ${GITHUB_WORKSPACE}

git clone -q -b master --no-tags \
https://x-access-token:${GITHUB_TOKEN}@github.com/asterisk/${INPUT_SRC_REPO} ${INPUT_DST_REPO}

git config --global --add safe.directory $(realpath ${INPUT_DST_REPO})

cd ${INPUT_DST_REPO}

git remote rename origin upstream

# We don't want to accidentally push anything to the public repo before
# we're ready so set the "push" url to "nothing"
git remote set-url --push upstream nothing

# Create the new PRIVATE repository from the clone and push the
# current master branch up.
gh repo create asterisk/${INPUT_DST_REPO} --private --disable-issues \
--disable-wiki --source=. --push

# Set the default repo for subsequent gh commands to the private repo.
gh repo set-default asterisk/${INPUT_DST_REPO}

# We need all the labels so the automation can run.
gh label clone asterisk/${INPUT_SRC_REPO}

# Just like the public repo, we want to disable merge commits
gh repo edit --enable-merge-commit=false

# Create the new repo and set it's parameters
gh repo create asterisk/${INPUT_DST_REPO} --private
gh repo edit asterisk/${INPUT_DST_REPO} --allow-forking=false --enable-auto-merge=false \
--enable-discussions=false --enable-issues=false --enable-merge-commit=false \
--enable-wiki=false

# Do a bare clone of the source repo
git clone --bare https://github.com/asterisk/${INPUT_SRC_REPO}.git ${REPO_DIR}

# Make sure the directory is trusted
git config --global --add safe.directory ${REPO_DIR}

cd ${REPO_DIR}

# Push everything to the new repo
git push --mirror https://x-access-token:${GITHUB_TOKEN}@github.com/asterisk/${INPUT_DST_REPO}.git &> /tmp/push || \
{ cat /tmp/push ; exit 1 ; }

# Make sure "master" is the default branch or actions won't run
gh repo edit asterisk/${INPUT_DST_REPO} --default-branch=master

# Let things settle a bit
sleep 5
declare -i count=0
while [ $count -le 5 ] ; do
gh -R asterisk/${INPUT_DST_REPO} workflow view CreateDocs && break
sleep 5
count+=1
done

# Disable the workflows we never want to run in the private repo
gh -R asterisk/${INPUT_DST_REPO} workflow disable CreateDocs
gh -R asterisk/${INPUT_DST_REPO} workflow disable MergeApproved
gh -R asterisk/${INPUT_DST_REPO} workflow disable NightlyTests
gh -R asterisk/${INPUT_DST_REPO} workflow disable "Nightly Admin"
gh -R asterisk/${INPUT_DST_REPO} workflow disable Releaser

0 comments on commit 5064c18

Please sign in to comment.