Repository navigation
102 lines (95 loc) · 3.75 KB
/
Copy pathsync-upstream.yml
File metadata and controls
102 lines (95 loc) · 3.75 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
name: Sync upstream
# 自建 fork 有意停留在 v3.15.1 基线:不再自动跟随上游。
# 需要合并某个上游版本时,从这里手动触发,或按下方命令在本地操作。
on:
workflow_dispatch:
permissions:
contents: read
jobs:
check:
name: Check upstream tags
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Compare upstream tags
id: upstream
shell: bash
run: |
set -euo pipefail
# 版本格式为 <私有版本>+<官方基线>,只和 + 之后的上游稳定 tag 比较。
base="$(node -p "require('./package.json').version.split('+')[1]")"
if [ -z "$base" ]; then
echo "package.json version is missing the +<upstream-base> part" >&2
exit 1
fi
latest="$(git ls-remote --tags --refs https://github.com/zai-org/ZCode.git 'v*' \
| sed 's#.*refs/tags/##' \
| grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' \
| sort -V \
| tail -n1)"
if [ -z "$latest" ]; then
echo "No stable upstream tag found" >&2
exit 1
fi
echo "base=$base" >> "$GITHUB_OUTPUT"
echo "latest=$latest" >> "$GITHUB_OUTPUT"
echo "[upstream] base=v$base latest=$latest"
if [ "$latest" = "v$base" ]; then
echo "new=false" >> "$GITHUB_OUTPUT"
else
echo "new=true" >> "$GITHUB_OUTPUT"
fi
- name: Notify Feishu (optional)
if: steps.upstream.outputs.new == 'true'
shell: bash
env:
FEISHU_WEBHOOK: ${{ secrets.FEISHU_WEBHOOK }}
LATEST: ${{ steps.upstream.outputs.latest }}
BASE: ${{ steps.upstream.outputs.base }}
run: |
if [ -z "${FEISHU_WEBHOOK:-}" ]; then
echo "FEISHU_WEBHOOK not configured; skipping Feishu notification"
exit 0
fi
curl -fsS -X POST -H "Content-Type: application/json" \
-d "{\"msg_type\":\"text\",\"content\":{\"text\":\"ZCode 上游出现新 tag $LATEST(当前基线 v$BASE),需要合并时请手动处理。\"}}" \
"$FEISHU_WEBHOOK" || echo "Feishu notification failed"
# 这个 fork 有意停留在当前基线,所以发现新 tag 只记录信息,不判失败:
# 每天一次红色 X 只会淹没真正的构建问题。
- name: Report new upstream tag
if: steps.upstream.outputs.new == 'true'
shell: bash
env:
LATEST: ${{ steps.upstream.outputs.latest }}
BASE: ${{ steps.upstream.outputs.base }}
run: |
{
echo "### Upstream has a newer tag (informational)"
echo ""
echo "- Current base: v$BASE"
echo "- Latest upstream tag: $LATEST"
echo ""
echo "This fork intentionally stays on v$BASE. Merge only when you want to."
echo ""
echo "Commands:"
echo '```bash'
echo "git fetch upstream --tags"
echo "git log --oneline v$BASE..$LATEST"
echo "git diff --stat v$BASE..$LATEST"
echo '```'
echo ""
echo "Do not use GitHub's Sync fork; it would overwrite self-host commits."
} >> "$GITHUB_STEP_SUMMARY"
echo "::notice::Upstream tag $LATEST is newer than base v$BASE. Informational only; merge manually when desired."
- name: Report up-to-date
if: steps.upstream.outputs.new == 'false'
shell: bash
run: |
{
echo "### Upstream sync"
echo ""
echo "Current base matches the latest upstream stable tag."
} >> "$GITHUB_STEP_SUMMARY"