Skip to content

Commit

Permalink
ci(config): 🔧 add create and merge ci script
Browse files Browse the repository at this point in the history
add script to merge dev branch into main branch with PR

Ref: #30
  • Loading branch information
anantakumarghosh committed Feb 3, 2024
1 parent 42c57ba commit ea2360e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
46 changes: 46 additions & 0 deletions .github/workflows/auto-create-and-merge-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Auto Create and Merge PR

on:
workflow_dispatch:
branches:
- development
env:
GH_TOKEN: ${{ github.token }}
jobs:
create_and_merge_pr:
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
pull-requests: write

steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: development

- name: Check for changes
id: check_changes
run: |
git fetch origin main:main
changes=$(git diff --name-only main..development)
if [ -z "$changes" ]; then
echo "No changes detected. Exiting."
exit 0
fi
- name: Create PR
run: |
pr_url=$(gh pr create --base main --head development --title "Automated PR - Merge development branch into main Branch" --body "Automated PR created by GitHub Actions." | awk '/created/ {print $5}')
echo "PR URL: $pr_url"
- name: Merge PR
run: |
pr_number=$(echo $pr_url | cut -d '/' -f 7)
- name: Merge PR
run: |
pr_number=$(echo $pr_url | cut -d '/' -f 7)
gh pr merge $pr_number --auto --merge
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if [ "$branch" = "main" ] || [ "$branch" = "development" ]; then
exit 1
fi

if ! [[ $branch =~ $valid_branch_n$branames_regex ]]; then
if ! [[ $branch =~ $valid_branch_names_regex ]]; then
echo "Invalid branch name: $branch; commit rejected"
echo "Please rename your branch to conform to $valid_branch_names_regex pattern."
exit 1
Expand Down

0 comments on commit ea2360e

Please sign in to comment.