Skip to content

Commit 9c91423

Browse files
authored
fixing conflict
- Conflict Prevention: The pull before push ensures no conflicts - Safer Commits: Only commits when there are actual changes - Better Branch Management: Ensures operations happen on the correct branch - Consistent with Other Workflows: Matches the pattern from your markdown validation workflow
1 parent 596c7f9 commit 9c91423

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

.github/workflows/update-md-date.yml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
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 changes if any
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
55+
git pull origin "$PR_BRANCH" --no-rebase
56+
57+
# Push all changes
58+
git push origin "$PR_BRANCH"

0 commit comments

Comments
 (0)