程序员工具箱

一键提交打标签和发布

2026-03-19  本文已影响0人  许一沐
## 操作规范

### 发布 GitHub Release

**当用户说 "提交打标签和发布" 时,自动执行以下完整流程(全部使用 GitHub HTTP API,无需 git tag/push tag):**

```bash
# 1. 提交所有更改
git add -A
git commit -m "feat: description

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>"

# 2. 推送代码
git push origin main

# 3. 从 git credential 获取 GitHub Token
GITHUB_TOKEN=$(echo "url=https://github.com" | git credential fill | grep password | cut -d= -f2)

# 4. 获取最新 commit hash
COMMIT_HASH=$(git rev-parse HEAD)

# 5. 获取当前最新 tag 并计算新版本
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v2.0.0")
NEW_TAG=$(echo "$LAST_TAG" | awk -F. '{print $1"."$2"."$3+1}')

# 6. 使用 GitHub API 创建 tag 引用
curl -s -X POST \
  -H "Authorization: Bearer $GITHUB_TOKEN" \
  -H "Accept: application/vnd.github.v3+json" \
  https://api.github.com/repos/toohamster/sftp-cc/git/refs \
  -d "{\"ref\":\"refs/tags/$NEW_TAG\",\"sha\":\"$COMMIT_HASH\"}"

# 7. 使用 GitHub API 创建 Release
curl -s -X POST \
  -H "Authorization: Bearer $GITHUB_TOKEN" \
  -H "Accept: application/vnd.github.v3+json" \
  https://api.github.com/repos/toohamster/sftp-cc/releases \
  -d "{\"tag_name\":\"$NEW_TAG\",\"target_commitish\":\"$COMMIT_HASH\",\"name\":\"$NEW_TAG - Release\",\"body\":\"Release $NEW_TAG\",\"draft\":false,\"prerelease\":false}"

注意:

上一篇 下一篇

猜你喜欢

热点阅读