Skip to content

Commit

Permalink
chore: fixed merge vs rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
kirrg001 committed Jan 16, 2025
1 parent 0990ec0 commit 9fd26c6
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions .github/workflows/cleanup-branches.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,30 @@ jobs:
git branch -r --merged origin/main | grep -E 'origin/(chore-|docs-|fix-|feat-|test-|refactor-)' | while read -r branch; do
branch_name=$(echo $branch | sed 's|origin/||')
# NOTE: We figure out the date when the branch got merged into main
merge_commit_date=$(git log origin/main --merges --grep="Merge branch '$branch_name'" -1 --format=%ct)
# NOTE: We figure out the last commit from the branch in main
last_commit_in_main=$(git log origin/main --oneline --grep="$branch_name" -1 --format=%H)
# NOTE: That case is actually not possible because we use `--merged`.
if [ -z "$merge_commit_date" ]; then
echo "Branch $branch_name has not been merged yet. Skipping."
continue
fi
# NOTE: If no commit from the branch is found in main, skip it.
if [ -z "$last_commit_in_main" ]; then
echo "Branch $branch_name has no commits in main. Skipping."
continue
fi
# NOTE: We get the date of the last commit from the branch in main.
merge_commit_date=$(git log -1 --format=%ct $last_commit_in_main)
# NOTE: Ensure no new commits are on this branch
last_commit_date=$(git log -1 --format=%ct origin/$branch_name)
# NOTE: Ensure no new commits are on this branch
last_commit_date=$(git log -1 --format=%ct origin/$branch_name)
if [[ $merge_commit_date -lt $threshold_date && $last_commit_date -le $merge_commit_date ]]; then
echo "Deleting branch: $branch_name"
if [[ $merge_commit_date -lt $threshold_date && $last_commit_date -le $merge_commit_date ]]; then
echo "Deleting branch: $branch_name"
if [[ $DRY_RUN = true ]]; then
echo "Dry run: git push origin --delete $branch_name"
else
git push origin --delete $branch_name
fi
if [[ $DRY_RUN = true ]]; then
echo "Dry run: git push origin --delete $branch_name"
else
echo "Skipping branch: $branch_name (either not 60 days old or has new commits)."
git push origin --delete $branch_name
fi
done
else
echo "Skipping branch: $branch_name (either not 60 days old or has new commits)."
fi
done

0 comments on commit 9fd26c6

Please sign in to comment.