Skip to content

Commit 4028542

Browse files
committed
rss1102/ci/release-workflow: 添加版本变更自动发布 CI
- 新增 build-reusable.yml: 可复用的单平台构建 workflow - 重构 build-multi-platform.yml: 改为调用 reusable workflow - 新增 release.yml: 检测版本变更后自动打 tag、构建、创建 Release 并上传产物
1 parent b5e944e commit 4028542

3 files changed

Lines changed: 211 additions & 101 deletions

File tree

.github/workflows/build-multi-platform.yml

Lines changed: 27 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -6,108 +6,34 @@ on:
66

77
jobs:
88
build-macos-intel:
9-
runs-on: macos-latest
10-
outputs:
11-
artifact_id: ${{ steps.upload.outputs.artifact-id }}
12-
artifact_url: ${{ steps.upload.outputs.artifact-url }}
13-
steps:
14-
- uses: actions/checkout@v6
15-
- name: Setup Flutter
16-
uses: subosito/flutter-action@v2
17-
with:
18-
flutter-version: '3.32.0'
19-
- name: Install dependencies
20-
run: flutter pub get
21-
- name: Build macOS Intel
22-
run: dart compile exe bin/main.dart -o api_tool_macos_intel
23-
- name: Verify binary
24-
run: |
25-
git clone --depth 1 --branch develop https://github.com/Tencent/tdesign-flutter.git
26-
dart run .github/scripts/cross_platform_verify.dart tdesign-flutter api_tool_macos_intel
27-
- name: Upload Artifact
28-
id: upload
29-
uses: actions/upload-artifact@v4
30-
with:
31-
name: api_tool_macos_intel
32-
path: api_tool_macos_intel
9+
uses: ./.github/workflows/build-reusable.yml
10+
with:
11+
runner: macos-latest
12+
artifact-name: api_tool_macos_intel
13+
binary-name: api_tool_macos_intel
3314

3415
build-macos-arm64:
35-
runs-on: macos-latest
36-
outputs:
37-
artifact_id: ${{ steps.upload.outputs.artifact-id }}
38-
artifact_url: ${{ steps.upload.outputs.artifact-url }}
39-
steps:
40-
- uses: actions/checkout@v6
41-
- name: Setup Flutter
42-
uses: subosito/flutter-action@v2
43-
with:
44-
flutter-version: '3.32.0'
45-
- name: Install dependencies
46-
run: flutter pub get
47-
- name: Build macOS ARM64
48-
run: dart compile exe bin/main.dart -o api_tool_macos_arm64 --target-os=macos --target-arch=arm64
49-
- name: Verify binary
50-
run: |
51-
git clone --depth 1 --branch develop https://github.com/Tencent/tdesign-flutter.git
52-
dart run .github/scripts/cross_platform_verify.dart tdesign-flutter api_tool_macos_arm64
53-
- name: Upload Artifact
54-
id: upload
55-
uses: actions/upload-artifact@v4
56-
with:
57-
name: api_tool_macos_arm64
58-
path: api_tool_macos_arm64
16+
uses: ./.github/workflows/build-reusable.yml
17+
with:
18+
runner: macos-latest
19+
artifact-name: api_tool_macos_arm64
20+
binary-name: api_tool_macos_arm64
21+
compile-args: '--target-os=macos --target-arch=arm64'
5922

6023
build-linux-x64:
61-
runs-on: ubuntu-latest
62-
outputs:
63-
artifact_id: ${{ steps.upload.outputs.artifact-id }}
64-
artifact_url: ${{ steps.upload.outputs.artifact-url }}
65-
steps:
66-
- uses: actions/checkout@v6
67-
- name: Setup Flutter
68-
uses: subosito/flutter-action@v2
69-
with:
70-
flutter-version: '3.32.0'
71-
- name: Install dependencies
72-
run: flutter pub get
73-
- name: Build Linux x64
74-
run: dart compile exe bin/main.dart -o api_tool_linux --target-arch=x64
75-
- name: Verify binary
76-
run: |
77-
git clone --depth 1 --branch develop https://github.com/Tencent/tdesign-flutter.git
78-
dart run .github/scripts/cross_platform_verify.dart tdesign-flutter api_tool_linux
79-
- name: Upload Artifact
80-
id: upload
81-
uses: actions/upload-artifact@v4
82-
with:
83-
name: api_tool_linux
84-
path: api_tool_linux
24+
uses: ./.github/workflows/build-reusable.yml
25+
with:
26+
runner: ubuntu-latest
27+
artifact-name: api_tool_linux
28+
binary-name: api_tool_linux
29+
compile-args: '--target-arch=x64'
8530

8631
build-windows-x64:
87-
runs-on: windows-latest
88-
outputs:
89-
artifact_id: ${{ steps.upload.outputs.artifact-id }}
90-
artifact_url: ${{ steps.upload.outputs.artifact-url }}
91-
steps:
92-
- uses: actions/checkout@v6
93-
- name: Setup Flutter
94-
uses: subosito/flutter-action@v2
95-
with:
96-
flutter-version: '3.32.0'
97-
- name: Install dependencies
98-
run: flutter pub get
99-
- name: Build Windows x64
100-
run: dart compile exe bin/main.dart -o api_tool_windows.exe
101-
- name: Verify binary
102-
run: |
103-
git clone --depth 1 --branch develop https://github.com/Tencent/tdesign-flutter.git
104-
dart run .github/scripts/cross_platform_verify.dart tdesign-flutter api_tool_windows.exe
105-
- name: Upload Artifact
106-
id: upload
107-
uses: actions/upload-artifact@v4
108-
with:
109-
name: api_tool_windows
110-
path: api_tool_windows.exe
32+
uses: ./.github/workflows/build-reusable.yml
33+
with:
34+
runner: windows-latest
35+
artifact-name: api_tool_windows
36+
binary-name: api_tool_windows.exe
11137

11238
comment-on-pr:
11339
needs: [build-macos-intel, build-macos-arm64, build-linux-x64, build-windows-x64]
@@ -120,16 +46,16 @@ jobs:
12046
issue-number: ${{ github.event.pull_request.number }}
12147
comment-author: 'github-actions[bot]'
12248
body-includes: 编译完成,产物如下
123-
49+
12450
- name: Create or Update PR Comment
12551
uses: peter-evans/create-or-update-comment@v4
12652
with:
12753
comment-id: ${{ steps.find-comment.outputs.comment-id }}
12854
issue-number: ${{ github.event.pull_request.number }}
12955
body: |
13056
✅ 编译完成,产物如下:
131-
- [api_tool_macos_intel](${{ needs.build-macos-intel.outputs.artifact_url }})
132-
- [api_tool_macos_arm64](${{ needs.build-macos-arm64.outputs.artifact_url }})
133-
- [api_tool_linux](${{ needs.build-linux-x64.outputs.artifact_url }})
134-
- [api_tool_windows](${{ needs.build-windows-x64.outputs.artifact_url }})
57+
- [api_tool_macos_intel](${{ needs.build-macos-intel.outputs.artifact-url }})
58+
- [api_tool_macos_arm64](${{ needs.build-macos-arm64.outputs.artifact-url }})
59+
- [api_tool_linux](${{ needs.build-linux-x64.outputs.artifact-url }})
60+
- [api_tool_windows](${{ needs.build-windows-x64.outputs.artifact-url }})
13561
edit-mode: replace
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Build Single Platform
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
runner:
7+
description: 'GitHub Actions runner (e.g. macos-latest, ubuntu-latest, windows-latest)'
8+
required: true
9+
type: string
10+
artifact-name:
11+
description: 'Name for the uploaded artifact'
12+
required: true
13+
type: string
14+
binary-name:
15+
description: 'Output binary file name'
16+
required: true
17+
type: string
18+
compile-args:
19+
description: 'Extra arguments for dart compile exe'
20+
required: false
21+
type: string
22+
default: ''
23+
outputs:
24+
artifact-id:
25+
description: 'Uploaded artifact ID'
26+
value: ${{ jobs.build.outputs.artifact_id }}
27+
artifact-url:
28+
description: 'Uploaded artifact URL'
29+
value: ${{ jobs.build.outputs.artifact_url }}
30+
31+
jobs:
32+
build:
33+
runs-on: ${{ inputs.runner }}
34+
outputs:
35+
artifact_id: ${{ steps.upload.outputs.artifact-id }}
36+
artifact_url: ${{ steps.upload.outputs.artifact-url }}
37+
steps:
38+
- uses: actions/checkout@v6
39+
40+
- name: Setup Flutter
41+
uses: subosito/flutter-action@v2
42+
with:
43+
flutter-version: '3.32.0'
44+
45+
- name: Install dependencies
46+
run: flutter pub get
47+
48+
- name: Build binary
49+
run: dart compile exe bin/main.dart -o ${{ inputs.binary-name }} ${{ inputs.compile-args }}
50+
51+
- name: Verify binary
52+
run: |
53+
git clone --depth 1 --branch develop https://github.com/Tencent/tdesign-flutter.git
54+
dart run .github/scripts/cross_platform_verify.dart tdesign-flutter ${{ inputs.binary-name }}
55+
56+
- name: Upload Artifact
57+
id: upload
58+
uses: actions/upload-artifact@v4
59+
with:
60+
name: ${{ inputs.artifact-name }}
61+
path: ${{ inputs.binary-name }}

.github/workflows/release.yml

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
name: Release on Version Change
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- 'pubspec.yaml'
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
check-version:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
version_changed: ${{ steps.check.outputs.changed }}
17+
new_version: ${{ steps.check.outputs.version }}
18+
steps:
19+
- uses: actions/checkout@v6
20+
with:
21+
fetch-depth: 2
22+
23+
- name: Check version change
24+
id: check
25+
run: |
26+
# 获取当前版本
27+
CURRENT_VERSION=$(grep '^version:' pubspec.yaml | head -1 | awk '{print $2}')
28+
echo "Current version: $CURRENT_VERSION"
29+
30+
# 获取上一次提交的版本
31+
PREVIOUS_VERSION=$(git show HEAD~1:pubspec.yaml 2>/dev/null | grep '^version:' | head -1 | awk '{print $2}' || echo "")
32+
echo "Previous version: $PREVIOUS_VERSION"
33+
34+
# 对比版本
35+
if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then
36+
echo "Version changed: $PREVIOUS_VERSION -> $CURRENT_VERSION"
37+
echo "changed=true" >> $GITHUB_OUTPUT
38+
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
39+
else
40+
echo "Version not changed, skipping release."
41+
echo "changed=false" >> $GITHUB_OUTPUT
42+
fi
43+
44+
- name: Check tag exists
45+
if: steps.check.outputs.changed == 'true'
46+
id: tag-check
47+
run: |
48+
TAG="v${{ steps.check.outputs.version }}"
49+
if git ls-remote --tags origin | grep -q "refs/tags/$TAG$"; then
50+
echo "Tag $TAG already exists, skipping release."
51+
echo "changed=false" >> $GITHUB_OUTPUT
52+
fi
53+
54+
create-tag:
55+
needs: check-version
56+
if: needs.check-version.outputs.version_changed == 'true'
57+
runs-on: ubuntu-latest
58+
steps:
59+
- uses: actions/checkout@v6
60+
61+
- name: Create and push tag
62+
run: |
63+
TAG="v${{ needs.check-version.outputs.new_version }}"
64+
git tag "$TAG"
65+
git push origin "$TAG"
66+
67+
build-macos-intel:
68+
needs: create-tag
69+
uses: ./.github/workflows/build-reusable.yml
70+
with:
71+
runner: macos-latest
72+
artifact-name: api_tool_macos_intel
73+
binary-name: api_tool_macos_intel
74+
75+
build-macos-arm64:
76+
needs: create-tag
77+
uses: ./.github/workflows/build-reusable.yml
78+
with:
79+
runner: macos-latest
80+
artifact-name: api_tool_macos_arm64
81+
binary-name: api_tool_macos_arm64
82+
compile-args: '--target-os=macos --target-arch=arm64'
83+
84+
build-linux-x64:
85+
needs: create-tag
86+
uses: ./.github/workflows/build-reusable.yml
87+
with:
88+
runner: ubuntu-latest
89+
artifact-name: api_tool_linux
90+
binary-name: api_tool_linux
91+
compile-args: '--target-arch=x64'
92+
93+
build-windows-x64:
94+
needs: create-tag
95+
uses: ./.github/workflows/build-reusable.yml
96+
with:
97+
runner: windows-latest
98+
artifact-name: api_tool_windows
99+
binary-name: api_tool_windows.exe
100+
101+
create-release:
102+
needs: [check-version, create-tag, build-macos-intel, build-macos-arm64, build-linux-x64, build-windows-x64]
103+
runs-on: ubuntu-latest
104+
steps:
105+
- uses: actions/checkout@v6
106+
107+
- name: Download all artifacts
108+
uses: actions/download-artifact@v4
109+
with:
110+
path: release-assets
111+
112+
- name: Create GitHub Release
113+
id: release
114+
run: |
115+
TAG="v${{ needs.check-version.outputs.new_version }}"
116+
117+
gh release create "$TAG" \
118+
--title "$TAG" \
119+
--generate-notes \
120+
./release-assets/api_tool_macos_intel/api_tool_macos_intel \
121+
./release-assets/api_tool_macos_arm64/api_tool_macos_arm64 \
122+
./release-assets/api_tool_linux/api_tool_linux \
123+
./release-assets/api_tool_windows/api_tool_windows.exe

0 commit comments

Comments
 (0)