-
Notifications
You must be signed in to change notification settings - Fork 2
28 lines (24 loc) · 952 Bytes
/
branch.yaml
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
name: Create Branch if Not Present
on:
push:
branches:
- main # Change this to your base branch
jobs:
create-branch:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Check if branch exists
id: check-branch
run: |
BRANCH_NAME=main # Change this to the branch you want to create
API_URL="https://api.github.com/repos/${{ github.repository }}/branches/${BRANCH_NAME}"
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" "$API_URL")
echo "::set-output name=branch_exists::$(if [ $RESPONSE -eq 200 ]; then echo 'true'; else echo 'false'; fi)"
- name: Create branch if not present
if: steps.check-branch.outputs.branch_exists == 'false'
run: |
BRANCH_NAME=main # Change this to the branch you want to create
git checkout -b $BRANCH_NAME
git push origin $BRANCH_NAME