-
Notifications
You must be signed in to change notification settings - Fork 4
143 lines (121 loc) · 5 KB
/
Copy pathupstream-sync.yml
File metadata and controls
143 lines (121 loc) · 5 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
name: Upstream Sync
# 当上游 rustfs/rustfs 发布新版本时,自动触发构建
on:
# 定时检查上游版本(每小时一次)
schedule:
- cron: '0 * * * *'
# 支持手动触发
workflow_dispatch:
inputs:
force_build:
description: '强制构建(即使版本未变化)'
required: false
type: boolean
default: false
jobs:
check-upstream:
name: 检查上游版本
runs-on: ubuntu-latest
permissions:
contents: write # 需要写权限来创建 tag
outputs:
has_new_version: ${{ steps.compare.outputs.has_new_version }}
upstream_version: ${{ steps.upstream.outputs.version }}
should_build: ${{ steps.compare.outputs.should_build }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: 获取上游最新版本
id: upstream
run: |
set -o pipefail
# version.rustfs.com/latest.json 是 RustFS 官方最新版本入口
RAW_RESPONSE="$(curl -fsSL 'https://version.rustfs.com/latest.json')"
UPSTREAM_VERSION="$(printf '%s' "$RAW_RESPONSE" | jq -r '.tag // .version // empty')"
if [ -z "$UPSTREAM_VERSION" ] || [ "$UPSTREAM_VERSION" = "null" ]; then
echo "❌ 无法从 latest.json 响应中提取上游版本"
echo "$RAW_RESPONSE"
exit 1
fi
echo "version=$UPSTREAM_VERSION" >> $GITHUB_OUTPUT
echo "✅ 上游最新版本: $UPSTREAM_VERSION"
- name: 获取当前仓库版本
id: current
run: |
# 从最新的 git tag 获取当前版本
CURRENT_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "📦 当前版本: $CURRENT_VERSION"
- name: 比较版本
id: compare
run: |
UPSTREAM="${{ steps.upstream.outputs.version }}"
CURRENT="${{ steps.current.outputs.version }}"
FORCE="${{ github.event.inputs.force_build }}"
UPSTREAM_NORMALIZED="${UPSTREAM#v}"
CURRENT_NORMALIZED="${CURRENT#v}"
echo "上游版本: $UPSTREAM"
echo "当前版本: $CURRENT"
if [ "$FORCE" = "true" ]; then
echo "🔨 强制构建模式"
echo "has_new_version=true" >> $GITHUB_OUTPUT
echo "should_build=true" >> $GITHUB_OUTPUT
elif [ "$UPSTREAM_NORMALIZED" != "$CURRENT_NORMALIZED" ]; then
echo "🆕 发现新版本: $UPSTREAM (当前: $CURRENT)"
echo "has_new_version=true" >> $GITHUB_OUTPUT
echo "should_build=true" >> $GITHUB_OUTPUT
else
echo "✅ 已是最新版本"
echo "has_new_version=false" >> $GITHUB_OUTPUT
echo "should_build=false" >> $GITHUB_OUTPUT
fi
- name: 创建新版本标签
if: steps.compare.outputs.has_new_version == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
UPSTREAM_VERSION="${{ steps.upstream.outputs.version }}"
# 配置 git
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# 检查标签是否已存在
if git rev-parse "$UPSTREAM_VERSION" >/dev/null 2>&1; then
echo "⚠️ 标签 $UPSTREAM_VERSION 已存在,跳过创建"
else
# 创建并推送标签
git tag -a "$UPSTREAM_VERSION" -m "Sync with upstream rustfs/rustfs $UPSTREAM_VERSION"
git push origin "$UPSTREAM_VERSION"
echo "✅ 已创建并推送标签: $UPSTREAM_VERSION"
fi
trigger-build:
name: 触发构建
needs: check-upstream
if: needs.check-upstream.outputs.should_build == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
actions: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: 触发构建工作流
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
UPSTREAM_VERSION="${{ needs.check-upstream.outputs.upstream_version }}"
echo "🚀 触发构建版本: $UPSTREAM_VERSION"
# 直接对新建 tag 触发 build.yml,确保构建上下文与 release tag 一致
gh workflow run build.yml \
--ref "$UPSTREAM_VERSION"
echo "✅ 构建工作流已触发"
- name: 发送通知
if: always()
run: |
UPSTREAM_VERSION="${{ needs.check-upstream.outputs.upstream_version }}"
echo "📢 构建通知:"
echo " - 上游版本: $UPSTREAM_VERSION"
echo " - 工作流状态: ${{ job.status }}"
echo " - 仓库: ${{ github.repository }}"
echo " - 运行ID: ${{ github.run_id }}"