Skip to content

Commit 9fc618d

Browse files
authored
Refactor GitHub Actions workflow for date updates
1 parent 698b458 commit 9fc618d

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,20 @@ on:
55
branches:
66
- main
77

8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
812
jobs:
913
update-date:
1014
runs-on: ubuntu-latest
1115

1216
steps:
13-
- name: Checkout repository
17+
- name: Checkout PR branch
1418
uses: actions/checkout@v4
1519
with:
1620
fetch-depth: 0
21+
ref: ${{ github.event.pull_request.head.ref }}
1722

1823
- name: Set up Python
1924
uses: actions/setup-python@v4
@@ -27,17 +32,17 @@ jobs:
2732
run: |
2833
git config --global user.email "github-actions[bot]@users.noreply.github.com"
2934
git config --global user.name "github-actions[bot]"
30-
35+
3136
- name: Update last modified date in Markdown files
3237
run: python .github/workflows/update_date.py
3338

34-
- name: Commit changes
39+
- name: Pull (merge) remote changes, commit, and push if needed
3540
env:
3641
TOKEN: ${{ secrets.GITHUB_TOKEN }}
3742
run: |
38-
git fetch origin
39-
git pull --rebase origin ${{ github.event.pull_request.head.ref }} || echo "No rebase needed"
43+
BRANCH="${{ github.event.pull_request.head.ref }}"
44+
git pull origin "$BRANCH" || echo "No merge needed"
4045
git add -A
4146
git commit -m "Update last modified date in Markdown files" || echo "No changes to commit"
4247
git remote set-url origin https://x-access-token:${TOKEN}@github.com/${{ github.repository }}
43-
git push origin HEAD:${{ github.event.pull_request.head.ref }}
48+
git push origin HEAD:"$BRANCH"

0 commit comments

Comments
 (0)