|
| 1 | +# Release Script Remote Detection Testing |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +The improved `release.sh` script now intelligently detects the appropriate git remote to use for pushing release tags. This document describes the improvements and how to test them. |
| 6 | + |
| 7 | +## Improvements Made |
| 8 | + |
| 9 | +### 1. **Dynamic Remote Detection** |
| 10 | + |
| 11 | +Previously, the script hard-coded the remote name as `github`: |
| 12 | +```bash |
| 13 | +git push github "$RELEASE_TAG" # Hard-coded, fails if remote has different name |
| 14 | +``` |
| 15 | + |
| 16 | +Now, the script uses a helper function `get_github_remote()` to automatically detect the appropriate remote: |
| 17 | +```bash |
| 18 | +GITHUB_REMOTE=$(get_github_remote) |
| 19 | +git push "$GITHUB_REMOTE" "$RELEASE_TAG" # Dynamic, works with any remote name |
| 20 | +``` |
| 21 | + |
| 22 | +### 2. **Smart Priority System** |
| 23 | + |
| 24 | +The `get_github_remote()` function implements a priority-based selection: |
| 25 | + |
| 26 | +1. **Primary**: Remotes with `github.com` in the URL (e.g., `git@github.com:...`) |
| 27 | + - Searches all configured remotes |
| 28 | + - Selects the first one matching this pattern |
| 29 | + - Ensures GitHub remotes are preferred |
| 30 | + |
| 31 | +2. **Fallback**: First available remote |
| 32 | + - If no github.com remotes exist |
| 33 | + - Uses the first remote in the list |
| 34 | + |
| 35 | +3. **Error**: No remotes found |
| 36 | + - Script exits with error message |
| 37 | + - Prevents unexpected behavior |
| 38 | + |
| 39 | +### 3. **Transparent Remote Display** |
| 40 | + |
| 41 | +The script now displays the selected remote at the start: |
| 42 | + |
| 43 | +``` |
| 44 | +Using remote: github (git@github.com:wysaid/CameraCapture.git) |
| 45 | +``` |
| 46 | + |
| 47 | +This allows users to verify the correct remote is being used before proceeding. |
| 48 | + |
| 49 | +## Test Scenarios |
| 50 | + |
| 51 | +### Scenario 1: Standard Setup (github.com + Local Upstream) |
| 52 | + |
| 53 | +**Configuration:** |
| 54 | +```bash |
| 55 | +github git@github.com:wysaid/CameraCapture.git (fetch) |
| 56 | +github git@github.com:wysaid/CameraCapture.git (push) |
| 57 | +origin git@git.corp.kuaishou.com:facemagic/ccap.git (fetch) |
| 58 | +origin git@git.corp.kuaishou.com:facemagic/ccap.git (push) |
| 59 | +``` |
| 60 | + |
| 61 | +**Expected Behavior:** |
| 62 | +- Script detects both remotes |
| 63 | +- Prioritizes `github` (contains github.com) |
| 64 | +- Displays: `Using remote: github (git@github.com:wysaid/CameraCapture.git)` |
| 65 | +- Executes: `git push github v1.4.0` |
| 66 | + |
| 67 | +**Verification:** |
| 68 | +```bash |
| 69 | +./scripts/release.sh --dry-run |
| 70 | +# Look for: "Using remote: github" in output |
| 71 | +``` |
| 72 | + |
| 73 | +### Scenario 2: Non-standard Remote Names |
| 74 | + |
| 75 | +**Configuration:** |
| 76 | +```bash |
| 77 | +upstream git@github.com:wysaid/CameraCapture.git (fetch) |
| 78 | +upstream git@github.com:wysaid/CameraCapture.git (push) |
| 79 | +internal git@git.corp.kuaishou.com:facemagic/ccap.git (fetch) |
| 80 | +internal git@git.corp.kuaishou.com:facemagic/ccap.git (push) |
| 81 | +``` |
| 82 | + |
| 83 | +**Expected Behavior:** |
| 84 | +- Script detects `upstream` as GitHub remote (even though it's not named `github`) |
| 85 | +- Displays: `Using remote: upstream (git@github.com:wysaid/CameraCapture.git)` |
| 86 | +- Executes: `git push upstream v1.4.0` |
| 87 | + |
| 88 | +**Why This Matters:** |
| 89 | +- Developers with different remote naming conventions work seamlessly |
| 90 | +- Corporate environments with multiple remotes are supported |
| 91 | +- Fork/upstream patterns are automatically handled |
| 92 | + |
| 93 | +### Scenario 3: Only Local Upstream |
| 94 | + |
| 95 | +**Configuration:** |
| 96 | +```bash |
| 97 | +origin git@git.corp.kuaishou.com:facemagic/ccap.git (fetch) |
| 98 | +origin git@git.corp.kuaishou.com:facemagic/ccap.git (push) |
| 99 | +``` |
| 100 | + |
| 101 | +**Expected Behavior:** |
| 102 | +- No github.com remote found |
| 103 | +- Script falls back to first available: `origin` |
| 104 | +- Displays: `Using remote: origin (git@git.corp.kuaishou.com:facemagic/ccap.git)` |
| 105 | +- Executes: `git push origin v1.4.0` |
| 106 | + |
| 107 | +**Note:** This works but isn't ideal for public releases to GitHub. |
| 108 | + |
| 109 | +### Scenario 4: No Remotes |
| 110 | + |
| 111 | +**Configuration:** |
| 112 | +```bash |
| 113 | +(no remotes configured) |
| 114 | +``` |
| 115 | + |
| 116 | +**Expected Behavior:** |
| 117 | +- Script exits with error: `Error: No git remote found!` |
| 118 | +- Prevents accidental release creation |
| 119 | +- User must configure at least one remote |
| 120 | + |
| 121 | +## Implementation Details |
| 122 | + |
| 123 | +### Helper Function: `get_github_remote()` |
| 124 | + |
| 125 | +Located at the beginning of the script (lines 38-57): |
| 126 | + |
| 127 | +```bash |
| 128 | +get_github_remote() { |
| 129 | + # First, try to find a remote with github.com in the URL |
| 130 | + local github_remote=$(git remote -v | grep 'github\.com' | awk '{print $1}' | head -1) |
| 131 | + |
| 132 | + if [ -n "$github_remote" ]; then |
| 133 | + echo "$github_remote" |
| 134 | + return 0 |
| 135 | + fi |
| 136 | + |
| 137 | + # Fallback: return first available remote |
| 138 | + local first_remote=$(git remote | head -1) |
| 139 | + if [ -n "$first_remote" ]; then |
| 140 | + echo "$first_remote" |
| 141 | + return 0 |
| 142 | + fi |
| 143 | + |
| 144 | + # No remotes found |
| 145 | + return 1 |
| 146 | +} |
| 147 | +``` |
| 148 | + |
| 149 | +### Usage in Script |
| 150 | + |
| 151 | +1. **Initialization (line 60):** |
| 152 | + ```bash |
| 153 | + GITHUB_REMOTE=$(get_github_remote) |
| 154 | + ``` |
| 155 | + |
| 156 | +2. **Validation (line 61-63):** |
| 157 | + ```bash |
| 158 | + if [ -z "$GITHUB_REMOTE" ]; then |
| 159 | + exit 1 |
| 160 | + fi |
| 161 | + ``` |
| 162 | + |
| 163 | +3. **Display (line 70):** |
| 164 | + ```bash |
| 165 | + echo -e " Using remote: ${GREEN}$GITHUB_REMOTE${NC} ($(git remote get-url "$GITHUB_REMOTE"))" |
| 166 | + ``` |
| 167 | + |
| 168 | +4. **Dry-run Command (line 314):** |
| 169 | + ```bash |
| 170 | + echo -e " ${BLUE}git push $GITHUB_REMOTE $RELEASE_TAG${NC}" |
| 171 | + ``` |
| 172 | + |
| 173 | +5. **Actual Push (line 327):** |
| 174 | + ```bash |
| 175 | + git push "$GITHUB_REMOTE" "$RELEASE_TAG" |
| 176 | + ``` |
| 177 | + |
| 178 | +## Benefits |
| 179 | + |
| 180 | +✅ **Flexibility**: Works with any remote naming convention |
| 181 | +✅ **Intelligence**: Automatically prioritizes GitHub remotes |
| 182 | +✅ **Safety**: Prevents silent failures with unsupported remote configurations |
| 183 | +✅ **Transparency**: Users see exactly which remote will be used |
| 184 | +✅ **Robustness**: Graceful fallback for edge cases |
| 185 | +✅ **Maintenance**: Script requires no manual configuration |
| 186 | + |
| 187 | +## Migration Guide |
| 188 | + |
| 189 | +### For Existing Users |
| 190 | + |
| 191 | +**No changes required!** The script is fully backward compatible. |
| 192 | + |
| 193 | +If your project uses a remote named `github` pointing to github.com: |
| 194 | +- Script will detect and use it automatically |
| 195 | +- Behavior is identical to previous version |
| 196 | + |
| 197 | +If your project uses a different remote name: |
| 198 | +- Script will now work correctly instead of failing |
| 199 | +- No additional configuration needed |
| 200 | + |
| 201 | +### For New Projects |
| 202 | + |
| 203 | +Simply configure your remotes normally: |
| 204 | +```bash |
| 205 | +git remote add github https://github.com/yourusername/yourrepo.git |
| 206 | +git remote add origin https://internal-git.company.com/yourrepo.git |
| 207 | +``` |
| 208 | + |
| 209 | +The script handles the rest automatically. |
| 210 | + |
| 211 | +## Testing the Changes |
| 212 | + |
| 213 | +### Quick Test: Dry-run Mode |
| 214 | + |
| 215 | +```bash |
| 216 | +# Test without actually creating tags |
| 217 | +./scripts/release.sh --dry-run |
| 218 | + |
| 219 | +# Expected output includes: |
| 220 | +# "Using remote: github (git@github.com:wysaid/CameraCapture.git)" |
| 221 | +# "git push github v1.4.0" (or whichever remote is detected) |
| 222 | +``` |
| 223 | + |
| 224 | +### Manual Test: Check Remote Detection |
| 225 | + |
| 226 | +```bash |
| 227 | +# Run the detection function in isolation |
| 228 | +bash -c ' |
| 229 | +SCRIPT_DIR="/path/to/scripts" |
| 230 | +cd "$(dirname "$SCRIPT_DIR")" |
| 231 | +
|
| 232 | +get_github_remote() { |
| 233 | + local github_remote=$(git remote -v | grep "github\.com" | awk "{print \$1}" | head -1) |
| 234 | + [ -n "$github_remote" ] && echo "$github_remote" && return 0 |
| 235 | + |
| 236 | + local first_remote=$(git remote | head -1) |
| 237 | + [ -n "$first_remote" ] && echo "$first_remote" && return 0 |
| 238 | + |
| 239 | + return 1 |
| 240 | +} |
| 241 | +
|
| 242 | +echo "Detected remote: $(get_github_remote)" |
| 243 | +' |
| 244 | +``` |
| 245 | + |
| 246 | +### Full Integration Test |
| 247 | + |
| 248 | +```bash |
| 249 | +# With version 1.4.0 prepared but not yet released: |
| 250 | +./scripts/release.sh --dry-run |
| 251 | + |
| 252 | +# Verify: |
| 253 | +# 1. Correct remote is shown |
| 254 | +# 2. All 7 validation steps pass |
| 255 | +# 3. Correct git commands would be executed |
| 256 | +# 4. Script exits with success |
| 257 | +``` |
| 258 | + |
| 259 | +## Related Files |
| 260 | + |
| 261 | +- `scripts/release.sh` - Main release script (improved) |
| 262 | +- `RELEASING.md` - Release procedure documentation |
| 263 | +- `scripts/update_version.sh` - Version update script |
| 264 | + |
| 265 | +## See Also |
| 266 | + |
| 267 | +- GitHub PR #25: Version Management System Implementation |
| 268 | +- PR Review Comments: Git remote handling improvements |
0 commit comments