From 21429aa69b9408a1a7490ca856d4ad05a6adcab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ge=CF=85=D0=BCj=CF=85=20lee?= <97003348+GoldenPearls@users.noreply.github.com> Date: Thu, 29 Aug 2024 10:58:56 +0900 Subject: [PATCH] Update Rename and Commit Markdown Files.yml --- .../Rename and Commit Markdown Files.yml | 44 +++++-------------- 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/.github/workflows/Rename and Commit Markdown Files.yml b/.github/workflows/Rename and Commit Markdown Files.yml index a7aabcb..6f18eb6 100644 --- a/.github/workflows/Rename and Commit Markdown Files.yml +++ b/.github/workflows/Rename and Commit Markdown Files.yml @@ -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." @@ -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