Skip to content

Commit

Permalink
Update Rename and Commit Markdown Files.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
GoldenPearls authored Aug 29, 2024
1 parent 53942fb commit 21429aa
Showing 1 changed file with 12 additions and 32 deletions.
44 changes: 12 additions & 32 deletions .github/workflows/Rename and Commit Markdown Files.yml
Original file line number Diff line number Diff line change
@@ -1,61 +1,41 @@
name: Rename and Commit Markdown Files

on:
push:
branches:
- main # main λΈŒλžœμΉ˜μ— ν‘Έμ‹œλ  λ•Œ μ›Œν¬ν”Œλ‘œμš° 트리거
workflow_dispatch: # μˆ˜λ™μœΌλ‘œ μ›Œν¬ν”Œλ‘œμš°λ₯Ό μ‹€ν–‰ν•  수 μžˆλŠ” μ˜΅μ…˜
- 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
token: ${{ secrets.GITBOOKKEY }}
fetch-depth: 0
ref: main

- name: Set UTF-8 Encoding
run: |
export LC_CTYPE="UTF-8" # UTF-8 인코딩을 λͺ…μ‹œμ μœΌλ‘œ μ„€μ •
export LC_CTYPE="UTF-8"
- name: Rename and Update Markdown files
run: |
for file in $(find developLog -type f -name '*.md'); do
# README.md 및 SUMMARY.md νŒŒμΌμ€ κ±΄λ„ˆλœ€
if [[ "$file" == *"README.md" ]] || [[ "$file" == *"SUMMARY.md" ]]; then
echo "Skipping $file"
continue # λ‹€μŒ 파일둜 진행
fi
# 파일 λ‚΄μš©μ˜ 첫 번째 제λͺ© 쀄을 μΆ”μΆœ
find developLog/* -type f -name '*.md' ! -name 'README.md' ! -name 'SUMMARY.md' | while read file; do
title=$(grep -m 1 '^#' "$file" | sed 's/^# //')
if [ -n "$title" ]; then
# 파일의 디렉토리 ꡬ쑰λ₯Ό μœ μ§€ν•˜λ©΄μ„œ 제λͺ©μ„ 기반으둜 μƒˆ 파일λͺ… 생성
dir=$(dirname "$file")
new_filename="$dir/$title.md"
new_dir=$(dirname "$new_filename")
mkdir -p "$new_dir"
# λ™μΌν•œ 파일λͺ…이 μ‘΄μž¬ν•˜λŠ”μ§€ 확인
if [ -e "$new_filename" ]; then
echo "File $new_filename already exists. Skipping..."
continue
fi
# λŒ€μƒ 디렉토리가 μ—†μœΌλ©΄ 생성
mkdir -p "$dir"
# 파일 이름이 λ™μΌν•œ κ²½μš°μ—λ„ κ°•μ œλ‘œ μ—…λ°μ΄νŠΈ
if [ "$file" != "$new_filename" ]; then
echo "Renaming $file to $new_filename"
mv "$file" "$new_filename"
else
echo "Updating timestamp for $file"
touch "$file" # 파일의 νƒ€μž„μŠ€νƒ¬ν”„λ₯Ό μ—…λ°μ΄νŠΈ
touch "$file"
fi
else
echo "No valid title found in $file, skipping."
Expand All @@ -64,8 +44,8 @@ jobs:
- name: Commit changes
run: |
git add . # λͺ¨λ“  파일 μΆ”κ°€
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 브랜치둜 ν‘Έμ‹œ
git push https://${{ secrets.GITBOOKKEY }}@github.com/GoldenPearls/gitBook.git

0 comments on commit 21429aa

Please sign in to comment.