Skip to content

Commit c26dfd8

Browse files
authored
Add GitHub Action to update Markdown file dates
1 parent 13ae0f7 commit c26dfd8

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Update Last Modified Date
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
update-date:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
ref: ${{ github.head_ref || github.ref_name }}
22+
23+
- name: Set up Python
24+
uses: actions/setup-python@v4
25+
with:
26+
python-version: '3.x'
27+
28+
- name: Install dependencies
29+
run: pip install python-dateutil
30+
31+
- name: Configure Git
32+
run: |
33+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
34+
git config --global user.name "github-actions[bot]"
35+
36+
- name: Update last modified date in Markdown files
37+
run: python .github/workflows/update_date.py
38+
39+
- name: Commit and merge changes
40+
env:
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
46+
run: |
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)
51+
git add -A
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

Comments
 (0)