Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] Add auto sync for WTF-Solidity and WTF-Ethers #191

Merged
merged 13 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/sync-tutorials.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Sync Tutorials
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *' # 每天运行一次
- cron: '0 0 * * 0' // 每周运行一次

jobs:
sync-tutorials:
Expand Down Expand Up @@ -32,6 +32,9 @@ jobs:
echo "::set-output name=changes::$temp"
rm temp.txt

- name: Generate Sidebar
run: npm run generate:sidebar

- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
40 changes: 40 additions & 0 deletions sync-meta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import os
import sys

def find_readme_files(folder):
readme_files = []
for root, dirs, files in os.walk(folder):
for file in files:
if file.lower() == "readme.md":
readme_files.append(os.path.join(root, file))
return readme_files


if __name__ == '__main__':
folder = os.curdir
files = find_readme_files(folder)
# print(files)

insert_before="<LessonProcess meta={require('./meta.json')} />"
append_text="<LessonQuizStart meta={require('./meta.json')} />"
insert_before_target="我最近在重新学"

for file in files:
with open(file,'r') as fd:
lines = fd.readlines()
# Flag
change = False

for i in range(len(lines)):
if insert_before_target in lines[i]:
change = True
lines[i] = lines[i].replace(insert_before_target,"{}\n\n{}".format(
insert_before,
insert_before_target
))
break

if change:
lines.append("\n{}".format(append_text))
with open(file, 'w') as fd:
fd.writelines(lines)
44 changes: 44 additions & 0 deletions sync.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,49 @@
"cp -r WTF-Ethers/0{1..9}_* ./",
"cp -r WTF-Ethers/10_* ./"
]
},
{
"sync": "https://github.com/WTFAcademy/WTF-Ethers.git",
"path": "docs/ethers-102",
"scripts": [
"cp -r WTF-Ethers/1{1..9}_* ./",
"cp -r WTF-Ethers/2{0..6}_* ./"
]
},
{
"sync": "https://github.com/AmazingAng/WTF-Solidity.git",
"path": "docs/solidity-101",
"scripts": [
"cp -r WTF-Solidity/0{1..9}_* ./",
"cp -r WTF-Solidity/1{0..5}_* ./",
"python3 ../../sync-meta.py"
]
},
{
"sync": "https://github.com/AmazingAng/WTF-Solidity.git",
"path": "docs/solidity-102",
"scripts": [
"cp -r WTF-Solidity/1{6..9}_* ./",
"cp -r WTF-Solidity/2{0..9}_* ./",
"cp -r WTF-Solidity/30_* ./",
"python3 ../../sync-meta.py"
]
},
{
"sync": "https://github.com/AmazingAng/WTF-Solidity.git",
"path": "docs/solidity-103",
"scripts": [
"cp -r WTF-Solidity/3{1..9}_* ./",
"cp -r WTF-Solidity/4{0..9}_* ./",
"cp -r WTF-Solidity/5{0..7}_* ./"
]
},
{
"sync": "https://github.com/AmazingAng/WTF-Solidity.git",
"path": "docs/solidity-104",
"scripts": [
"cp -r WTF-Solidity/S0{1..9}_* ./",
"cp -r WTF-Solidity/S1{0..7}_* ./"
]
}
]
14 changes: 10 additions & 4 deletions sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ jq -c '.[]' $CONFIG_FILE | while read -r repo; do
git clone $SYNC_URL $REPO_NAME

# 执行脚本
for SCRIPT in "${SCRIPTS[@]}"; do
eval $SCRIPT
done
while IFS= read -r SCRIPT; do
# echo "$SCRIPT"
eval "$SCRIPT"
done <<< "$SCRIPTS"

# 删除克隆的仓库
rm -rf $REPO_NAME
Expand All @@ -43,8 +44,13 @@ jq -c '.[]' $CONFIG_FILE | while read -r repo; do
fi
done

# 添加更改到 git
# 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"