Skip to content

Commit 701bb43

Browse files
committed
feat: 添加手动触发工作流支持,优化版本递增逻辑并更新标签创建流程
Change-Id: Id5caaaf81550827216a8445af904f60dd8b86142 Signed-off-by: OhYee <[email protected]>
1 parent 2486aaf commit 701bb43

File tree

1 file changed

+78
-10
lines changed

1 file changed

+78
-10
lines changed

.github/workflows/release-test.yml

Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,82 @@
11
name: Release Test Package
22

33
on:
4-
push:
5-
tags:
6-
- 'test-v*'
4+
# 支持手动触发,用户可以在 GitHub Actions 页面点击 "Run workflow"
5+
workflow_dispatch:
6+
inputs:
7+
version_bump:
8+
description: '版本递增类型'
9+
required: true
10+
default: 'patch'
11+
type: choice
12+
options:
13+
- patch # 0.0.1 -> 0.0.2
14+
- minor # 0.0.1 -> 0.1.0
15+
- major # 0.0.1 -> 1.0.0
716

817
jobs:
918
release-test:
1019
runs-on: ubuntu-latest
1120
permissions:
12-
contents: read
21+
contents: write
1322
id-token: write
1423
steps:
1524
- uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0 # 获取所有历史和 tags
1627

1728
- name: Set up Python
1829
uses: actions/setup-python@v5
1930
with:
2031
python-version: '3.10'
2132

22-
- name: Extract version from tag
33+
- name: Get latest test version and calculate next version
34+
id: version
2335
run: |
24-
TAG="${{ github.ref_name }}"
25-
# 从 test-v0.0.1 中提取 0.0.1
26-
VERSION="${TAG#test-v}"
27-
echo "VERSION=${VERSION}" >> $GITHUB_ENV
28-
echo "Extracted version: ${VERSION}"
36+
# 获取所有 agentrun-inner-test-v* 的 tags,找到最新版本
37+
LATEST_TAG=$(git tag -l "agentrun-inner-test-v*" | sort -V | tail -n 1)
38+
39+
if [ -z "$LATEST_TAG" ]; then
40+
# 如果没有找到任何 tag,从 0.0.0 开始
41+
CURRENT_VERSION="0.0.0"
42+
echo "No existing test tags found, starting from 0.0.0"
43+
else
44+
# 从 tag 中提取版本号
45+
CURRENT_VERSION="${LATEST_TAG#agentrun-inner-test-v}"
46+
echo "Latest test tag: $LATEST_TAG (version: $CURRENT_VERSION)"
47+
fi
48+
49+
# 解析版本号
50+
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION"
51+
52+
# 根据用户选择递增版本
53+
BUMP_TYPE="${{ inputs.version_bump }}"
54+
case "$BUMP_TYPE" in
55+
major)
56+
MAJOR=$((MAJOR + 1))
57+
MINOR=0
58+
PATCH=0
59+
;;
60+
minor)
61+
MINOR=$((MINOR + 1))
62+
PATCH=0
63+
;;
64+
patch)
65+
PATCH=$((PATCH + 1))
66+
;;
67+
esac
68+
69+
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
70+
NEW_TAG="agentrun-inner-test-v${NEW_VERSION}"
71+
72+
echo "VERSION=${NEW_VERSION}" >> $GITHUB_OUTPUT
73+
echo "TAG=${NEW_TAG}" >> $GITHUB_OUTPUT
74+
echo "New version: ${NEW_VERSION}"
75+
echo "New tag: ${NEW_TAG}"
2976
3077
- name: Update package name and version in pyproject.toml
3178
run: |
79+
VERSION="${{ steps.version.outputs.VERSION }}"
3280
# 修改包名为 agentrun-inner-test
3381
sed -i 's/name = "agentrun-sdk"/name = "agentrun-inner-test"/' pyproject.toml
3482
# 修改版本号
@@ -38,6 +86,7 @@ jobs:
3886
3987
- name: Update __version__ in __init__.py
4088
run: |
89+
VERSION="${{ steps.version.outputs.VERSION }}"
4190
if grep -q "__version__" agentrun/__init__.py; then
4291
sed -i 's/__version__ = "[^"]*"/__version__ = "'${VERSION}'"/' agentrun/__init__.py
4392
else
@@ -65,3 +114,22 @@ jobs:
65114
password: ${{ secrets.PYPI_API_TOKEN }}
66115
verify-metadata: false
67116

117+
- name: Create and push tag
118+
run: |
119+
TAG="${{ steps.version.outputs.TAG }}"
120+
git config --local user.email "[email protected]"
121+
git config --local user.name "GitHub Action"
122+
git tag -a "$TAG" -m "Release test package version ${{ steps.version.outputs.VERSION }}"
123+
git push origin "$TAG"
124+
echo "Created and pushed tag: $TAG"
125+
126+
- name: Summary
127+
run: |
128+
echo "## 🎉 Test Package Released!" >> $GITHUB_STEP_SUMMARY
129+
echo "" >> $GITHUB_STEP_SUMMARY
130+
echo "- **Package Name:** agentrun-inner-test" >> $GITHUB_STEP_SUMMARY
131+
echo "- **Version:** ${{ steps.version.outputs.VERSION }}" >> $GITHUB_STEP_SUMMARY
132+
echo "- **Tag:** ${{ steps.version.outputs.TAG }}" >> $GITHUB_STEP_SUMMARY
133+
echo "- **Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
134+
echo "" >> $GITHUB_STEP_SUMMARY
135+
echo "Install with: \`pip install agentrun-inner-test==${{ steps.version.outputs.VERSION }}\`" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)