88 - labeled
99
1010permissions :
11- contents : write
11+ # Permissions are still useful for the initial checkout and reading PR data
12+ contents : read
1213 pull-requests : read
1314
1415jobs :
@@ -17,30 +18,51 @@ jobs:
1718 runs-on : ubuntu-latest
1819
1920 steps :
21+ # Step 1: Checkout using the PAT to have write access later
2022 - name : Checkout PR Branch
2123 uses : actions/checkout@v4
2224 with :
23- # CORRECT: Check out the branch name, not the SHA
25+ # Use the PAT so we can push back to the repo
26+ token : ${{ secrets.ACTIONS_PAT }}
2427 ref : ${{ github.event.pull_request.head.ref }}
2528 fetch-depth : 0
2629
27- - name : Configure Git
30+ # Step 2: Configure git with the user associated with the PAT
31+ # This makes the commit appear from a user, not a bot
32+ - name : Configure Git User
2833 run : |
29- git config user.name "github-actions[bot]"
30- git config user.email "github-actions[bot]@users.noreply.github.com"
34+ # Use a real user's info (or a dedicated bot user)
35+ # to ensure other actions are triggered.
36+ git config user.name "Your Name or Bot Name"
37+ git config user.email "your-email@example.com"
3138
32- - name : Squash Commits
39+ # Step 3: Squash commits and create a detailed commit message
40+ - name : Squash Commits and Generate Message
41+ id : squash
3342 run : |
3443 set -e # Exit on error
3544 BASE_BRANCH=${{ github.event.pull_request.base.ref }}
3645 MERGE_BASE=$(git merge-base origin/$BASE_BRANCH HEAD)
37- echo "Squashing commits down to the merge base: $MERGE_BASE"
46+
47+ # Get the subject of the very first commit for the new title
48+ COMMIT_SUBJECT=$(git log --reverse --format=%s ${{ env.MERGE_BASE }}..HEAD | head -n 1)
49+
50+ # Get a formatted list of all commit messages for the new body
51+ COMMIT_BODY=$(git log --format="* %s (%h)" ${{ env.MERGE_BASE }}..HEAD)
52+
53+ echo "New commit subject: $COMMIT_SUBJECT"
54+
55+ # Perform the squash
3856 git reset --soft $MERGE_BASE
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 }}"
57+
58+ # Create the new commit with the detailed message
59+ git commit -m "$COMMIT_SUBJECT" -m "$COMMIT_BODY"
60+ env :
61+ MERGE_BASE : ${{ steps.squash.outputs.merge_base }}
4162
63+
64+ # Step 4: Force-push the squashed commit
4265 - name : Force-Push to PR Branch
4366 run : |
44- # CORRECT: Explicitly specify the branch to push to
4567 BRANCH_NAME=${{ github.event.pull_request.head.ref }}
4668 git push --force origin HEAD:$BRANCH_NAME
0 commit comments