Skip to content

Commit b9d70b3

Browse files
ci: Create Tag
1 parent 97604d9 commit b9d70b3

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

.github/workflows/create-tag.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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."

0 commit comments

Comments
 (0)