-
Notifications
You must be signed in to change notification settings - Fork 4
44 lines (37 loc) · 1.52 KB
/
create-tag.yaml
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
name: OpenIM Create Tag
on:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]
jobs:
create_tag:
runs-on: ubuntu-latest
if: startsWith(github.event.comment.body, '/create-tag')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Create a new tag
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Use bash parameter expansion to handle comment extraction
COMMENT_BODY="${{ github.event.comment.body }}"
VERSION=$(echo "$COMMENT_BODY" | awk '/^\/create tag/ {print $3}')
TAG_COMMENT=$(echo "$COMMENT_BODY" | grep -oP '(?<=").*?(?=")')
# Validate version number
if ! [[ $VERSION =~ ^v([0-9]+\.){2}[0-9]+$ ]]; then
echo "Invalid version number: $VERSION"
echo "The version number must match the pattern 'vX.Y.Z' where X, Y, and Z are integers."
exit 1
fi
# Configure Git and create the tag
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "GitHub Actions Bot"
git tag -a "$VERSION" -m "$TAG_COMMENT"
git push origin "$VERSION"
echo "Tag '$VERSION' created with comment: $TAG_COMMENT"
# Set output for subsequent steps, if necessary
echo "tag_created=$VERSION" >> $GITHUB_ENV
# Set output for subsequent steps, if necessary
echo "tag_created=$VERSION" >> $GITHUB_ENV