1+ name : ' Tag Creator'
2+ description : ' Create and manage git tags with validation'
3+
4+ inputs :
5+ tag :
6+ description : ' Tag to create (e.g., v1.0.0)'
7+ required : true
8+ token :
9+ description : ' GitHub token for authentication'
10+ required : true
11+
12+ force :
13+ description : ' Force overwrite existing tag'
14+ required : false
15+ default : ' false'
16+ branch :
17+ description : ' Branch to tag from'
18+ required : false
19+ default : ' main'
20+ tag_format :
21+ description : ' Tag format validation regex'
22+ required : false
23+ default : ' ^v[0-9]+\.[0-9]+\.[0-9]+(-.*)?$'
24+
25+ runs :
26+ using : composite
27+ steps :
28+ - name : Checkout repository
29+ uses : actions/checkout@v4
30+ with :
31+ ref : ${{ inputs.branch }}
32+ fetch-depth : 0
33+ token : ${{ inputs.token }}
34+
35+ - name : Validate tag format
36+ shell : bash
37+ run : |
38+ TAG="${{ inputs.tag }}"
39+ FORMAT="${{ inputs.tag_format }}"
40+
41+ if [[ ! "$TAG" =~ $FORMAT ]]; then
42+ echo "Invalid tag format: $TAG"
43+ echo "Expected format: $FORMAT"
44+ exit 1
45+ fi
46+ echo "Tag format is valid: $TAG"
47+
48+ - name : Check if tag exists
49+ id : check-tag
50+ shell : bash
51+ run : |
52+ TAG="${{ inputs.tag }}"
53+
54+ if git rev-parse "$TAG" >/dev/null 2>&1; then
55+ echo "exists=true" >> $GITHUB_OUTPUT
56+ echo "️Tag $TAG already exists"
57+
58+ if [ "${{ inputs.force }}" != "true" ]; then
59+ echo "Tag already exists. Use 'force' option to overwrite."
60+ exit 1
61+ else
62+ echo "Force option enabled, will overwrite existing tag"
63+ fi
64+ else
65+ echo "exists=false" >> $GITHUB_OUTPUT
66+ echo "Tag $TAG is available"
67+ fi
68+
69+ - name : Set Git configuration
70+ shell : bash
71+ run : |
72+ git config user.name "${{ github.actor }}"
73+ git config user.email "${{ github.actor }}@users.noreply.github.com"
74+
75+ - name : Create/Update tag
76+ shell : bash
77+ run : |
78+ TAG="${{ inputs.tag }}"
79+ BRANCH="${{ inputs.branch }}"
80+ COMMIT_SHA=$(git rev-parse HEAD)
81+
82+ echo "Tag Details:"
83+ echo " Tag: $TAG"
84+ echo " Commit: $COMMIT_SHA"
85+ echo " Branch: $BRANCH"
86+ echo " Author: ${{ github.actor }}"
87+ echo " Force: ${{ inputs.force }}"
88+ echo " Timestamp: $(date -u +"%Y-%m-%d %H:%M:%S UTC")"
89+
90+ if [ "${{ steps.check-tag.outputs.exists }}" == "true" ] && [ "${{ inputs.force }}" == "true" ]; then
91+ echo "Updating existing tag..."
92+ git tag -f "$TAG" "$COMMIT_SHA"
93+ git push origin ":refs/tags/$TAG"
94+ sleep 2
95+ git push origin "$TAG"
96+ echo "Tag $TAG updated successfully"
97+ else
98+ echo "Creating new tag..."
99+ git tag "$TAG" "$COMMIT_SHA"
100+ git push origin "$TAG"
101+ echo "Tag $TAG created successfully"
102+ fi
103+
104+ - name : Verify tag creation
105+ shell : bash
106+ run : |
107+ TAG="${{ inputs.tag }}"
108+
109+ # Verify local tag
110+ if git rev-parse "$TAG" >/dev/null 2>&1; then
111+ echo "Local tag verified: $TAG"
112+ else
113+ echo "Local tag verification failed"
114+ exit 1
115+ fi
116+
117+ # Wait a bit for remote sync
118+ sleep 3
119+
120+ # Verify remote tag
121+ if git ls-remote --tags origin | grep -q "refs/tags/$TAG"; then
122+ echo "Remote tag verified: $TAG"
123+ echo "Tag creation completed successfully!"
124+ else
125+ echo "Remote tag verification might be delayed, but push was successful"
126+ fi
0 commit comments