Skip to content

Commit fb8da7c

Browse files
committed
chore: Improve commit-scoop-manifest script to check for source manifest existence and enhance error handling
1 parent 1a057d0 commit fb8da7c

File tree

1 file changed

+81
-54
lines changed

1 file changed

+81
-54
lines changed

scripts/commit-scoop-manifest.ps1

Lines changed: 81 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,95 @@
11
Write-Host "🚀 Committing scoop manifest changes..."
22

3-
if (Test-Path 'zed-cli-win-unofficial.json') {
4-
Write-Host "✅ Found fixed manifest: zed-cli-win-unofficial.json"
5-
Write-Host " Size: $((Get-Item 'zed-cli-win-unofficial.json').Length) bytes"
6-
7-
# Debug: Show git status
8-
Write-Host "🔍 Git status:"
9-
git status
10-
git branch -a
11-
12-
# Configure git user (required for commits)
13-
git config user.name "SameerJS6"
14-
git config user.email "[email protected]"
3+
# Check if the source manifest exists first
4+
if (-not (Test-Path 'dist/scoop/zed-cli-win-unofficial.json')) {
5+
Write-Host "❌ No scoop manifest found in dist/scoop/"
6+
exit 1
7+
}
8+
9+
# Debug: Show git status
10+
Write-Host "🔍 Git status before checkout:"
11+
git status
12+
git branch -a
13+
14+
# Configure git user (required for commits)
15+
git config user.name "SameerJS6"
16+
git config user.email "[email protected]"
17+
18+
# For tag-based workflows, we need to checkout the main branch FIRST
19+
Write-Host "🔄 Checking out main branch..."
20+
git fetch origin main
21+
git checkout main
22+
if ($LASTEXITCODE -ne 0) {
23+
Write-Host "❌ Failed to checkout main branch"
24+
exit 1
25+
}
26+
27+
# Get the current branch name
28+
$currentBranch = git branch --show-current
29+
Write-Host "📋 Current branch: $currentBranch"
30+
31+
# Now that we're on main, create the fixed manifest
32+
Write-Host "🔧 Creating fixed scoop manifest..."
33+
if (Test-Path 'dist/scoop/zed-cli-win-unofficial.json') {
34+
# Read the original content as text to preserve formatting
35+
$content = Get-Content 'dist/scoop/zed-cli-win-unofficial.json' -Raw
1536

16-
# For tag-based workflows, we need to checkout the main branch
17-
Write-Host "🔄 Ensuring we're on the main branch..."
18-
git fetch origin main
19-
git checkout main
37+
# Use regex to find and modify the bin array while preserving formatting
38+
if ($content -notmatch '"zed-cli-win-unofficial/zed\.bat"') {
39+
Write-Host "🔧 Adding zed.bat to bin array..."
40+
41+
# Find the bin array and add the new entry
42+
$pattern = '("bin":\s*\[\s*"[^"]+")(\s*\])'
43+
$replacement = '$1, "zed-cli-win-unofficial/zed.bat"$2'
44+
45+
$updatedContent = $content -replace $pattern, $replacement
46+
47+
# Save the updated manifest
48+
$updatedContent | Set-Content 'zed-cli-win-unofficial.json' -NoNewline
49+
Write-Host "✅ Created fixed manifest: zed-cli-win-unofficial.json"
50+
Write-Host " Size: $((Get-Item 'zed-cli-win-unofficial.json').Length) bytes"
51+
}
52+
else {
53+
Write-Host "ℹ️ zed.bat already exists in bin array, copying as-is"
54+
Copy-Item 'dist/scoop/zed-cli-win-unofficial.json' 'zed-cli-win-unofficial.json'
55+
}
56+
}
57+
else {
58+
Write-Host "❌ Source manifest disappeared"
59+
exit 1
60+
}
61+
62+
# Add the fixed manifest file
63+
git add zed-cli-win-unofficial.json
64+
if ($LASTEXITCODE -ne 0) {
65+
Write-Host "❌ Failed to add file to git staging"
66+
exit 1
67+
}
68+
Write-Host "📝 Added file to git staging"
69+
70+
# Check if there are changes to commit
71+
$gitStatus = git status --porcelain
72+
if ($gitStatus) {
73+
# Commit with descriptive message
74+
$commitMessage = "Scoop update for zed-cli-win-unofficial version ${env:GITHUB_REF_NAME} with zed.bat"
75+
git commit -m $commitMessage
2076
if ($LASTEXITCODE -ne 0) {
21-
Write-Host "❌ Failed to checkout main branch"
77+
Write-Host "❌ Failed to commit changes"
2278
exit 1
2379
}
80+
Write-Host "✅ Committed changes with message: '$commitMessage'"
2481

25-
# Get the current branch name
26-
$currentBranch = git branch --show-current
27-
Write-Host "📋 Current branch: $currentBranch"
28-
29-
# Add the fixed manifest file
30-
git add zed-cli-win-unofficial.json
82+
# Push to the current branch
83+
git push origin $currentBranch
3184
if ($LASTEXITCODE -ne 0) {
32-
Write-Host "❌ Failed to add file to git staging"
85+
Write-Host "❌ Failed to push changes to $currentBranch"
3386
exit 1
3487
}
35-
Write-Host "📝 Added file to git staging"
36-
37-
# Check if there are changes to commit
38-
$gitStatus = git status --porcelain
39-
if ($gitStatus) {
40-
# Commit with descriptive message
41-
$commitMessage = "Scoop update for zed-cli-win-unofficial version ${env:GITHUB_REF_NAME} with zed.bat"
42-
git commit -m $commitMessage
43-
if ($LASTEXITCODE -ne 0) {
44-
Write-Host "❌ Failed to commit changes"
45-
exit 1
46-
}
47-
Write-Host "✅ Committed changes with message: '$commitMessage'"
48-
49-
# Push to the current branch
50-
git push origin $currentBranch
51-
if ($LASTEXITCODE -ne 0) {
52-
Write-Host "❌ Failed to push changes to $currentBranch"
53-
exit 1
54-
}
55-
Write-Host "🚀 Pushed changes to $currentBranch branch"
56-
57-
Write-Host ""
58-
Write-Host "🎉 Successfully updated scoop manifest!"
59-
}
60-
else {
61-
Write-Host "ℹ️ No changes to commit (manifest may already be up to date)"
62-
}
88+
Write-Host "🚀 Pushed changes to $currentBranch branch"
6389

90+
Write-Host ""
91+
Write-Host "🎉 Successfully updated scoop manifest!"
6492
}
6593
else {
66-
Write-Host "❌ No manifest file found to commit"
67-
exit 1
94+
Write-Host "ℹ️ No changes to commit (manifest may already be up to date)"
6895
}

0 commit comments

Comments
 (0)