한글까지 _로 바뀌는 것을 변경 #41
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: 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' ! -name 'README.md' ! -name 'SUMMARY.md' | while read file; do | |
# 파일의 디렉토리 구조를 유지하면서 첫 번째 H1 제목을 추출하여 새 파일명 생성 | |
dir=$(dirname "$file") | |
title=$(grep -m 1 '^#' "$file" | sed 's/^# //') | |
if [ -n "$title" ]; then | |
# 공백과 한글을 유지하면서 특수 문자만 언더스코어로 변환 | |
sanitized_title=$(echo "$title" | sed 's/[^[:alnum:]ㄱ-ㅎㅏ-ㅣ가-힣 ]/_/g') | |
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 브랜치로 푸시 |