feat: 增加 post-commit 钩子;增加 README

This commit is contained in:
Ching 2024-05-13 16:52:57 +08:00
commit 265bf10495
2 changed files with 29 additions and 0 deletions

8
README.md Normal file
View File

@ -0,0 +1,8 @@
### post-commit
Script to ensure a tag for the current month exists.
每次提交时检查是否存在当前月份的tag如果不存在则创建一个。
#### usage
```shell
$ cp /path/to/your/git/hooks/post-commit /path/to/your/git/repo/.git/hooks/
```

21
post-commit Normal file
View File

@ -0,0 +1,21 @@
#!/bin/sh
# Script to ensure a tag for the current month exists
# Get the current year and month
YEAR_MONTH=$(date +%Y%m)
# Format the tag as v{year}{month}
TAG_NAME="v$YEAR_MONTH"
# Check if the tag already exists
if ! git rev-parse -q --verify "refs/tags/$TAG_NAME" >/dev/null; then
echo "Creating new tag for this month: $TAG_NAME"
# Create the tag
git tag -a "$TAG_NAME" -m "Monthly tag for $TAG_NAME"
# Optionally, you can push the tag to a remote repository
git push origin "$TAG_NAME"
else
echo "Tag for this month already exists: $TAG_NAME"
fi