-
Notifications
You must be signed in to change notification settings - Fork 9
45 lines (35 loc) · 1.21 KB
/
add-forked-branch.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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 "[email protected]"
# 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 }}