Skip to content

Commit 6c8d2a0

Browse files
committed
ci: Git optimization to generation documentation
Fixes memory issues and script crash Signed-off-by: Pierre-Yves Lapersonne <pierreyves.lapersonne@orange.com>
1 parent 23f4399 commit 6c8d2a0

File tree

1 file changed

+87
-30
lines changed

1 file changed

+87
-30
lines changed

scripts/generateWebDocumentation.sh

Lines changed: 87 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ EXIT_BAD_PARAMETER=3
5151
EXIT_CANNOT_PROCESS=4
5252

5353
on_error_signal() {
54-
_ "❌ An error occurred with command '$BASH_COMMAND'. Exits. ($EXIT_ERROR_SIG)"
54+
local exit_code=$?
55+
local line_number=${BASH_LINENO[0]}
56+
_ "❌ An error occurred with command '$BASH_COMMAND' at line $line_number (exit code: $exit_code). Exits. ($EXIT_ERROR_SIG)" true
5557
if [[ $use_git -eq 1 ]]; then
5658
clean_repo
5759
fi
@@ -244,42 +246,87 @@ echo '<!doctype html><html><head><meta http-equiv="refresh" content="0; URL= htt
244246
if [[ $use_git -eq 1 ]]; then
245247
_ "👉 Versioning documentation in service pages branch (it can take a lot of time)..."
246248

249+
# Git memory boost
250+
git config pack.windowMemory "100m"
251+
git config pack.packSizeLimit "100m"
252+
git config pack.threads "1"
253+
git config core.packedGitLimit "128m"
254+
git config core.packedGitWindowSize "128m"
255+
git config http.postBuffer 524288000
256+
247257
clean_repo
248258

249259
# git config commit.gpgsign false
250260

251261
_ "🔨 Checkout service pages branch, align with remote"
252262

263+
# Clean before all to free memory
264+
git gc --auto
265+
253266
# Check if the local branch exists.
254267
if git show-ref --verify --quiet refs/heads/"$SERVICE_PAGES_BRANCH"; then
255268
_ "🔨 Checking out local branch '$SERVICE_PAGES_BRANCH'"
256-
git checkout "$SERVICE_PAGES_BRANCH"
257-
git reset --hard origin/$SERVICE_PAGES_BRANCH # Ensure to be aligned with remote version.
269+
270+
# Delete current pages branch and create new one (memory cleanup)
271+
git branch -D "$SERVICE_PAGES_BRANCH" 2>/dev/null || true
272+
git fetch origin "$SERVICE_PAGES_BRANCH"
273+
git checkout -b "$SERVICE_PAGES_BRANCH" "origin/$SERVICE_PAGES_BRANCH"
258274
else
259275
_ "🔨 Local branch '$SERVICE_PAGES_BRANCH' does not exist. Checking out from remote."
260-
git fetch origin
261-
git checkout -b "$SERVICE_PAGES_BRANCH" origin/"$SERVICE_PAGES_BRANCH"
276+
git fetch origin "$SERVICE_PAGES_BRANCH"
277+
git checkout -b "$SERVICE_PAGES_BRANCH" "origin/$SERVICE_PAGES_BRANCH"
262278
fi
263279

280+
_ "✅ Branch '$SERVICE_PAGES_BRANCH' checked out successfully"
281+
282+
264283
_ "🔨 Applying changes"
265284

266285
# Ensure we have only updated files on destination branch.
267286
# Supposing all assets are in the branch in root level (/)
268287
# Do not remove .ico and .sg files ; keep the ones already existing in the branch
269288
# Do not remove theme-settings.json
270-
clean_directory "css"
271-
clean_directory "data"
272-
clean_directory "documentation"
273-
clean_directory "images"
274-
clean_directory "img"
275-
clean_directory "index"
276-
clean_directory "js"
277-
clean_directory "*.jpg"
278-
clean_directory ".html"
279-
clean_directory "CNAME"
280-
281-
# Copy all files from temporary folder to branch
282-
cp -r "$DOCUMENTATION_HTML_LOCATION"/* "$DOCS_DIRECTORY"
289+
_ "🔨 Cleaning old documentation files"
290+
291+
# One-line deletion comman
292+
find "$DOCS_DIRECTORY" -mindepth 1 \
293+
\( -type d -name "css" -o \
294+
-type d -name "data" -o \
295+
-type d -name "documentation" -o \
296+
-type d -name "images" -o \
297+
-type d -name "img" -o \
298+
-type d -name "index" -o \
299+
-type d -name "js" \) \
300+
-exec rm -rf {} + 2>/dev/null || true
301+
302+
# Specific deletions
303+
find "$DOCS_DIRECTORY" -maxdepth 1 \
304+
\( -name "*.jpg" -o -name "*.html" -o -name "CNAME" \) \
305+
-type f -delete 2>/dev/null || true
306+
307+
_ "✅ Cleanup completed"
308+
309+
# Copy all files from temporary folder to branch (with progress)
310+
_ "🔨 Copying documentation files (this may take several minutes)..."
311+
312+
# If available use rsync command
313+
# Otherwise fallback to cp command
314+
if command -v rsync &> /dev/null; then
315+
rsync -a --info=progress2 "$DOCUMENTATION_HTML_LOCATION/" "$DOCS_DIRECTORY/" || {
316+
_ "rsync failed, falling back to cp" true
317+
cp -r "$DOCUMENTATION_HTML_LOCATION"/* "$DOCS_DIRECTORY"
318+
}
319+
else
320+
if ! cp -r "$DOCUMENTATION_HTML_LOCATION"/* "$DOCS_DIRECTORY" 2>&1; then
321+
_ "Copy failed (exit code: $?)" true
322+
_ " Source: $DOCUMENTATION_HTML_LOCATION" true
323+
_ " Destination: $DOCS_DIRECTORY" true
324+
exit $EXIT_CANNOT_PROCESS
325+
fi
326+
fi
327+
328+
_ "✅ Files copied successfully"
329+
283330

284331
# It seems there is an issue with references of images
285332
# Need to copy them also in root images folder at least for landing page
@@ -300,18 +347,28 @@ if [[ $use_git -eq 1 ]]; then
300347
cp "$DOCS_DIRECTORY/images/OUDSTokensRaw/ic_design_token_figma_raw.png" "$DOCS_DIRECTORY/images"
301348
cp "$DOCS_DIRECTORY/images/OUDSTokensSemantic/ic_design_token_figma_semantic.png" "$DOCS_DIRECTORY/images"
302349

303-
_ "🔨 Adding things (~ $files_count files)"
304-
git add "$DOCS_DIRECTORY/css"
305-
git add "$DOCS_DIRECTORY/data"
306-
git add "$DOCS_DIRECTORY/documentation"
307-
git add "$DOCS_DIRECTORY/images"
308-
git add "$DOCS_DIRECTORY/img"
309-
git add "$DOCS_DIRECTORY/index"
310-
git add "$DOCS_DIRECTORY/js"
311-
git add "$DOCS_DIRECTORY/*.jpg"
312-
git add "$DOCS_DIRECTORY/*.json"
313-
git add "$DOCS_DIRECTORY/*.html"
314-
git add "$DOCS_DIRECTORY/CNAME"
350+
_ "🔨 Staging changes (~ $files_count files, this may take time)..."
351+
352+
# One-line add command to minimize number of commands
353+
git add "$DOCS_DIRECTORY/css" \
354+
"$DOCS_DIRECTORY/data" \
355+
"$DOCS_DIRECTORY/documentation" \
356+
"$DOCS_DIRECTORY/images" \
357+
"$DOCS_DIRECTORY/img" \
358+
"$DOCS_DIRECTORY/index" \
359+
"$DOCS_DIRECTORY/js" \
360+
"$DOCS_DIRECTORY"/*.jpg \
361+
"$DOCS_DIRECTORY"/*.json \
362+
"$DOCS_DIRECTORY"/*.html \
363+
"$DOCS_DIRECTORY/CNAME" 2>/dev/null || true
364+
365+
# Check if changes
366+
if git diff --cached --quiet; then
367+
_ "⚠️ No changes to commit"
368+
else
369+
changes_count=$(git diff --cached --numstat | wc -l)
370+
_ "✅ Staged $changes_count changes"
371+
fi
315372

316373
_ "🔨 Committing things (be ready if passwords / passphrases are asked)"
317374
commit_message=$(printf "docs: update DocC documentation for version v%s (%s)\n\nUpdate documentation for GitHub pages of version v%s of OUDS iOS library (build timestamp %s)\n\nWARNING: This is an automatic commit 🤖" "$lib_version" "$timestamp" "$lib_version" "$timestamp")

0 commit comments

Comments
 (0)