diff --git a/.gitignore b/.gitignore index ebc5fe3e2..db51c0f48 100644 --- a/.gitignore +++ b/.gitignore @@ -112,5 +112,8 @@ docs/public/ # Typedoc generated files modules/**/generated/ +# ignore branch specific content files that are generated +branch_content + # PyCharm .idea \ No newline at end of file diff --git a/build-config.json b/build-config.json new file mode 100644 index 000000000..b5957b778 --- /dev/null +++ b/build-config.json @@ -0,0 +1,3 @@ +{ + "branches": ["10.5.0.cl"] +} diff --git a/gatsby-node.js b/gatsby-node.js index 2b1ace902..b8f7380ed 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -30,7 +30,6 @@ exports.createPages = async function ({ actions, graphql }) { relativePath } } - } } } @@ -39,24 +38,24 @@ exports.createPages = async function ({ actions, graphql }) { const namePageIdMap = {}; data.allAsciidoc.edges.forEach((e) => { - const { sourceInstanceName: sourceName, relativePath : relPath } = e.node.parent; + const { + sourceInstanceName: sourceName, + relativePath: relPath, + } = e.node.parent; const pageId = e.node.pageAttributes.pageid; - if (sourceName === 'tutorials'){ - const relPathSplit = relPath.split('/'); - const pageIdSplit = pageId.split('__'); - let finalPageId = pageId; - if( pageIdSplit.length > 1) { + if (sourceName === 'tutorials') { + const relPathSplit = relPath.split('/'); + const pageIdSplit = pageId.split('__'); + let finalPageId = pageId; + if (pageIdSplit.length > 1) { finalPageId = pageIdSplit[1]; - } - let mapPageId = `tutorials/` + finalPageId; - if(relPathSplit.length > 1) { - mapPageId = `tutorials/${relPathSplit[0]}/` + finalPageId; - } - namePageIdMap[e.node.parent.name] = - mapPageId || NOT_FOUND_PAGE_ID; - } - - else { + } + let mapPageId = `tutorials/${finalPageId}`; + if (relPathSplit.length > 1) { + mapPageId = `tutorials/${relPathSplit[0]}/${finalPageId}`; + } + namePageIdMap[e.node.parent.name] = mapPageId || NOT_FOUND_PAGE_ID; + } else { namePageIdMap[e.node.parent.name] = e.node.pageAttributes.pageid || NOT_FOUND_PAGE_ID; } @@ -64,33 +63,42 @@ exports.createPages = async function ({ actions, graphql }) { data.allAsciidoc.edges.forEach((edge) => { const { pageid: pageId } = edge.node.pageAttributes; - const { sourceInstanceName: sourceName, relativePath : relPath } = edge.node.parent; + const { + sourceInstanceName: sourceName, + relativePath: relPath, + } = edge.node.parent; // Tutorials module pageids follow pattern {subdirectory}_{final_url_stub} to give unique IDs in system but allow directory structure in URL - if (sourceName === 'tutorials'){ - // One-level of subdirectory part of stub - const relPathSplit = relPath.split('/'); - const pageIdSplit = pageId.split('__'); - let finalPageId = pageId; - if( pageIdSplit.length > 1) { + if (sourceName === 'tutorials') { + // One-level of subdirectory part of stub + const relPathSplit = relPath.split('/'); + const pageIdSplit = pageId.split('__'); + let finalPageId = pageId; + if (pageIdSplit.length > 1) { finalPageId = pageIdSplit[1]; - } + } - let finalPath = `/tutorials/${finalPageId}`; - if(relPathSplit.length > 1) { - finalPath = `/tutorials/${relPathSplit[0]}/${finalPageId}`; - } - - actions.createPage({ - path: finalPath, - component: require.resolve( - './src/components/DevDocTemplate/index.tsx', - ), - context: { pageId, navId: DOC_NAV_PAGE_ID, namePageIdMap }, - }); - } + let finalPath = `/tutorials/${finalPageId}`; + if (relPathSplit.length > 1) { + finalPath = `/tutorials/${relPathSplit[0]}/${finalPageId}`; + } - else { + actions.createPage({ + path: finalPath, + component: require.resolve( + './src/components/DevDocTemplate/index.tsx', + ), + context: { pageId, navId: DOC_NAV_PAGE_ID, namePageIdMap }, + }); + } else if (relPath.startsWith('10.5')) { + actions.createPage({ + path: `/10.5/${pageId}`, + component: require.resolve( + './src/components/DevDocTemplate/index.tsx', + ), + context: { pageId, navId: DOC_NAV_PAGE_ID, namePageIdMap }, + }); + } else { actions.createPage({ path: `/${pageId}`, component: require.resolve( diff --git a/scripts/pre-build/stage-build.sh b/scripts/pre-build/stage-build.sh new file mode 100755 index 000000000..a61ca8512 --- /dev/null +++ b/scripts/pre-build/stage-build.sh @@ -0,0 +1,85 @@ +#!/bin/bash + +# Color codes for better logging visibility +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +BLUE='\033[0;34m' +RESET='\033[0m' + +# This script is executed before the build starts. + +# Function to install packages with retry and logging +install_deps() { + local dependencies=("$@") + + for dep in "${dependencies[@]}"; do + echo -e "${BLUE}Installing package: $dep...${RESET}" + + # First try apt-get installation + if apt-get update && apt-get install -y "$dep"; then + echo -e "${GREEN}$dep installed successfully with apt-get.${RESET}" + else + echo -e "${RED}apt-get failed. Trying to install $dep with brew...${RESET}" + + # Fallback to brew if apt-get fails + if command -v brew &> /dev/null; then + if brew install "$dep"; then + echo -e "${GREEN}$dep installed successfully with brew.${RESET}" + else + echo -e "${RED}Failed to install $dep with brew.${RESET}" + exit 1 + fi + else + echo -e "${RED}brew is not installed. Failed to install $dep.${RESET}" + exit 1 + fi + fi + done +} + +# Main script execution +echo -e "${BLUE}Starting package installations...${RESET}" + +# List of dependencies to install +dependencies=("jq") + +install_deps "${dependencies[@]}" # Pass the list of dependencies to the function + +# install jq if not already installed via install_deps +echo -e "${YELLOW}Installing jq...${RESET}" +apt-get update && apt-get install -y jq + +# Get the current git branch +current_branch=$(git branch --show-current) + +# 0. Get a list of branches as an array of strings from the config file +branches=($(jq -r '.branches[]' build-config.json)) + +# Clean the branch_content folder +echo -e "\n${YELLOW}Cleaning the branch_content folder...${RESET}" +mkdir -p branch_content +echo -e "${GREEN}Cleaning branch_content folder completed.${RESET}" + +# 1. Copy the modules from other git branches +for branch in "${branches[@]}" +do + echo -e "\n${BLUE}Processing branch: $branch...${RESET}" + git fetch origin $branch + rm -rf modules/ROOT/pages + echo -e "${YELLOW}Copying modules from branch: $branch...${RESET}" + git checkout $branch -- modules/ROOT/pages + mkdir -p branch_content/$branch + cp -r modules/ROOT/pages/* branch_content/$branch + echo -e "${GREEN}Completed processing for branch: $branch.${RESET}" + git checkout $current_branch -- modules/ROOT/pages + # 3. Update the path variable in the ascidoc file (you can add the code for this here) +done + +# 4. Copy the modules from branch_content to the modules folder +echo -e "\n${BLUE}Copying the modules from branch_content to modules folder...${RESET}" +cp -r branch_content modules/ROOT/pages +echo -e "${GREEN}Copying modules from branch_content to modules folder completed.${RESET}" + + +echo -e "${GREEN}Script execution completed.${RESET}"