Skip to content

Commit 48c5aa9

Browse files
committed
feat: Add GitHub Actions workflow for syncing to KernelSU repository.
1 parent bac0a88 commit 48c5aa9

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Sync to KernelSU Repo
2+
3+
# 触发条件
4+
on:
5+
push:
6+
branches:
7+
- main
8+
release:
9+
types: [published]
10+
workflow_dispatch:
11+
12+
jobs:
13+
sync:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout Source Code
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
# 关键修复:禁止 checkout 插件接管 Git 凭据
21+
persist-credentials: false
22+
23+
- name: Sync Source Code and Tags
24+
env:
25+
DEST_REPO: "https://x-access-token:${{ secrets.SYNC_PAT }}@github.com/KernelSU-Modules-Repo/netproxy.git"
26+
run: |
27+
git remote add downstream "$DEST_REPO"
28+
29+
git push downstream --all --force
30+
31+
git push downstream --tags || true
32+
33+
echo "源代码推送完成!已跳过受保护的标签。"
34+
35+
- name: Sync Latest Release
36+
# 仅在发布新 Release 或手动触发时运行此步骤
37+
if: github.event_name == 'release' || github.event_name == 'workflow_dispatch'
38+
env:
39+
GH_TOKEN: ${{ secrets.SYNC_PAT }}
40+
UPSTREAM_REPO: ${{ github.repository }} # 当前仓库 (Fanju6/NetProxy-Magisk)
41+
DEST_REPO: "KernelSU-Modules-Repo/netproxy" # 目标仓库
42+
run: |
43+
# 1. 获取主仓库最新 Release 的标签名
44+
LATEST_TAG=$(gh release view --repo $UPSTREAM_REPO --json tagName -q .tagName)
45+
echo "主仓库最新 Release 标签: $LATEST_TAG"
46+
47+
# 2. 检查下游仓库是否已经存在该 Release
48+
if gh release view $LATEST_TAG --repo $DEST_REPO &>/dev/null; then
49+
echo "下游仓库已存在 Release $LATEST_TAG,无需重复同步。"
50+
else
51+
echo "下游仓库缺失 Release $LATEST_TAG,开始同步..."
52+
53+
# 3. 创建临时目录并下载主仓库的所有附件
54+
mkdir -p release_assets
55+
gh release download $LATEST_TAG --repo $UPSTREAM_REPO --dir release_assets
56+
57+
# 4. 获取主仓库 Release 的标题和更新日志
58+
TITLE=$(gh release view $LATEST_TAG --repo $UPSTREAM_REPO --json name -q .name)
59+
NOTES=$(gh release view $LATEST_TAG --repo $UPSTREAM_REPO --json body -q .body)
60+
61+
# 5. 在下游仓库创建相同的 Release 并上传附件
62+
gh release create $LATEST_TAG ./release_assets/* --repo $DEST_REPO --title "$TITLE" --notes "$NOTES"
63+
64+
echo "Release $LATEST_TAG 同步成功!"
65+
fi

0 commit comments

Comments
 (0)