1818 uses : actions/checkout@v4
1919 with :
2020 fetch-depth : 0
21+ ref : ${{ github.head_ref || github.ref_name }}
2122
2223 - name : Set up Python
2324 uses : actions/setup-python@v4
@@ -35,13 +36,23 @@ jobs:
3536 - name : Update last modified date in Markdown files
3637 run : python .github/workflows/update_date.py
3738
38- - name : Commit changes
39+ - name : Commit and merge changes
3940 env :
40- TOKEN : ${{ secrets.GITHUB_TOKEN }}
41+ PR_BRANCH : ${{ github.head_ref || github.ref_name }}
42+ GIT_AUTHOR_NAME : github-actions[bot]
43+ GIT_AUTHOR_EMAIL : github-actions[bot]@users.noreply.github.com
44+ GIT_COMMITTER_NAME : github-actions[bot]
45+ GIT_COMMITTER_EMAIL : github-actions[bot]@users.noreply.github.com
4146 run : |
42- git fetch origin ${{ github.event.pull_request.head.ref }}
43- git pull --rebase origin ${{ github.event.pull_request.head.ref }} || echo "No rebase needed"
47+ # Ensure we're on the correct branch
48+ git switch -c "$PR_BRANCH" || git switch "$PR_BRANCH"
49+
50+ # Stage and commit all changes (new, modified, deleted)
4451 git add -A
45- git commit -m "Update last modified date in Markdown files" || echo "No changes to commit"
46- git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
47- git push origin HEAD:${{ github.event.pull_request.head.ref }}
52+ git diff --staged --quiet || git commit -m "Update last modified date in Markdown files"
53+
54+ # Pull and merge existing changes from remote
55+ git pull origin "$PR_BRANCH" --no-rebase
56+
57+ # Push all changes to the PR branch
58+ git push origin "$PR_BRANCH"
0 commit comments