From bc66d54a0f433270e4a3bf4c5dc4faa4450b30b4 Mon Sep 17 00:00:00 2001 From: rrzt <96531856+rrzt@users.noreply.github.com> Date: Mon, 29 Jun 2026 11:29:57 +0800 Subject: [PATCH] Add workflow to sync repos and unzip files This workflow synchronizes multiple GitHub repositories to subfolders and handles unzipping files to the master branch. It runs on a schedule and allows manual triggering. --- .github/workflows/main.yml | 163 +++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..309115d5 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,163 @@ +name: Sync GitHub Repos to Subfolders and unzip to master + +on: + schedule: + - cron: '0 * * * *' # 每小时一次 + - cron: '0 0 * * *' + workflow_dispatch: + +env: + FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true + +concurrency: + group: sync_job_lock + cancel-in-progress: true + +jobs: + sync_and_unzip: + runs-on: ubuntu-latest + + steps: + - name: Checkout default branch + uses: actions/checkout@v4 + + - name: Set up Git config + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + - name: Reset repo + run: | + set -e + DEFAULT_BRANCH=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p') + git fetch origin $DEFAULT_BRANCH + git checkout $DEFAULT_BRANCH || git checkout -b $DEFAULT_BRANCH + git reset --hard origin/$DEFAULT_BRANCH + git clean -fdx + + - name: Fetch subprojects(已修复 submodule) + run: | + echo "==== 开始同步仓库 ====" + declare -A repos=( + [dr]="https://github.com/jak0099/dr.git" + [tvbox]="https://github.com/cluntop/tvbox.git" + [T4]="https://github.com/4TVBox/TVBox.git" + [wzxxcz]="https://github.com/wzxxcz/wzxxcz.git" + [Tomorrow]="https://github.com/tushen6/Tomorrow.git" + [aa999ok]="https://github.com/AA999OK/TVBOX.git" + [sky4726]="https://github.com/sky4726/sk.git" + [ediart]="https://github.com/ediart/tvbox.git" + [lemonguo121]="https://github.com/lemonguo121/BoxRes.git" + [leexuben]="https://github.com/leexuben/TVBOX-merge.git" + [yjl]="https://github.com/YJL20190405/TVBOX.git" + [zheng1976]="https://github.com/zheng197600/tvbox.git" + [FGBLH]="https://github.com/FGBLH/FG.git" + [yihad168]="https://github.com/yihad168/tv.git" + [李在付]="https://github.com/lizaifu2026/df.git" + [cpu_iy3]="https://github.com/IY-CPU/IY.git" + [cpu_iy]="https://gitee.com/cpu-iy/iy.git" + [cpu_iy2]="https://gitee.com/cpu-iy/lib.git" + [reF1nd]="https://github.com/syccccc2333-oss/singbox_config.git" + [bd]="https://github.com/xiaohaozifeifeifei/bd.git" + [catvod]="https://github.com/Darklessing/catvod.git" + [jaychouqq]="https://github.com/wliqi495-create/jaychouqq.git" + + ) + + for name in "${!repos[@]}"; do + echo "→ 同步 $name" + rm -rf "$name" temp-"$name" + + git clone --depth 1 "${repos[$name]}" temp-"$name" || { + echo "❌ 克隆失败 $name,跳过" + continue + } + + mkdir -p "$name" + + # ⭐ 核心修复:不会再复制 .git + rsync -a --exclude='.git' temp-"$name"/ "$name"/ + + rm -rf temp-"$name" + done + + - name: Sync DustinWin _posts + run: | + rm -rf temp-dustinwin + git clone --depth 1 https://github.com/DustinWin/dustinwin.github.io.git temp-dustinwin || exit 0 + mkdir -p _posts + rsync -a --exclude='.git' temp-dustinwin/_posts/ _posts/ + rm -rf temp-dustinwin + + - name: Fix timestamps(安全版) + run: | + dirs="dr tvbox T4 wzxxcz Tomorrow aa999ok sky4726 ediart lemonguo121 leexuben yjl zheng1976 FGBLH yihad168 cpu_iy cpu_iy2 reF1nd bd catvod jaychouqq _posts" + + for d in $dirs; do + [ -d "$d" ] || continue + find "$d" -type f -print0 + done | xargs -0 touch + + - name: Download NewTVBox + run: | + rm -rf gitee-source + mkdir -p gitee-source + + curl -L -o github.zip "https://github.com/PizazzGY/NewTVBox/archive/refs/heads/main.zip" || exit 0 + + if unzip -t github.zip >/dev/null 2>&1; then + unzip -q github.zip + rsync -a --exclude='.git' NewTVBox-main/ gitee-source/ + rm -rf NewTVBox-main github.zip + else + rm -f github.zip + fi + + - name: Commit main + run: | + git add . + git commit -m "Sync all projects" || echo "No changes" + DEFAULT_BRANCH=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p') + git push origin $DEFAULT_BRANCH + + - name: Sync to master + run: | + DEFAULT_BRANCH=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p') + git fetch origin + + if git show-ref --quiet refs/remotes/origin/master; then + git checkout master + else + git checkout -b master + fi + + git reset --hard origin/$DEFAULT_BRANCH + git push origin master --force + + - name: Unzip ZIP + run: | + if [ -d "gitee-source" ]; then + cd gitee-source + for file in *.zip; do + [ -e "$file" ] || continue + unzip -o "$file" + done + cd .. + fi + + - name: Commit unzip + run: | + git add . + git commit -m "Unzip ZIP files" || echo "No changes" + git push origin master --force + + cleanup_runs: + runs-on: ubuntu-latest + needs: sync_and_unzip + steps: + - name: Delete old runs + uses: Mattraks/delete-workflow-runs@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + retain_days: 3 + keep_minimum_runs: 10