Skip to content

Commit 8807639

Browse files
Create fix_utils_path.yml
1 parent 6cc605f commit 8807639

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Fix UTILS path in notebooks
2+
3+
on:
4+
workflow_dispatch: # 수동 실행
5+
6+
jobs:
7+
fix-notebooks:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
12+
- name: Run fix script
13+
run: |
14+
python3 - <<'EOF'
15+
import os, json
16+
17+
CHAPTERS_DIR = "./chapters"
18+
19+
OLD_LINES = [
20+
'# 서브폴더 지정 (utils, figures 등)\n',
21+
'UTILS = f"{BASE}/utils"\n',
22+
'FIGS = f"{BASE}/figures"'
23+
]
24+
25+
NEW_LINES = [
26+
'# 서브폴더 지정\n',
27+
'UTILS = "/content/resources/utils" # git clone 경로\n',
28+
'FIGS = os.path.join(BASE, "figures")\n',
29+
'os.makedirs(FIGS, exist_ok=True)'
30+
]
31+
32+
OLD_STR = "".join(OLD_LINES)
33+
NEW_STR = "".join(NEW_LINES)
34+
35+
for fname in sorted(os.listdir(CHAPTERS_DIR)):
36+
if not fname.endswith(".ipynb"):
37+
continue
38+
fpath = os.path.join(CHAPTERS_DIR, fname)
39+
with open(fpath, "r", encoding="utf-8") as f:
40+
nb = json.load(f)
41+
42+
changed = False
43+
for cell in nb["cells"]:
44+
source = "".join(cell["source"])
45+
if OLD_STR in source:
46+
new_source = source.replace(OLD_STR, NEW_STR)
47+
cell["source"] = [line + "\n" for line in new_source.split("\n")]
48+
cell["source"][-1] = cell["source"][-1].rstrip("\n")
49+
changed = True
50+
51+
if changed:
52+
with open(fpath, "w", encoding="utf-8") as f:
53+
json.dump(nb, f, ensure_ascii=False, indent=1)
54+
print(f"✅ 수정됨: {fname}")
55+
else:
56+
print(f"⏭️ 패턴 없음: {fname}")
57+
EOF
58+
59+
- name: Commit and push
60+
run: |
61+
git config user.email "actions@github.com"
62+
git config user.name "GitHub Actions"
63+
git add chapters/
64+
git commit -m "fix: UTILS 경로를 git clone 경로로 일괄 수정" || echo "변경사항 없음"
65+
git push

0 commit comments

Comments
 (0)