File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ name : Create Tag
2+
3+ on :
4+ workflow_dispatch :
5+ inputs :
6+ tag_name :
7+ description : ' Tag name (e.g., v1.2.3, v1.2.3-beta.1)'
8+ required : true
9+ type : string
10+
11+ permissions :
12+ contents : write # 允许推送标签
13+
14+ jobs :
15+ create-tag :
16+ runs-on : ubuntu-latest
17+ steps :
18+ - name : Checkout repository
19+ uses : actions/checkout@v4
20+ with :
21+ fetch-depth : 0 # 获取所有历史,用于检查标签是否已存在
22+
23+ - name : Validate tag format
24+ run : |
25+ TAG="${{ github.event.inputs.tag_name }}"
26+ if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+.*$ ]]; then
27+ echo "❌ Tag must start with 'v' and contain at least three numbers (e.g., v1.2.3)"
28+ exit 1
29+ fi
30+ echo "✅ Tag format is valid."
31+
32+ - name : Check if tag already exists
33+ run : |
34+ TAG="${{ github.event.inputs.tag_name }}"
35+ if git rev-parse "$TAG" >/dev/null 2>&1; then
36+ echo "❌ Tag $TAG already exists locally."
37+ exit 1
38+ fi
39+ # 检查远程是否存在(可选,但建议)
40+ if git ls-remote --tags origin "$TAG" | grep -q "refs/tags/$TAG"; then
41+ echo "❌ Tag $TAG already exists on remote."
42+ exit 1
43+ fi
44+ echo "✅ Tag does not exist."
45+
46+ - name : Create and push tag
47+ run : |
48+ TAG="${{ github.event.inputs.tag_name }}"
49+ git config user.name "github-actions[bot]"
50+ git config user.email "github-actions[bot]@users.noreply.github.com"
51+ git tag "$TAG"
52+ git push origin "$TAG"
53+ echo "🚀 Tag $TAG created and pushed successfully."
54+
55+ - name : Done
56+ run : echo "The tag will now trigger the 'install' workflow automatically."
You can’t perform that action at this time.
0 commit comments