-
Notifications
You must be signed in to change notification settings - Fork 12
57 lines (50 loc) · 1.82 KB
/
create-tag.yml
File metadata and controls
57 lines (50 loc) · 1.82 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
name: Create Tag
on:
workflow_dispatch:
inputs:
tag_name:
description: 'Tag name (e.g., v1.2.3, v1.2.3-beta.1)'
required: true
type: string
permissions:
contents: read # 只需要读权限,推送使用 PAT
jobs:
create-tag:
runs-on: ubuntu-latest
steps:
# 关键修改:使用 PAT 来 checkout,后续的 push 才能生效
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.PAT_FOR_TAG }} # <--- 使用我们刚配置的 secret
- name: Validate tag format
run: |
TAG="${{ github.event.inputs.tag_name }}"
if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+.*$ ]]; then
echo "❌ Tag must start with 'v' and contain at least three numbers (e.g., v1.2.3)"
exit 1
fi
echo "✅ Tag format is valid."
- name: Check if tag already exists
run: |
TAG="${{ github.event.inputs.tag_name }}"
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "❌ Tag $TAG already exists locally."
exit 1
fi
if git ls-remote --tags origin "$TAG" | grep -q "refs/tags/$TAG"; then
echo "❌ Tag $TAG already exists on remote."
exit 1
fi
echo "✅ Tag does not exist."
- name: Create and push tag using PAT
run: |
TAG="${{ github.event.inputs.tag_name }}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag "$TAG"
git push origin "$TAG"
echo "🚀 Tag $TAG created and pushed successfully."
- name: Done
run: echo "The tag has been pushed and should trigger the 'install' workflow automatically."