Skip to content

Update Rename and Commit Markdown Files.yml #60

Update Rename and Commit Markdown Files.yml

Update Rename and Commit Markdown Files.yml #60

name: Rename and Commit Markdown Files
on:
push:
branches:
- main # main λΈŒλžœμΉ˜μ— ν‘Έμ‹œλ  λ•Œ μ›Œν¬ν”Œλ‘œμš° 트리거
workflow_dispatch: # μˆ˜λ™μœΌλ‘œ μ›Œν¬ν”Œλ‘œμš°λ₯Ό μ‹€ν–‰ν•  수 μžˆλŠ” μ˜΅μ…˜
jobs:
process-markdown:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITBOOKKEY }}
fetch-depth: 0
ref: main
- name: Set UTF-8 Encoding
run: |
export LC_CTYPE="UTF-8" # UTF-8 인코딩을 λͺ…μ‹œμ μœΌλ‘œ μ„€μ •
- name: Rename and Update Markdown files
run: |
find developLog -type f -name '*.md' | while IFS= read -r file; do
# README.md 및 SUMMARY.md νŒŒμΌμ€ κ±΄λ„ˆλœ€
if [[ "$file" == *"README.md" ]] || [[ "$file" == *"SUMMARY.md" ]]; then
echo "Skipping $file"
continue
fi
# 파일 λ‚΄μš©μ˜ 첫 번째 제λͺ© 쀄을 μΆ”μΆœ
title=$(grep -m 1 '^#' "$file")
if [ -n "$title" ]; then
# 곡백은 μœ μ§€ν•˜λ©΄μ„œ 특수 문자만 μ–Έλ”μŠ€μ½”μ–΄λ‘œ λ³€ν™˜ (ν•œκΈ€μ€ κ·ΈλŒ€λ‘œ μœ μ§€)
sanitized_title=$(echo "$title" | tr -c '[:alnum:]κ°€-힣 ' '_')
dir=$(dirname "$file")
new_filename="$dir/$sanitized_title.md"
# 파일 이름이 λ™μΌν•œ κ²½μš°μ—λ„ κ°•μ œλ‘œ μ—…λ°μ΄νŠΈ
if [ "$file" != "$new_filename" ]; then
echo "Renaming $file to $new_filename"
mv "$file" "$new_filename"
else
echo "Updating timestamp for $file"
touch "$file" # 파일의 νƒ€μž„μŠ€νƒ¬ν”„λ₯Ό μ—…λ°μ΄νŠΈ
fi
else
echo "No valid title found in $file, skipping."
fi
done
- name: Commit changes
run: |
git add -A # λͺ¨λ“  변경사항 μΆ”κ°€
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git diff --staged --quiet || git commit -m "Rename and update Markdown files based on h1 titles"
git push https://${{ secrets.GITBOOKKEY }}@github.com/GoldenPearls/gitBook.git # 변경사항을 main 브랜치둜 ν‘Έμ‹œ