Rename and update Markdown files based on h1 titles #100
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 Add New Markdown Files | |
on: | |
push: | |
branches: | |
- main # main λΈλμΉμ νΈμλ λ μν¬νλ‘μ° νΈλ¦¬κ±° | |
workflow_dispatch: # μλμΌλ‘ μν¬νλ‘μ°λ₯Ό μ€νν μ μλ μ΅μ | |
jobs: | |
process-markdown: | |
runs-on: ubuntu-latest # μ΅μ Ubuntu νκ²½μμ μν¬νλ‘μ° μ€ν | |
steps: | |
- name: Checkout repository # GitHub 리ν¬μ§ν 리μ μ½λλ₯Ό 체ν¬μμ | |
uses: actions/checkout@v4 # GitHubμμ μ 곡νλ checkout μ‘μ μ μ¬μ© | |
with: | |
token: ${{ secrets.GITBOOKKEY }} # GitHub Personal Access Token μ¬μ© | |
fetch-depth: 1 # μ΅μ 컀λ°λ§ κ°μ Έμ€λλ‘ μ€μ νμ¬ μ±λ₯ μ΅μ ν | |
- name: Set UTF-8 Encoding # UTF-8 μΈμ½λ©μ μ€μ νμ¬ μΈμ½λ© λ¬Έμ λ°©μ§ | |
run: | | |
export LC_CTYPE="UTF-8" # UTF-8 μΈμ½λ© λͺ μμ μΌλ‘ μ€μ | |
- name: Rename and Add New Markdown files # Markdown νμΌμ μ΄λ¦ λ³κ²½ λ° λ³΅μ¬ | |
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 | |
# νμΌ λ΄μ©μ 첫 λ²μ§Έ μ λͺ© μ€(H1)μ μΆμΆνκ³ #μ μ κ±° | |
title=$(grep -m 1 '^#' "$file" | sed 's/^# //') | |
if [ -n "$title" ]; then | |
# νμΌμ λλ ν 리 ꡬ쑰λ₯Ό μ μ§νλ©΄μ μ λͺ©μ κΈ°λ°μΌλ‘ μ νμΌλͺ μμ± | |
dir=$(dirname "$file") | |
new_filename="$dir/$title.md" | |
# λμ νμΌμ΄ μ΄λ―Έ μ‘΄μ¬νλ©΄ κΈ°μ‘΄ νμΌ μμ | |
if [ -e "$new_filename" ]; then | |
echo "File $new_filename already exists. Deleting..." | |
rm "$file" | |
continue | |
fi | |
# νμΌ μ΄λ¦μ΄ λμΌν κ²½μ°μλ κ°μ λ‘ μ λ°μ΄νΈ | |
if [ "$file" != "$new_filename" ]; then | |
echo "Renaming $file to $new_filename" | |
git mv "$file" "$new_filename" # Gitμ΄ μ΄λ¦ λ³κ²½μΌλ‘ μΈμνκ² git mv μ¬μ© | |
else | |
echo "Updating timestamp for $file" | |
touch "$file" # νμΌμ νμμ€ν¬νλ₯Ό μ λ°μ΄νΈ | |
fi | |
else | |
echo "No valid title found in $file, skipping." | |
fi | |
done | |
echo "Rename and update completed successfully!" # μμ μλ£ λ©μμ§ μΆλ ₯ | |
- 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 λΈλμΉλ‘ νΈμ |