Skip to content

Commit fbd9eaf

Browse files
authored
Merge pull request #9603 from microsoft/ntrogh/optimize-build
Update docs build scripts
2 parents e1275e1 + b5b6b77 commit fbd9eaf

3 files changed

Lines changed: 338 additions & 0 deletions

File tree

build/docs-release-part1.sh

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/bash
2+
# Prepare a new VS Code release (Part 1)
3+
# Usage: ./docs-release-part1.sh <version> <releaseDate> <commitHash>
4+
#
5+
# Example:
6+
# ./build/docs-release-part1.sh 1.114.0 2026-04-02 abc123...def
7+
8+
set -e
9+
10+
show_help() {
11+
cat << EOF
12+
Usage: ./build/docs-release-part1.sh <version> <releaseDate> <commitHash>
13+
14+
Prepares a new VS Code Stable release by running the following steps:
15+
1. Create the release notes file from the endgame template
16+
2. Update the VS Code commit hash and version in templates
17+
3. Export and clean up default keybindings
18+
19+
Arguments:
20+
version The full version string (e.g. 1.114.0)
21+
releaseDate The release date in YYYY-MM-DD format (e.g. 2026-04-02)
22+
commitHash The 40-character git commit hash from the VS Code build
23+
24+
Options:
25+
-h, --help Show this help message
26+
27+
The commit hash and version can be found at:
28+
https://builds.code.visualstudio.com/builds/stable
29+
30+
Example:
31+
./build/docs-release-part1.sh 1.114.0 2026-04-02 a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4e5f6a1b2
32+
EOF
33+
}
34+
35+
# Check for help flag
36+
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
37+
show_help
38+
exit 0
39+
fi
40+
41+
# Validate arguments
42+
if [ "$#" -ne 3 ]; then
43+
echo "Error: Expected 3 arguments, got $#."
44+
echo "Usage: ./build/docs-release-part1.sh <version> <releaseDate> <commitHash>"
45+
echo "Run with --help for more information."
46+
exit 1
47+
fi
48+
49+
VERSION="$1"
50+
RELEASE_DATE="$2"
51+
COMMIT_HASH="$3"
52+
53+
# Derive release number and milestone from version (e.g. 1.114.0 → 114)
54+
RELEASE_NUMBER=$(echo "$VERSION" | cut -d. -f2)
55+
MILESTONE="$VERSION"
56+
57+
# Determine the script directory and project root
58+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
59+
ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
60+
61+
echo "=== VS Code Release Preparation (Part 1) ==="
62+
echo ""
63+
echo " Release number: $RELEASE_NUMBER"
64+
echo " Release date: $RELEASE_DATE"
65+
echo " Milestone: $MILESTONE"
66+
echo " Commit hash: $COMMIT_HASH"
67+
echo " Version: $VERSION"
68+
echo ""
69+
70+
# Step 1: Create release notes
71+
echo "--- Step 1: Create release notes ---"
72+
node "$SCRIPT_DIR/create-release-notes.js" "$RELEASE_NUMBER" "$RELEASE_DATE" "$MILESTONE"
73+
echo ""
74+
75+
# Step 2: Update VS Code version in templates
76+
echo "--- Step 2: Update VS Code version ---"
77+
node "$SCRIPT_DIR/update-vscode-version.js" "$COMMIT_HASH" "$VERSION"
78+
echo ""
79+
80+
# Step 3: Export default keybindings
81+
echo "--- Step 3: Export default keybindings ---"
82+
KEYBINDINGS_DIR="$SCRIPT_DIR/keybindings"
83+
code-insiders --disable-extensions --export-default-keybindings "$KEYBINDINGS_DIR"
84+
echo ""
85+
86+
# Step 4: Clean up keybindings
87+
echo "--- Step 4: Clean up keybindings ---"
88+
node "$SCRIPT_DIR/cleanup-keybindings.js"
89+
echo ""
90+
91+
echo "=== Release preparation (Part 1) complete ==="

build/docs-release-part2.sh

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/bin/bash
2+
# Prepare a new VS Code Insiders release (Part 2)
3+
# Usage: ./build/docs-release-part2.sh <version> <releaseDate>
4+
#
5+
# Example:
6+
# ./build/docs-release-part2.sh 1.115.0 2026-05-07
7+
8+
set -e
9+
10+
show_help() {
11+
cat << EOF
12+
Usage: ./build/docs-release-part2.sh <version> <releaseDate>
13+
14+
Optimizes media content, creates Insiders release notes for the next version,
15+
and updates date metadata in documentation articles.
16+
17+
Steps performed:
18+
1. Optimize PNG images in the release-notes media folder (convert to WebP)
19+
2. Optimize MP4 videos in the release-notes media folder
20+
3. Create Insiders release notes from the template
21+
4. Update DateApproved metadata in documentation articles
22+
23+
Arguments:
24+
version The full version string (e.g. 1.115.0)
25+
releaseDate The release date in YYYY-MM-DD format (e.g. 2026-05-07)
26+
27+
Options:
28+
-h, --help Show this help message
29+
30+
Derived values:
31+
releaseNumber Extracted from version (e.g. 1.115.0 → 115)
32+
mediaFolder release-notes/images/1_<releaseNumber>
33+
milestone v<version> (e.g. v1.115.0)
34+
lastUpdated Today's date (for Insiders release notes)
35+
36+
Example:
37+
./build/docs-release-part2.sh 1.115.0 2026-05-07
38+
EOF
39+
}
40+
41+
# Check for help flag
42+
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
43+
show_help
44+
exit 0
45+
fi
46+
47+
# Validate arguments
48+
if [ "$#" -ne 2 ]; then
49+
echo "Error: Expected 2 arguments, got $#."
50+
echo "Usage: ./build/docs-release-part2.sh <version> <releaseDate>"
51+
echo "Run with --help for more information."
52+
exit 1
53+
fi
54+
55+
VERSION="$1"
56+
RELEASE_DATE="$2"
57+
58+
# Validate version format (e.g. 1.115.0)
59+
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
60+
echo "Error: version must be in the format X.Y.Z (e.g. 1.115.0)."
61+
exit 1
62+
fi
63+
64+
# Validate date format (YYYY-MM-DD)
65+
if [[ ! "$RELEASE_DATE" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
66+
echo "Error: releaseDate must be in YYYY-MM-DD format (e.g. 2026-05-07)."
67+
exit 1
68+
fi
69+
70+
# Derive values from version
71+
RELEASE_NUMBER=$(echo "$VERSION" | cut -d. -f2)
72+
MILESTONE="v$VERSION"
73+
MAJOR_MINOR="1.$RELEASE_NUMBER"
74+
MEDIA_FOLDER="release-notes/images/1_${RELEASE_NUMBER}"
75+
LAST_UPDATED=$(date +%Y-%m-%d)
76+
77+
# Determine the script directory and project root
78+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
79+
ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
80+
81+
echo "=== VS Code Release Preparation (Part 2 — Insiders) ==="
82+
echo ""
83+
echo " Version: $VERSION"
84+
echo " Release number: $RELEASE_NUMBER"
85+
echo " Release date: $RELEASE_DATE"
86+
echo " Milestone: $MILESTONE"
87+
echo " Media folder: $MEDIA_FOLDER"
88+
echo " Last updated: $LAST_UPDATED"
89+
echo ""
90+
91+
cd "$ROOT_DIR"
92+
93+
# Step 1: Optimize images
94+
echo "--- Step 1: Optimize images ---"
95+
if [ -d "$MEDIA_FOLDER" ]; then
96+
bash "$SCRIPT_DIR/optimize-images.sh" "$MEDIA_FOLDER"
97+
else
98+
echo "Skipping: Media folder not found ($MEDIA_FOLDER)"
99+
fi
100+
echo ""
101+
102+
# Step 2: Optimize videos
103+
echo "--- Step 2: Optimize videos ---"
104+
if [ -d "$MEDIA_FOLDER" ]; then
105+
bash "$SCRIPT_DIR/optimize-videos.sh" "$MEDIA_FOLDER"
106+
else
107+
echo "Skipping: Media folder not found ($MEDIA_FOLDER)"
108+
fi
109+
echo ""
110+
111+
# Step 3: Create Insiders release notes
112+
echo "--- Step 3: Create Insiders release notes ---"
113+
node "$SCRIPT_DIR/create-release-notes.js" --insiders "$RELEASE_NUMBER" "$RELEASE_DATE" "$MILESTONE" "$LAST_UPDATED"
114+
echo ""
115+
116+
# Step 4: Update date metadata
117+
echo "--- Step 4: Update date metadata ---"
118+
node "$SCRIPT_DIR/update-dates.js" "$MAJOR_MINOR" "$RELEASE_DATE"
119+
echo ""
120+
121+
echo "=== Release preparation (Part 2) complete ==="

build/optimize-images.sh

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#!/bin/bash
2+
# Convert PNG images to WebP and update markdown references
3+
# Usage: ./optimize-images.sh <media-folder>
4+
5+
show_help() {
6+
cat << EOF
7+
Usage: ./optimize-images.sh <media-folder>
8+
9+
Converts all PNG images in the specified folder to WebP format using ffmpeg,
10+
then updates any markdown files that reference those images.
11+
12+
Arguments:
13+
media-folder Path to the folder containing PNG files to convert
14+
(e.g., release-notes/images/1_113)
15+
16+
Options:
17+
-h, --help Show this help message
18+
19+
Example:
20+
./optimize-images.sh release-notes/images/1_113
21+
22+
Note: Original PNG files are removed after successful conversion.
23+
EOF
24+
}
25+
26+
# Check for help flag
27+
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
28+
show_help
29+
exit 0
30+
fi
31+
32+
# Check if folder argument is provided
33+
if [ -z "$1" ]; then
34+
echo "Error: Missing media folder argument."
35+
echo "Usage: ./optimize-images.sh <media-folder>"
36+
echo "Run with --help for more information."
37+
exit 1
38+
fi
39+
40+
MEDIA_FOLDER="$1"
41+
42+
# Check if folder exists
43+
if [ ! -d "$MEDIA_FOLDER" ]; then
44+
echo "Error: Folder not found: $MEDIA_FOLDER"
45+
exit 1
46+
fi
47+
48+
# Check if ffmpeg is available
49+
if ! command -v ffmpeg &> /dev/null; then
50+
echo "Error: ffmpeg is not installed or not in PATH."
51+
echo "Please install ffmpeg to use this script."
52+
exit 1
53+
fi
54+
55+
# Count PNG files
56+
shopt -s nullglob
57+
png_files=("$MEDIA_FOLDER"/*.png)
58+
png_count=${#png_files[@]}
59+
shopt -u nullglob
60+
61+
if [ "$png_count" -eq 0 ]; then
62+
echo "No PNG files found in $MEDIA_FOLDER"
63+
exit 0
64+
fi
65+
66+
echo "Found $png_count PNG file(s) in $MEDIA_FOLDER"
67+
echo "Converting to WebP..."
68+
echo ""
69+
70+
# Process each PNG file
71+
processed=0
72+
failed=0
73+
converted_files=()
74+
75+
for file in "$MEDIA_FOLDER"/*.png; do
76+
[ -e "$file" ] || continue
77+
78+
filename=$(basename "$file")
79+
webp_file="${file%.png}.webp"
80+
81+
echo "Processing: $filename"
82+
83+
if ffmpeg -hide_banner -loglevel error -i "$file" "$webp_file" -y; then
84+
rm "$file"
85+
echo " ✓ Converted: $filename${filename%.png}.webp"
86+
converted_files+=("$filename")
87+
processed=$((processed + 1))
88+
else
89+
echo " ✗ Failed to convert $filename"
90+
rm -f "$webp_file"
91+
failed=$((failed + 1))
92+
fi
93+
94+
echo ""
95+
done
96+
97+
# Update markdown references
98+
if [ "${#converted_files[@]}" -gt 0 ]; then
99+
echo "Updating markdown references..."
100+
101+
# Determine the markdown folder to search based on the media folder path
102+
# e.g., release-notes/images/1_113 → release-notes/
103+
# docs/copilot/images/ → docs/copilot/
104+
md_folder=$(echo "$MEDIA_FOLDER" | sed 's|/images/.*|/|')
105+
106+
md_updated=0
107+
for png_name in "${converted_files[@]}"; do
108+
webp_name="${png_name%.png}.webp"
109+
# Find and update markdown files referencing this PNG
110+
grep -rl "$png_name" "$md_folder" --include="*.md" 2>/dev/null | while read -r md_file; do
111+
sed -i "s|$png_name|$webp_name|g" "$md_file"
112+
echo " ✓ Updated reference in $md_file: $png_name$webp_name"
113+
md_updated=$((md_updated + 1))
114+
done
115+
done
116+
117+
echo ""
118+
fi
119+
120+
# Summary
121+
echo "Done!"
122+
echo "Successfully converted: $processed file(s)"
123+
if [ "$failed" -gt 0 ]; then
124+
echo "Failed: $failed file(s)"
125+
exit 1
126+
fi

0 commit comments

Comments
 (0)