|
| 1 | +# ZCF Release - Automated Release and Commit |
| 2 | + |
| 3 | +Automate version release and code commit using changeset. |
| 4 | + |
| 5 | +## Usage |
| 6 | + |
| 7 | +```bash |
| 8 | +/zcf-release [-p|-mi|-ma] |
| 9 | +``` |
| 10 | + |
| 11 | +## Parameters |
| 12 | + |
| 13 | +- `-p` or `--patch`: Patch version (default) - bug fixes, minor changes |
| 14 | +- `-mi` or `--minor`: Minor version - new features, backward compatible |
| 15 | +- `-ma` or `--major`: Major version - breaking changes, incompatible |
| 16 | + |
| 17 | +## Context |
| 18 | + |
| 19 | +- Automatically analyze code changes and generate bilingual CHANGELOG |
| 20 | +- Use changeset for version management |
| 21 | +- Auto commit code and create release tags |
| 22 | +- Support GitHub Actions auto publish to npm |
| 23 | + |
| 24 | +## Your Role |
| 25 | + |
| 26 | +You are a professional release management assistant responsible for: |
| 27 | +1. Analyzing code changes |
| 28 | +2. Generating standardized CHANGELOG |
| 29 | +3. Executing version release process |
| 30 | + |
| 31 | +## Execution Flow |
| 32 | + |
| 33 | +Parse arguments: $ARGUMENTS |
| 34 | + |
| 35 | +### 1. Parameter Parsing |
| 36 | + |
| 37 | +```bash |
| 38 | +VERSION_TYPE="patch" # Default to patch version |
| 39 | + |
| 40 | +case "$ARGUMENTS" in |
| 41 | + -p|--patch) |
| 42 | + VERSION_TYPE="patch" |
| 43 | + ;; |
| 44 | + -mi|--minor) |
| 45 | + VERSION_TYPE="minor" |
| 46 | + ;; |
| 47 | + -ma|--major) |
| 48 | + VERSION_TYPE="major" |
| 49 | + ;; |
| 50 | + "") |
| 51 | + VERSION_TYPE="patch" |
| 52 | + ;; |
| 53 | + *) |
| 54 | + echo "Unknown parameter: $ARGUMENTS" |
| 55 | + echo "Usage: /zcf-release [-p|-mi|-ma]" |
| 56 | + exit 1 |
| 57 | + ;; |
| 58 | +esac |
| 59 | + |
| 60 | +echo "🚀 Preparing to release $VERSION_TYPE version" |
| 61 | +``` |
| 62 | + |
| 63 | +### 2. Check Working Directory Status |
| 64 | + |
| 65 | +Check if the current working directory meets release conditions: |
| 66 | + |
| 67 | +```bash |
| 68 | +# Ensure in project root directory |
| 69 | +if [ ! -f "package.json" ]; then |
| 70 | + echo "❌ Error: package.json not found, please run in project root" |
| 71 | + exit 1 |
| 72 | +fi |
| 73 | + |
| 74 | +# Check for uncommitted changes |
| 75 | +if ! git diff --quiet || ! git diff --cached --quiet; then |
| 76 | + echo "⚠️ Detected uncommitted changes:" |
| 77 | + git status --short |
| 78 | + echo "" |
| 79 | + read -p "Commit these changes first? [Y/n] " -n 1 -r |
| 80 | + echo |
| 81 | + if [[ $REPLY =~ ^[Yy]$ ]] || [[ -z $REPLY ]]; then |
| 82 | + echo "Please commit changes before releasing" |
| 83 | + exit 1 |
| 84 | + fi |
| 85 | +fi |
| 86 | + |
| 87 | +echo "✅ Working directory status OK" |
| 88 | +``` |
| 89 | + |
| 90 | +### 3. Analyze Version Changes |
| 91 | + |
| 92 | +Analyze all changes since last release: |
| 93 | + |
| 94 | +```bash |
| 95 | +# Get last release tag |
| 96 | +LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") |
| 97 | + |
| 98 | +if [ -z "$LAST_TAG" ]; then |
| 99 | + echo "📊 No previous version tag found, analyzing all commits" |
| 100 | + COMMITS=$(git log --oneline) |
| 101 | +else |
| 102 | + echo "📊 Last version: $LAST_TAG" |
| 103 | + echo "Analyzing changes since $LAST_TAG..." |
| 104 | + COMMITS=$(git log $LAST_TAG..HEAD --oneline) |
| 105 | +fi |
| 106 | + |
| 107 | +# Show commit history |
| 108 | +echo -e "\n📝 Changes:" |
| 109 | +echo "$COMMITS" |
| 110 | + |
| 111 | +# Analyze file changes |
| 112 | +echo -e "\n📁 File change statistics:" |
| 113 | +if [ -z "$LAST_TAG" ]; then |
| 114 | + git diff --stat |
| 115 | +else |
| 116 | + git diff --stat $LAST_TAG..HEAD |
| 117 | +fi |
| 118 | +``` |
| 119 | + |
| 120 | +### 4. Generate CHANGELOG Content |
| 121 | + |
| 122 | +Based on code change analysis, I will generate CHANGELOG following these standards: |
| 123 | + |
| 124 | +**Format Requirements**: |
| 125 | +1. Chinese description first, English description second |
| 126 | +2. No mixing Chinese and English on the same line |
| 127 | +3. Organize by category: New Features, Optimization, Fixes, Documentation, etc. |
| 128 | +4. Each entry should be concise and clear |
| 129 | + |
| 130 | +**Example Format**: |
| 131 | +```markdown |
| 132 | +## 新功能 |
| 133 | + |
| 134 | +- 添加技术执行指南文档,提供命令执行最佳实践 |
| 135 | +- 支持自动化发版命令 /zcf-release |
| 136 | +- Windows 路径自动加引号处理 |
| 137 | + |
| 138 | +## New Features |
| 139 | + |
| 140 | +- Add technical execution guidelines with command best practices |
| 141 | +- Support automated release command /zcf-release |
| 142 | +- Automatic quote handling for Windows paths |
| 143 | + |
| 144 | +## 优化 |
| 145 | + |
| 146 | +- 优先使用 ripgrep 提升搜索性能 |
| 147 | +- 改进模板文件组织结构 |
| 148 | + |
| 149 | +## Optimization |
| 150 | + |
| 151 | +- Prioritize ripgrep for better search performance |
| 152 | +- Improve template file organization |
| 153 | + |
| 154 | +## 修复 |
| 155 | + |
| 156 | +- 修复 Windows 路径反斜杠丢失问题 |
| 157 | + |
| 158 | +## Fixes |
| 159 | + |
| 160 | +- Fix Windows path backslash escaping issue |
| 161 | +``` |
| 162 | + |
| 163 | +### 5. Create Changeset |
| 164 | + |
| 165 | +Create changeset file based on analysis: |
| 166 | + |
| 167 | +```bash |
| 168 | +# Generate timestamp |
| 169 | +TIMESTAMP=$(date +%Y%m%d%H%M%S) |
| 170 | +CHANGESET_FILE=".changeset/release-$TIMESTAMP.md" |
| 171 | + |
| 172 | +# Create changeset file |
| 173 | +echo "📝 Creating changeset file..." |
| 174 | +cat > "$CHANGESET_FILE" << 'EOF' |
| 175 | +--- |
| 176 | +"zcf": $VERSION_TYPE |
| 177 | +--- |
| 178 | +
|
| 179 | +[Bilingual CHANGELOG content generated based on actual changes] |
| 180 | +EOF |
| 181 | + |
| 182 | +echo "✅ Changeset file created: $CHANGESET_FILE" |
| 183 | +``` |
| 184 | + |
| 185 | +### 6. Update Version Number |
| 186 | + |
| 187 | +Use changeset to update version number and CHANGELOG: |
| 188 | + |
| 189 | +```bash |
| 190 | +echo "🔄 Updating version number and CHANGELOG..." |
| 191 | +pnpm changeset version |
| 192 | + |
| 193 | +# Get new version number |
| 194 | +NEW_VERSION=$(node -p "require('./package.json').version") |
| 195 | +echo "📦 New version: v$NEW_VERSION" |
| 196 | + |
| 197 | +# Show CHANGELOG update |
| 198 | +echo -e "\n📋 CHANGELOG has been updated, please review the content" |
| 199 | +``` |
| 200 | + |
| 201 | +### 7. Create Release Commit |
| 202 | + |
| 203 | +Commit all changes and create version tag: |
| 204 | + |
| 205 | +```bash |
| 206 | +echo "💾 Committing release changes..." |
| 207 | + |
| 208 | +# Add all changes |
| 209 | +git add . |
| 210 | + |
| 211 | +# Create release commit |
| 212 | +git commit -m "chore: release v$NEW_VERSION |
| 213 | +
|
| 214 | +- Update version to $NEW_VERSION |
| 215 | +- Update CHANGELOG.md |
| 216 | +- Generated by /zcf-release command" |
| 217 | + |
| 218 | +# Create tag |
| 219 | +git tag -a "v$NEW_VERSION" -m "Release v$NEW_VERSION" |
| 220 | +echo "🏷️ Tag created: v$NEW_VERSION" |
| 221 | +``` |
| 222 | + |
| 223 | +### 8. Push to Remote Repository |
| 224 | + |
| 225 | +```bash |
| 226 | +echo "🚀 Pushing to remote repository..." |
| 227 | + |
| 228 | +# Push main branch |
| 229 | +git push origin main |
| 230 | + |
| 231 | +# Push tag |
| 232 | +git push origin "v$NEW_VERSION" |
| 233 | + |
| 234 | +echo -e "\n✅ Release preparation complete!" |
| 235 | +echo "📦 Version v$NEW_VERSION is ready" |
| 236 | +echo "🤖 GitHub Actions will automatically publish to npm" |
| 237 | +echo "👀 View release status: https://github.com/UfoMiao/zcf/actions" |
| 238 | +``` |
| 239 | + |
| 240 | +## Complete Workflow Summary |
| 241 | + |
| 242 | +1. **Preparation Phase**: Check parameters, working directory status |
| 243 | +2. **Analysis Phase**: Analyze commit history and file changes |
| 244 | +3. **Generation Phase**: Create bilingual CHANGELOG |
| 245 | +4. **Execution Phase**: Update version, commit, tag, push |
| 246 | +5. **Release Phase**: GitHub Actions auto publish |
| 247 | + |
| 248 | +## Important Notes |
| 249 | + |
| 250 | +- Ensure all code has been tested |
| 251 | +- CHANGELOG must follow bilingual format standards |
| 252 | +- Choose the correct version type |
| 253 | +- Carefully review CHANGELOG content before release |
| 254 | + |
| 255 | +--- |
| 256 | + |
| 257 | +**Now starting release process...** |
0 commit comments