Skip to content

Commit

Permalink
Update branch-name-check.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
arsalan-dev-engineer authored Nov 27, 2024
1 parent 514e2fd commit 88e2873
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions .github/workflows/branch-name-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Enforce Branch Naming Convention with Auto-Increment
on:
push:
branches:
- 'feature/*'
- 'feature/*' # Trigger on push to any feature branch (feature/*)

jobs:
auto_increment:
Expand All @@ -12,25 +12,32 @@ jobs:
- name: Checkout the repository
uses: actions/checkout@v2

- name: Increment branch number
- name: Fetch last feature number and increment
run: |
# Fetch the last used feature number from the file
LAST_NUMBER=$(cat last-feature-number.txt || echo 0)
# Fetch the last used feature number from the file (if it exists)
if [ -f last-feature-number.txt ]; then
LAST_NUMBER=$(cat last-feature-number.txt)
else
LAST_NUMBER=0 # Start from 0 if the file doesn't exist
fi
# Increment the feature number by 1
NEXT_NUMBER=$((LAST_NUMBER + 1))
# Create the branch name based on the incremented number
# Create the new branch name based on the incremented number
BRANCH_NAME="feature-$NEXT_NUMBER"
# Update the last feature number file
echo $NEXT_NUMBER > last-feature-number.txt
echo "Creating new branch with name: $BRANCH_NAME"
# Optionally, create the branch locally and push it
# Create the branch locally and push it to the remote repository
git checkout -b $BRANCH_NAME
git push origin $BRANCH_NAME
# Push the updated last number file
# Commit and push the updated last feature number file
git add last-feature-number.txt
git commit -m "Update feature number"
git push origin main # Or whatever the default branch is
git commit -m "Update feature number to $NEXT_NUMBER"
git push origin main # Push the updated feature number file to the default branch (main)

0 comments on commit 88e2873

Please sign in to comment.