Skip to content

Commit 0a6de4c

Browse files
author
Codesphere Developer
committed
fix(ci): load environment in patch generator
Sourced ci/env.sh in generate-brand-patch.sh to ensure VSCODE_QUALITY and other environment variables are available for get_repo.sh execution.
1 parent e7c20c5 commit 0a6de4c

File tree

1 file changed

+48
-27
lines changed

1 file changed

+48
-27
lines changed

ci/generate-brand-patch.sh

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,62 @@
11
#!/usr/bin/env bash
22
# Codesphere Patch Generator
3-
# This script generates the codesphere-brand.patch file by applying branding changes
4-
# to a clean VSCodium vscode checkout and creating a git diff.
3+
# Generates codesphere-brand.patch by applying branding to a clean VSCodium checkout.
4+
# Uses a temporary directory to avoid modifying the VSCodium submodule source.
55

66
set -e
77

88
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
99
REPO_ROOT="$SCRIPT_DIR/.."
10-
VSCODIUM_DIR="$REPO_ROOT/vendor/vscodium"
11-
VSCODE_DIR="$VSCODIUM_DIR/vscode"
10+
VSCODIUM_SUBMODULE="$REPO_ROOT/vendor/vscodium"
1211
PATCH_OUTPUT="$SCRIPT_DIR/patches/codesphere-brand.patch"
1312

13+
# Load central environment (if not already loaded)
14+
if [ -f "$REPO_ROOT/ci/env.sh" ]; then
15+
. "$REPO_ROOT/ci/env.sh"
16+
fi
17+
18+
# Temporary workspace vars
19+
TEMP_ROOT="$REPO_ROOT/build_temp"
20+
TEMP_VSCODIUM="$TEMP_ROOT/vscodium"
21+
TEMP_VSCODE="$TEMP_VSCODIUM/vscode"
22+
1423
echo "🔧 Codesphere Brand Patch Generator"
1524
echo "===================================="
16-
echo ""
25+
echo "Working directory: $TEMP_ROOT"
1726

18-
# Ensure we're in a git repo
19-
if [ ! -d "$VSCODE_DIR/.git" ]; then
20-
echo "❌ Error: $VSCODE_DIR is not a git repository"
21-
echo "Please run vendor/vscodium/get_repo.sh first to initialize the vscode directory"
22-
exit 1
23-
fi
27+
# Cleanup any previous run
28+
rm -rf "$TEMP_ROOT"
29+
mkdir -p "$TEMP_VSCODIUM"
2430

25-
cd "$VSCODE_DIR" || exit 1
31+
# 1. Copy VSCodium scripts to temp dir (so we can fix CRLF safely)
32+
echo "📦 Copying VSCodium scripts to temp workspace..."
33+
cp -r "$VSCODIUM_SUBMODULE/"* "$TEMP_VSCODIUM/"
2634

27-
# Make sure the working directory is clean
28-
if [ -n "$(git status --porcelain)" ]; then
29-
echo "⚠️ Warning: vscode directory has uncommitted changes"
30-
echo "Resetting to clean state..."
31-
git reset --hard HEAD
32-
git clean -fd
35+
# 2. Fix CRLF line endings in the temp scripts (crucial for Windows/WSL)
36+
echo "🔧 Fixing CRLF line endings in temp scripts..."
37+
find "$TEMP_VSCODIUM" -name "*.sh" -type f -exec sed -i 's/\r$//' {} +
38+
39+
# 3. Fetch VS Code source using the temp scripts
40+
echo "📥 Fetching VS Code source (this may take time)..."
41+
cd "$TEMP_VSCODIUM" || exit 1
42+
# Force bash usage to ensuring expected behavior
43+
bash ./get_repo.sh
44+
45+
# 4. Verify fetch success
46+
if [ ! -d "$TEMP_VSCODE/.git" ]; then
47+
echo "❌ Error: Failed to fetch vscode source in temp dir"
48+
exit 1
3349
fi
3450

35-
echo "✅ Clean vscode checkout ready"
51+
echo "✅ Clean vscode checkout ready in temp dir"
3652
echo ""
3753
echo "🎨 Applying Codesphere branding changes..."
3854

39-
# Apply all the branding replacements that were in enforce-branding.sh
40-
# First, github.com/VSCodium -> github.com/Codesphere
55+
cd "$TEMP_VSCODE" || exit 1
56+
57+
# Apply branding replacements (Regex logic from original enforce-branding.sh)
58+
59+
# github.com/VSCodium -> github.com/Codesphere
4160
find . -type f \( -name "*.ts" -o -name "*.js" -o -name "*.html" -o -name "*.json" -o -name "*.md" -o -name "*.iss" -o -name "*.xml" -o -name "*.spec.template" -o -name "*.yaml" -o -name "*.template" -o -name "*.rs" -o -name "*.isl" -o -name "*.txt" -o -name "*.toml" \) \
4261
-not -path "*/node_modules/*" -not -path "*/.git/*" \
4362
-exec perl -pi -e 's/github\.com\/VSCodium/github.com\/Codesphere/g' {} + 2>/dev/null || true
@@ -72,24 +91,26 @@ find . -type f \( -name "*.ts" -o -name "*.js" -o -name "*.html" -o -name "*.jso
7291
-not -path "*/node_modules/*" -not -path "*/.git/*" \
7392
-exec perl -pi -e 's/code\.visualstudio\.com/codesphere.com/g' {} + 2>/dev/null || true
7493

75-
echo "✅ Branding changes applied"
94+
echo "✅ Branding changes applied to temp source"
7695
echo ""
7796
echo "📝 Generating patch file..."
7897

79-
# Generate the patch
98+
# Generate the patch from the temp repo
8099
git add -A
81100
git diff --cached > "$PATCH_OUTPUT"
82101

83-
# Reset the changes
84-
git reset --hard HEAD
85-
git clean -fd
86-
87102
echo ""
88103
if [ -s "$PATCH_OUTPUT" ]; then
89104
PATCH_LINES=$(wc -l < "$PATCH_OUTPUT")
90105
echo "✅ Patch generated successfully!"
91106
echo " File: $PATCH_OUTPUT"
92107
echo " Lines: $PATCH_LINES"
108+
109+
# Cleanup
110+
echo "🧹 Cleaning up temp workspace..."
111+
cd "$REPO_ROOT"
112+
rm -rf "$TEMP_ROOT"
113+
echo "✨ Done."
93114
else
94115
echo "❌ No changes detected - patch file is empty"
95116
exit 1

0 commit comments

Comments
 (0)