-
Notifications
You must be signed in to change notification settings - Fork 0
206 lines (180 loc) · 6.64 KB
/
Copy pathupdate-sing-box.yml
File metadata and controls
206 lines (180 loc) · 6.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
name: 自动更新 sing-box eBPF 内核
# 定时跟踪 CHIZI-0618/sing-box 的 testing-ref1nd 分支。
# 上游变化时只构建 Android arm64,直接更新模块内核并触发本仓库 CI。
on:
schedule:
- cron: '*/10 * * * *'
workflow_dispatch:
inputs:
force:
description: 即使上游提交未变化也重新构建
required: false
type: boolean
default: false
permissions:
contents: read
concurrency:
group: update-sing-box
cancel-in-progress: true
env:
UPSTREAM_REPOSITORY: CHIZI-0618/sing-box
UPSTREAM_BRANCH: testing-ref1nd
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
MARKER_FILE: .github/upstream/sing-box-testing-ref1nd.sha
TARGET_FILE: src/module/bin/sing-box
GO_VERSION: 1.25.12
NDK_VERSION: r25c
BUILD_TAGS: with_gvisor,with_quic,with_dhcp,with_utls,with_clash_api,with_tailscale,badlinkname,tfogo_checklinkname0,with_provider,with_ebpf
jobs:
check:
name: 检查上游提交
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.compare.outputs.changed }}
upstream_sha: ${{ steps.compare.outputs.upstream_sha }}
short_sha: ${{ steps.compare.outputs.short_sha }}
steps:
- name: 拉取当前仓库
uses: actions/checkout@v7
with:
ref: ${{ env.DEFAULT_BRANCH }}
persist-credentials: false
- name: 比较上游提交
id: compare
env:
GH_TOKEN: ${{ github.token }}
FORCE_UPDATE: ${{ inputs.force || false }}
shell: bash
run: |
set -euo pipefail
upstream_sha="$(gh api "repos/${UPSTREAM_REPOSITORY}/commits/${UPSTREAM_BRANCH}" --jq '.sha')"
current_sha=""
if [[ -f "$MARKER_FILE" ]]; then
current_sha="$(tr -d '[:space:]' < "$MARKER_FILE")"
fi
changed=false
if [[ "$FORCE_UPDATE" == "true" || "$upstream_sha" != "$current_sha" ]]; then
changed=true
fi
echo "changed=$changed" >> "$GITHUB_OUTPUT"
echo "upstream_sha=$upstream_sha" >> "$GITHUB_OUTPUT"
echo "short_sha=${upstream_sha:0:8}" >> "$GITHUB_OUTPUT"
{
echo "### sing-box 上游检查"
echo "- 当前记录:\`${current_sha:-未记录}\`"
echo "- 上游提交:\`$upstream_sha\`"
echo "- 需要更新:\`$changed\`"
} >> "$GITHUB_STEP_SUMMARY"
build:
name: 构建 Android arm64 eBPF 内核
needs: check
if: needs.check.outputs.changed == 'true'
runs-on: ubuntu-24.04
permissions:
contents: read
steps:
- name: 拉取上游源码
uses: actions/checkout@v7
with:
repository: ${{ env.UPSTREAM_REPOSITORY }}
ref: ${{ needs.check.outputs.upstream_sha }}
fetch-depth: 0
persist-credentials: false
- name: 配置 Go
uses: actions/setup-go@v7
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: 配置 Android NDK
id: setup-ndk
uses: nttld/setup-ndk@v1
with:
ndk-version: ${{ env.NDK_VERSION }}
- name: 构建内核
env:
TAGS: ${{ env.BUILD_TAGS }}
CGO_ENABLED: '1'
GOOS: android
GOARCH: arm64
CC: ${{ steps.setup-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android33-clang
BPF_CLANG: ${{ steps.setup-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android33-clang
run: make build
- name: 检查构建产物
run: |
set -euo pipefail
test -s sing-box
file sing-box | grep -q 'ARM aarch64'
chmod 0755 sing-box
sha256sum sing-box
- name: 上传构建产物
uses: actions/upload-artifact@v7
with:
name: sing-box-android-arm64-${{ needs.check.outputs.short_sha }}
path: sing-box
if-no-files-found: error
retention-days: 1
update:
name: 更新模块并直接提交
needs:
- check
- build
if: needs.check.outputs.changed == 'true'
runs-on: ubuntu-latest
permissions:
actions: write
contents: write
steps:
- name: 拉取当前仓库
uses: actions/checkout@v7
with:
ref: ${{ env.DEFAULT_BRANCH }}
fetch-depth: 0
- name: 下载构建产物
uses: actions/download-artifact@v8
with:
name: sing-box-android-arm64-${{ needs.check.outputs.short_sha }}
path: .artifacts/sing-box
- name: 替换内核并提交
id: commit
env:
UPSTREAM_SHA: ${{ needs.check.outputs.upstream_sha }}
SHORT_SHA: ${{ needs.check.outputs.short_sha }}
shell: bash
run: |
set -euo pipefail
git pull --ff-only origin "$DEFAULT_BRANCH"
install -m 0755 .artifacts/sing-box/sing-box "$TARGET_FILE"
mkdir -p "$(dirname "$MARKER_FILE")"
printf '%s\n' "$UPSTREAM_SHA" > "$MARKER_FILE"
git add -- "$TARGET_FILE" "$MARKER_FILE"
if git diff --cached --quiet; then
echo "updated=false" >> "$GITHUB_OUTPUT"
echo "构建产物与仓库内容一致,无需提交。" >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
git diff --cached --check
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git commit \
-m "chore(core): 更新 sing-box eBPF 内核至 ${SHORT_SHA}" \
-m "上游提交: https://github.com/${UPSTREAM_REPOSITORY}/commit/${UPSTREAM_SHA}"
git push origin "HEAD:${DEFAULT_BRANCH}"
echo "updated=true" >> "$GITHUB_OUTPUT"
echo "commit_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- name: 触发模块持续集成
if: steps.commit.outputs.updated == 'true'
env:
GH_TOKEN: ${{ github.token }}
run: gh workflow run ci.yml --ref "$DEFAULT_BRANCH"
- name: 写入更新摘要
if: steps.commit.outputs.updated == 'true'
env:
COMMIT_SHA: ${{ steps.commit.outputs.commit_sha }}
UPSTREAM_SHA: ${{ needs.check.outputs.upstream_sha }}
run: |
{
echo "### sing-box 内核已更新"
echo "- 上游提交:[$UPSTREAM_SHA](https://github.com/${UPSTREAM_REPOSITORY}/commit/$UPSTREAM_SHA)"
echo "- 本仓库提交:[$COMMIT_SHA](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/commit/$COMMIT_SHA)"
echo "- 后续操作:已触发模块持续集成"
} >> "$GITHUB_STEP_SUMMARY"