Skip to content

Merge pull request #125 from Fanju6/dependabot/github_actions/actions… #13

Merge pull request #125 from Fanju6/dependabot/github_actions/actions…

Merge pull request #125 from Fanju6/dependabot/github_actions/actions… #13

name: Sync to KernelSU Repo
# 触发条件
on:
push:
branches:
- main
release:
types: [published]
workflow_dispatch:
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Checkout Source Code
uses: actions/checkout@v6
with:
fetch-depth: 0
# 关键修复:禁止 checkout 插件接管 Git 凭据
persist-credentials: false
- name: Sync Source Code and Tags
env:
DEST_REPO: "https://x-access-token:${{ secrets.SYNC_PAT }}@github.com/KernelSU-Modules-Repo/netproxy.git"
run: |
git remote add downstream "$DEST_REPO"
git push downstream --all --force
git push downstream --tags || true
echo "源代码推送完成!已跳过受保护的标签。"
- name: Sync Latest Release
# 仅在发布新 Release 或手动触发时运行此步骤
if: github.event_name == 'release' || github.event_name == 'workflow_dispatch'
env:
GH_TOKEN: ${{ secrets.SYNC_PAT }}
UPSTREAM_REPO: ${{ github.repository }} # 当前仓库 (Fanju6/NetProxy-Magisk)
DEST_REPO: "KernelSU-Modules-Repo/netproxy" # 目标仓库
run: |
# 1. 获取主仓库最新 Release 的标签名
LATEST_TAG=$(gh release view --repo $UPSTREAM_REPO --json tagName -q .tagName)
echo "主仓库最新 Release 标签: $LATEST_TAG"
# 2. 检查下游仓库是否已经存在该 Release
if gh release view $LATEST_TAG --repo $DEST_REPO &>/dev/null; then
echo "下游仓库已存在 Release $LATEST_TAG,无需重复同步。"
else
echo "下游仓库缺失 Release $LATEST_TAG,开始同步..."
# 3. 创建临时目录并下载主仓库的所有附件
mkdir -p release_assets
gh release download $LATEST_TAG --repo $UPSTREAM_REPO --dir release_assets
# 4. 获取主仓库 Release 的标题和更新日志
TITLE=$(gh release view $LATEST_TAG --repo $UPSTREAM_REPO --json name -q .name)
NOTES=$(gh release view $LATEST_TAG --repo $UPSTREAM_REPO --json body -q .body)
# 5. 在下游仓库创建相同的 Release 并上传附件
gh release create $LATEST_TAG ./release_assets/* --repo $DEST_REPO --title "$TITLE" --notes "$NOTES"
echo "Release $LATEST_TAG 同步成功!"
fi