Create another.yaml #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |