From 55da686be6a26347e545ecdf89a78394c7b24ed2 Mon Sep 17 00:00:00 2001 From: Guga Date: Fri, 29 Dec 2023 22:11:04 +0900 Subject: [PATCH] =?UTF-8?q?fork=20=EC=8B=9C=20branch=20=EC=9E=90=EB=8F=99?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/add-forked-branch.yml | 45 +++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/add-forked-branch.yml diff --git a/.github/workflows/add-forked-branch.yml b/.github/workflows/add-forked-branch.yml new file mode 100644 index 0000000..9eb0ca8 --- /dev/null +++ b/.github/workflows/add-forked-branch.yml @@ -0,0 +1,45 @@ +name: Create Branch on Fork + +on: + fork: + branches: + - main + +jobs: + create-branch: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Get forked user's ID + id: get-forked-user + run: | + FORKED_USER=$(curl -s ${GITHUB_API_URL}/repos/${{ github.repository }}/forks | jq -r '.[0].owner.login') + echo "Forked user: $FORKED_USER" + echo "::set-output name=forked_user::$FORKED_USER" + env: + GITHUB_API_URL: https://api.github.com + + - name: Create branch on original repository + run: | + FORKED_USER=${{ steps.get-forked-user.outputs.forked_user }} + NEW_BRANCH_NAME="${FORKED_USER}" + + # Set up Git config + git config user.name "GitHub Actions" + git config user.email "actions@github.com" + + # Fetch branches from original repository + git fetch origin + + # Create a new branch + git checkout -b $NEW_BRANCH_NAME origin/main + + # Push the new branch to the original repository + git push origin $NEW_BRANCH_NAME + + env: + FORKED_USER: ${{ steps.get-forked-user.outputs.forked_user }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}