-
Notifications
You must be signed in to change notification settings - Fork 908
427 lines (373 loc) · 15.8 KB
/
release.yml
File metadata and controls
427 lines (373 loc) · 15.8 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
name: Release Astron Agent
on:
push:
tags:
- 'v*.*.*' # 匹配语义版本号 (v1.0.0, v2.1.3, etc.)
- 'v*.*.*-*' # 匹配预发布版本 (v1.0.0-beta.1, v2.1.0-rc.1, etc.)
workflow_dispatch:
inputs:
tag:
description: 'Tag to release (e.g., v1.0.0)'
required: true
type: string
prerelease:
description: 'Mark as pre-release'
required: false
default: false
type: boolean
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: write
packages: write
attestations: write
id-token: write
pull-requests: read
env:
REGISTRY_GHCR: ghcr.io
jobs:
# ============================================================================
# Stage 1: Validation and Preparation
# ============================================================================
prepare-release:
name: 🚀 Prepare Release
runs-on: ubuntu-latest
outputs:
version: ${{ steps.meta.outputs.version }}
is-prerelease: ${{ steps.meta.outputs.is-prerelease }}
has-core-services: ${{ steps.detect.outputs.has-core-services }}
has-console-hub: ${{ steps.detect.outputs.has-console-hub }}
has-console-frontend: ${{ steps.detect.outputs.has-console-frontend }}
changelog: ${{ steps.changelog.outputs.result }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch complete history for changelog generation
- name: Validate tag format
id: meta
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
VERSION="${{ github.event.inputs.tag }}"
IS_PRERELEASE="${{ github.event.inputs.prerelease }}"
else
VERSION=${GITHUB_REF#refs/tags/}
# Check if it's a pre-release version (contains -, alpha, beta, rc, etc.)
if [[ "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
IS_PRERELEASE="false"
else
IS_PRERELEASE="true"
fi
fi
# Validate version format
if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+ ]]; then
echo "❌ Invalid version format: $VERSION"
echo "✅ Correct format: v1.0.0, v1.0.0-beta.1, v1.0.0-rc.1"
exit 1
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "is-prerelease=$IS_PRERELEASE" >> $GITHUB_OUTPUT
echo "🏷️ Release version: $VERSION"
echo "🔖 Pre-release: $IS_PRERELEASE"
- name: Smart project detection
id: detect
run: |
echo "🔍 Detecting Astron Agent components..."
HAS_CORE_SERVICES="false"
HAS_CONSOLE_HUB="false"
HAS_CONSOLE_FRONTEND="false"
# Detect Core service components (based on build-push.yml structure)
CORE_COMPONENTS=("tenant" "memory/database" "plugin/rpa" "plugin/link" "plugin/aitools" "agent" "knowledge" "workflow")
CORE_COUNT=0
for component in "${CORE_COMPONENTS[@]}"; do
if [[ -f "core/${component}/Dockerfile" ]]; then
CORE_COUNT=$((CORE_COUNT + 1))
echo "✅ Core component: core/${component}/"
fi
done
if [[ $CORE_COUNT -gt 0 ]]; then
HAS_CORE_SERVICES="true"
echo "✅ Detected $CORE_COUNT Core service components"
fi
# Detect Console Hub (Java)
if [[ -f "console/backend/hub/pom.xml" && -f "console/backend/hub/Dockerfile" ]]; then
HAS_CONSOLE_HUB="true"
echo "✅ Console Hub: console/backend/hub/ (Java Spring Boot)"
fi
# Detect Console Frontend (React)
if [[ -f "console/frontend/package.json" && -f "console/frontend/Dockerfile" ]]; then
HAS_CONSOLE_FRONTEND="true"
echo "✅ Console Frontend: console/frontend/ (React)"
fi
echo "has-core-services=$HAS_CORE_SERVICES" >> $GITHUB_OUTPUT
echo "has-console-hub=$HAS_CONSOLE_HUB" >> $GITHUB_OUTPUT
echo "has-console-frontend=$HAS_CONSOLE_FRONTEND" >> $GITHUB_OUTPUT
- name: Resolve main release range
id: release-range
run: |
echo "Resolving main branch release range..."
CURRENT_TAG="${{ steps.meta.outputs.version }}"
BASE_BRANCH="origin/main"
git fetch origin main --no-tags
CURRENT_TAG_SHA=$(git rev-list -n 1 "$CURRENT_TAG" 2>/dev/null || git rev-parse HEAD)
CURRENT_TAG_DATE=$(git show -s --format=%cI "$CURRENT_TAG_SHA")
echo "current-tag-date=$CURRENT_TAG_DATE" >> $GITHUB_OUTPUT
PREVIOUS_TAG=$(git tag --merged="$BASE_BRANCH" --sort=-creatordate --format='%(refname:strip=2) %(creatordate:iso-strict)' | awk -v current_tag="$CURRENT_TAG" -v current_date="$CURRENT_TAG_DATE" '$1 != current_tag && $2 < current_date { print $1; exit }')
if [[ -n "$PREVIOUS_TAG" ]]; then
PREVIOUS_TAG_SHA=$(git rev-list -n 1 "$PREVIOUS_TAG")
PREVIOUS_TAG_DATE=$(git show -s --format=%cI "$PREVIOUS_TAG_SHA")
echo "previous-tag=$PREVIOUS_TAG" >> $GITHUB_OUTPUT
echo "previous-tag-date=$PREVIOUS_TAG_DATE" >> $GITHUB_OUTPUT
else
echo "previous-tag=" >> $GITHUB_OUTPUT
echo "previous-tag-date=" >> $GITHUB_OUTPUT
fi
- name: Generate Changelog
id: changelog
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
result-encoding: string
script: |
const previousTag = `${{ steps.release-range.outputs.previous-tag }}`.trim();
const previousTagDate = `${{ steps.release-range.outputs.previous-tag-date }}`.trim();
const currentTagDate = `${{ steps.release-range.outputs.current-tag-date }}`.trim();
const owner = context.repo.owner;
const repo = context.repo.repo;
const pulls = await github.paginate(github.rest.pulls.list, {
owner,
repo,
state: "closed",
base: "main",
sort: "updated",
direction: "desc",
per_page: 100,
});
const mergedPulls = pulls
.filter((pr) => pr.merged_at)
.filter((pr) => !previousTagDate || new Date(pr.merged_at) > new Date(previousTagDate))
.filter((pr) => !currentTagDate || new Date(pr.merged_at) <= new Date(currentTagDate))
.sort((a, b) => new Date(a.merged_at) - new Date(b.merged_at));
const categories = {
features: [],
fixes: [],
improvements: [],
};
const formatPr = (pr) => `- ${pr.title} ([#${pr.number}](${pr.html_url}))`;
for (const pr of mergedPulls) {
const title = pr.title.toLowerCase();
if (/^(feat|feature)(\(|:)/.test(title)) {
categories.features.push(formatPr(pr));
} else if (/^(fix|bugfix)(\(|:)/.test(title)) {
categories.fixes.push(formatPr(pr));
} else {
categories.improvements.push(formatPr(pr));
}
}
const lines = ["## What's Changed", ""];
if (previousTag) {
lines.push(`Based on PRs merged into \`main\` since \`${previousTag}\`.`);
} else {
lines.push("Based on PRs merged into `main`.");
}
lines.push("");
lines.push("### New Features");
lines.push(...(categories.features.length ? categories.features : ["- No new features in this release"]));
lines.push("");
lines.push("### Fixes");
lines.push(...(categories.fixes.length ? categories.fixes : ["- No bug fixes in this release"]));
lines.push("");
lines.push("### Improvements");
lines.push(...(categories.improvements.length ? categories.improvements : ["- No improvements in this release"]));
core.info(`Generated changelog from ${mergedPulls.length} PR(s) merged into main.`);
return lines.join("\n");
# ============================================================================
# Stage 2: Build Docker Images (reuse build-push logic)
# ============================================================================
build-core-services:
name: 🏗️ Build Core Services
runs-on: ubuntu-latest
needs: prepare-release
if: needs.prepare-release.outputs.has-core-services == 'true'
strategy:
matrix:
service:
- { name: "tenant", path: "core/tenant", emoji: "🏢" }
- { name: "database", path: "core/memory/database", emoji: "🧠" }
- { name: "rpa", path: "core/plugin/rpa", emoji: "🤖" }
- { name: "link", path: "core/plugin/link", emoji: "🔗" }
- { name: "aitools", path: "core/plugin/aitools", emoji: "🛠️" }
- { name: "agent", path: "core/agent", emoji: "🤖" }
- { name: "knowledge", path: "core/knowledge", emoji: "📚" }
- { name: "workflow", path: "core/workflow", emoji: "⚡" }
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY_GHCR }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY_GHCR }}/${{ github.repository }}/core-${{ matrix.service.name }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=${{ needs.prepare-release.outputs.version }}
- name: Build and push ${{ matrix.service.emoji }} ${{ matrix.service.name }} image
uses: docker/build-push-action@v5
with:
context: .
file: ./${{ matrix.service.path }}/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ needs.prepare-release.outputs.version }}
GIT_COMMIT=${{ github.sha }}
BUILD_TIME=${{ github.run_id }}
no-cache: true
build-console-hub:
name: ☕ Build Console Hub
runs-on: ubuntu-latest
needs: prepare-release
if: needs.prepare-release.outputs.has-console-hub == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY_GHCR }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY_GHCR }}/${{ github.repository }}/console-hub
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=${{ needs.prepare-release.outputs.version }}
- name: Build and push Console Hub image
uses: docker/build-push-action@v5
with:
context: .
file: ./console/backend/hub/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ needs.prepare-release.outputs.version }}
GIT_COMMIT=${{ github.sha }}
BUILD_TIME=${{ github.run_id }}
no-cache: true
provenance: false
sbom: false
build-console-frontend:
name: 🌐 Build Console Frontend
runs-on: ubuntu-latest
needs: prepare-release
if: needs.prepare-release.outputs.has-console-frontend == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
install: true
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY_GHCR }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY_GHCR }}/${{ github.repository }}/console-frontend
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=${{ needs.prepare-release.outputs.version }}
- name: Build and push Console Frontend image
uses: docker/build-push-action@v5
with:
context: .
file: ./console/frontend/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ needs.prepare-release.outputs.version }}
GIT_COMMIT=${{ github.sha }}
BUILD_TIME=${{ github.run_id }}
no-cache: true
# ============================================================================
# Stage 3: Create GitHub Release
# ============================================================================
create-release:
name: 🎉 Create GitHub Release
runs-on: ubuntu-latest
needs:
- prepare-release
- build-core-services
- build-console-hub
- build-console-frontend
if: always() && needs.prepare-release.result == 'success'
steps:
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.prepare-release.outputs.version }}
name: "Astron Agent ${{ needs.prepare-release.outputs.version }}"
body: ${{ needs.prepare-release.outputs.changelog }}
prerelease: ${{ needs.prepare-release.outputs.is-prerelease }}
generate_release_notes: false
token: ${{ secrets.GITHUB_TOKEN }}
- name: Release Summary
run: |
echo "=== 🎉 Astron Agent Release Summary ==="
echo ""
echo "🏷️ Version: ${{ needs.prepare-release.outputs.version }}"
echo "🔖 Pre-release: ${{ needs.prepare-release.outputs.is-prerelease }}"
echo "📦 Release page: https://github.com/${{ github.repository }}/releases/tag/${{ needs.prepare-release.outputs.version }}"
echo ""
echo "🐳 Docker Image Build Status:"
echo " 🏗️ Core Services: ${{ needs.build-core-services.result }}"
echo " ☕ Console Hub: ${{ needs.build-console-hub.result }}"
echo " 🌐 Console Frontend: ${{ needs.build-console-frontend.result }}"
echo ""
echo "🎯 Quick Start:"
echo "git clone https://github.com/${{ github.repository }}.git"
echo "cd astron-agent"
echo "git checkout ${{ needs.prepare-release.outputs.version }}"
echo "docker-compose up -d"
echo ""
echo "✅ 🚀 Astron Agent Release Complete!"