Skip to content

Update Rename and Commit Markdown Files.yml #72

Update Rename and Commit Markdown Files.yml

Update Rename and Commit Markdown Files.yml #72

name: Rename and Commit Markdown Files
on:
push:
branches:
- main
workflow_dispatch:
jobs:
process-markdown:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITBOOKKEY }}
fetch-depth: 1
- name: Set UTF-8 Encoding
run: |
export LC_CTYPE="UTF-8"
- name: Rename and Update Markdown files
run: |
find developLog -type f -name '*.md' | while IFS= read -r file; do
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:]κ°€-힣 ' '_')
sanitized_title=$(echo "$sanitized_title" | sed 's/^_//;s/_$//')
dir=$(dirname "$file")
new_filename="$dir/$sanitized_title.md"
if [ "$file" != "$new_filename" ]; then
if [ -f "$new_filename" ]; then
echo "Removing duplicate $new_filename"
rm "$new_filename"
fi
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