Skip to content

Commit 6b830e7

Browse files
authored
Update squash-pr.yml
1 parent e049113 commit 6b830e7

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

.github/workflows/squash-pr.yml

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,21 @@ on:
77
types:
88
- labeled
99

10-
# Grant permission to write to the repository
1110
permissions:
1211
contents: write
1312
pull-requests: read
1413

1514
jobs:
1615
squash:
17-
# Only run if the 'squash-and-merge' label was added
1816
if: github.event.label.name == 'squash-and-merge'
1917
runs-on: ubuntu-latest
2018

2119
steps:
2220
- name: Checkout PR Branch
2321
uses: actions/checkout@v4
2422
with:
25-
# Check out the head of the PR
26-
ref: ${{ github.event.pull_request.head.sha }}
27-
# Fetch all history so we can rebase
23+
# CORRECT: Check out the branch name, not the SHA
24+
ref: ${{ github.event.pull_request.head.ref }}
2825
fetch-depth: 0
2926

3027
- name: Configure Git
@@ -34,21 +31,16 @@ jobs:
3431
3532
- name: Squash Commits
3633
run: |
37-
# The PR's target branch (e.g., 'main' or 'develop')
34+
set -e # Exit on error
3835
BASE_BRANCH=${{ github.event.pull_request.base.ref }}
39-
40-
# Get the commit hash of the merge base
4136
MERGE_BASE=$(git merge-base origin/$BASE_BRANCH HEAD)
42-
4337
echo "Squashing commits down to the merge base: $MERGE_BASE"
44-
45-
# Perform the soft reset to un-commit changes
4638
git reset --soft $MERGE_BASE
47-
48-
# Commit all the changes as a single commit using the PR title
49-
git commit -m "${{ github.event.pull_request.title }}"
39+
# Use the PR title and body for the commit message
40+
git commit -m "${{ github.event.pull_request.title }}" -m "${{ github.event.pull_request.body }}"
5041
5142
- name: Force-Push to PR Branch
5243
run: |
53-
# Push the new squashed commit, overwriting the previous history
54-
git push --force
44+
# CORRECT: Explicitly specify the branch to push to
45+
BRANCH_NAME=${{ github.event.pull_request.head.ref }}
46+
git push --force origin HEAD:$BRANCH_NAME

0 commit comments

Comments
 (0)