-
Notifications
You must be signed in to change notification settings - Fork 61
/
sync.sh
executable file
·56 lines (44 loc) · 1.38 KB
/
sync.sh
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
#!/bin/bash
# 读取 sync.json 并解析其内容
CONFIG_FILE="sync.json"
LOG_START="--------------------------------\nSync started at $(date)\n\n"
echo -e $LOG_START >> changes.txt
jq -c '.[]' $CONFIG_FILE | while read -r repo; do
SYNC_URL=$(echo $repo | jq -r '.sync')
TARGET_PATH=$(echo $repo | jq -r '.path')
SCRIPTS=$(echo $repo | jq -r '.scripts[]')
# 进入目标目录
cd $TARGET_PATH || continue
# 克隆仓库
REPO_NAME=$(basename $SYNC_URL .git)
git clone $SYNC_URL $REPO_NAME
# 执行脚本
while IFS= read -r SCRIPT; do
# echo "$SCRIPT"
eval "$SCRIPT"
done <<< "$SCRIPTS"
# 删除克隆的仓库
rm -rf $REPO_NAME
# 返回上级目录
cd - > /dev/null
# 记录更改的文件
CHANGED_FILES=$(git status docs/ --porcelain | awk '{print $2}')
echo $CHANGED_FILES
if [ -n "$CHANGED_FILES" ]; then
CHANGES="Changes in ${TARGET_PATH}:\n${CHANGED_FILES}\n"
fi
# 输出更改的内容到文件
if [ -n "$CHANGES" ]; then
echo -e $CHANGES >> changes.txt # 追加到文件中
echo -e $CHANGES >> temp.txt
fi
done
# generate new sidebar
npm run generate:sidebar
# # 添加更改到 git
git add docs/
git add changes.txt
git add sidebar.json
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git commit -m "Update tutorials" || echo "No changes to commit"