GitBook: No commit message #67
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' | 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" | |
# νμΌ λ΄μ©μ μμ νμΌμ μ μ₯ν ν, νμΌ μ΄λ¦μ λ³κ²½ | |
tmp_file=$(mktemp) | |
cat "$file" > "$tmp_file" | |
mv "$tmp_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 λΈλμΉλ‘ νΈμ |