-
Notifications
You must be signed in to change notification settings - Fork 0
65 lines (56 loc) · 2.42 KB
/
Rename and Commit Markdown Files.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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 브랜치로 푸시