Skip to content

Commit

Permalink
feat(github-actions): add script to get latest tag for current commit
Browse files Browse the repository at this point in the history
Add a Bash script to retrieve the latest Git tag associated with the
current commit. The script configures Git user information, extracts
the current commit hash, finds any tags pointing at the commit, and
displays the most recent tag if available.

Assumptions:
- Tags are annotated and follow a time-based ordering.
  • Loading branch information
godcong committed Jul 10, 2024
1 parent b961372 commit 7837d0c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions scripts/git/commit_tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# 设置 Git 用户信息
git config user.name "GitHub Action"
git config user.email "[email protected]"

#git config user.name "godcong"
#git config user.email "[email protected]"

# 获取当前HEAD的哈希值
CURRENT_COMMIT=$(git rev-parse HEAD)

# 查找与当前提交匹配的标签
TAG_FOR_CURRENT_COMMIT=$(git tag --points-at "$CURRENT_COMMIT")

# 检查是否有标签
if [ -n "$TAG_FOR_CURRENT_COMMIT" ]; then
# 将标签列表转换为数组
IFS=$'\n' read -d '' -r -a TAGS_ARRAY <<< "$TAG_FOR_CURRENT_COMMIT"
# 找到最新的标签,假设标签按时间顺序排列
LATEST_TAG=${TAGS_ARRAY[-1]}
echo "$LATEST_TAG"
fi

0 comments on commit 7837d0c

Please sign in to comment.