test #11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update Post Date | |
on: | |
push: | |
branches: | |
- main # main 브랜치에 Push될 때 실행 | |
jobs: | |
update_post_date: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up time zone (KST) | |
run: | | |
sudo ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime | |
echo "Time zone set to Asia/Seoul" | |
- name: Update post date to latest commit time | |
run: | | |
# 최신 commit 시간 가져오기 (한국 시간 적용) | |
LAST_COMMIT_DATE=$(git log -1 --format=%cd --date=format-local:'%Y-%m-%d %H:%M:%S %z') | |
echo "Latest Commit Date: $LAST_COMMIT_DATE" | |
# `_posts/` 폴더의 모든 `.md` 파일에서 `date:` 값 갱신 | |
find _posts -type f -name "*.md" | while read file; do | |
if grep -q "^date: " "$file"; then | |
sed -i "s/^date: .*/date: \"$LAST_COMMIT_DATE\"/" "$file" | |
else | |
sed -i "1s/^/date: \"$LAST_COMMIT_DATE\"\n/" "$file" | |
fi | |
done | |
- name: Commit and push changes | |
run: | | |
git config --global user.name "GitHub Actions" | |
git config --global user.email "[email protected]" | |
git add _posts/*.md | |
git commit -m "Auto-update post date to latest commit time" || exit 0 | |
git push |