Sync OpenClash_Overwrite Submodule #641
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Sync OpenClash_Overwrite Submodule | |
| on: | |
| schedule: | |
| # 每 2 小时自动检查并同步一次上游最新 Commit | |
| - cron: "0 */2 * * *" | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| concurrency: | |
| group: main-writers | |
| jobs: | |
| sync-submodule: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout main branch | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 | |
| with: | |
| ref: main | |
| fetch-depth: 0 | |
| submodules: true | |
| - name: Update submodule | |
| run: | | |
| submodule_paths=( | |
| "overwrite/OpenClash_Overwrite" | |
| ) | |
| # .gitmodules 中跟踪 main,同步后会指向最新提交 | |
| git submodule update --init --remote --checkout "${submodule_paths[@]}" | |
| - name: Commit and push if needed | |
| run: | | |
| submodule_paths=( | |
| "overwrite/OpenClash_Overwrite" | |
| ) | |
| if [ -n "$(git status --porcelain -- "${submodule_paths[@]}")" ]; then | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add -- "${submodule_paths[@]}" | |
| git commit -m "chore(overwrite): sync OpenClash_Overwrite submodule" | |
| # 使用 pull --rebase 防止多人同时 push 导致的冲突 | |
| git pull --rebase origin main | |
| git push origin HEAD:main | |
| else | |
| echo "No changes to commit." | |
| fi |