Commit e08320ee authored by Miguel Angel Reina Ortega's avatar Miguel Angel Reina Ortega
Browse files

Fix for handling version in gl-pages

parent 0db8bef5
Loading
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -176,12 +176,15 @@ def replaceLineBreaks(progress: Progress, mdLines: list[str]) -> list[str]:
	_taskID = progress.add_task('[blue]Replacing linebreaks', total=0)
	# progress.update()
	linebreaksregex = re.compile('<\s*br\s*/?\s*>')
	# Blockquote code boundary: > then optional spaces, then ``` or 4-space indent (do not strip the line first).
	blockquotecoderegex = re.compile(r'^\s*>\s*(?:```|    )')

	_lines: list[str] = []
	_inCodeBlock = False
	for line in mdLines:
		# Check if we are in a code block
		if line.strip().startswith('```'):
		# 1- fenced ``` (leading whitespace allowed), 2- 4-space indent on raw line,
		# 3- same inside a blockquote (> optional spaces before ``` or indent)
		if line.lstrip().startswith('```') or line.startswith('    ') or blockquotecoderegex.match(line):
			_inCodeBlock = not _inCodeBlock
		if _inCodeBlock:
			_lines.append(line)
+94 −51
Original line number Diff line number Diff line
@@ -48,6 +48,16 @@ echo "CLEAN_WEB_PAGES:" ${CLEAN_WEB_PAGES}
PAGES_BRANCH=gl-pages
HTTPS_REMOTE=https://gitlab-ci-token:${MIKE_ACCESS_TOKEN}@${CI_SERVER_FQDN}/${CI_PROJECT_PATH}.git

# Parse vX.Y.Z into numeric components (base 10, so 9 < 10 works correctly).
parse_semver() {
    local tag
    tag=$(echo "$1" | tr -d '\r\n' | xargs)
    tag="${tag#v}"
    PARSE_MAJOR=$((10#$(echo "${tag}" | cut -d. -f1)))
    PARSE_INTER=$((10#$(echo "${tag}" | cut -d. -f2)))
    PARSE_MINOR=$((10#$(echo "${tag}" | cut -d. -f3)))
}

echo "\n------ Install necessary packages --------"
pip install -q mkdocs-material mike rich mkdocs-rss-plugin

@@ -115,39 +125,68 @@ python3 -c "from mkdocs.config import load_config; load_config('mkdocs.yml')" ||
if [[ ${TAG_NAME} == v* ]]; then
    echo "\nAdding download tab for version ${TAG_NAME}..."
    mkdir -p "docs/download"
    if [ ! -f docs/download/index.md ]; then
      cp /generateSpecWebSite/indexDownload.md docs/download/index.md
    fi
    if [ -f "baseline/${SPEC_NAME}_${TAG_NAME}.docx" ]; then
      mv "baseline/${SPEC_NAME}_${TAG_NAME}.docx" docs/download
      spec_name=$(echo ${SPEC_NAME/&/and})
      file_name=$(ls docs/download/*.docx)
      filename_corrected=$(echo ${file_name/&/and})
      mv docs/download/"${SPEC_NAME}_${TAG_NAME}.docx" ${filename_corrected}
      sed -i 's/SPECWORD/'"${spec_name}_${TAG_NAME}.docx"'/g' docs/download/index.md
    else
      echo "Warning: No ${SPEC_NAME}_${TAG_NAME}.docx file found in baseline directory"
      sed -i -E 's|\[!\[Word\]\(images/Word\.png\)\]\(SPECWORD\)||g' docs/download/index.md
    fi
    if [ -f "baseline/${SPEC_NAME}_${TAG_NAME}.pdf" ]; then
      mv "baseline/${SPEC_NAME}_${TAG_NAME}.pdf" docs/download
      spec_name=$(echo ${SPEC_NAME/&/and})
      file_name=$(ls docs/download/*.pdf)
      filename_corrected=$(echo ${file_name/&/and})
      mv docs/download/"${SPEC_NAME}_${TAG_NAME}.pdf" ${filename_corrected}
      sed -i 's/SPECPDF/'"${spec_name}_${TAG_NAME}.pdf"'/g' docs/download/index.md
    else
      echo "Warning: No ${SPEC_NAME}_${TAG_NAME}.pdf file found in baseline directory"
      sed -i -E 's|\[!\[Pdf\]\(images/Pdf\.png\)\]\(SPECPDF\)||g' docs/download/index.md
    fi
    if [ -f "baseline/${SPEC_NAME}_${TAG_NAME}.epub" ]; then
      mv "baseline/${SPEC_NAME}_${TAG_NAME}.epub" docs/download
      spec_name=$(echo ${SPEC_NAME/&/and})
      file_name=$(ls docs/download/*.epub)
      filename_corrected=$(echo ${file_name/&/and})
      mv docs/download/"${SPEC_NAME}_${TAG_NAME}.epub" ${filename_corrected}
      sed -i 's/SPECEPUB/'"${spec_name}_${TAG_NAME}.epub"'/g' docs/download/index.md
    else
      echo "Warning: No ${SPEC_NAME}_${TAG_NAME}.epub file found in baseline directory"
      sed -i -E 's|\[!\[Epub\]\(images/Epub\.png\)\]\(SPECEPUB\)||g' docs/download/index.md
    fi
    echo ${spec_name}
    #for x in docs/download/*"&"*; do   mv -- "$x" "${x//&/and}"; done
    sed -i 's/PROJECT/'${CI_PROJECT_NAME^^}'/g' docs/download/index.md
    sed -i 's/SPECWORD/'"${spec_name}_${TAG_NAME}.docx"'/g' docs/download/index.md
    sed -i 's/SPECPDF/'"${spec_name}_${TAG_NAME}.pdf"'/g' docs/download/index.md
    sed -i 's/SPECEPUB/'"${spec_name}_${TAG_NAME}.epub"'/g' docs/download/index.md
    sed -i 's/VERSION/'${TAG_NAME}'/g' docs/download/index.md
    cat docs/download/index.md
    echo "  - Download: 'download/index.md'" >> mkdocs.yml
    echo "\nAdding release notes tab for version ${TAG_NAME}..."
    mkdir -p "docs/release_notes"
    if [ ! -f docs/release_notes/index.md ]; then
      cp /generateSpecWebSite/indexReleaseNotes.md docs/release_notes/index.md
    fi
    if [ -f "baseline/Release_Notes_${TAG_NAME}.docx" ]; then
      mv "baseline/Release_Notes_${TAG_NAME}.docx" docs/release_notes
      sed -i 's/PROJECT/'${CI_PROJECT_NAME^^}'/g' docs/release_notes/index.md
      sed -i 's/VERSION/'${TAG_NAME}'/g' docs/release_notes/index.md
      sed -i 's/SPECWORD/'"Release_Notes_${TAG_NAME}.docx"'/g' docs/release_notes/index.md
    else
      echo "Warning: No Release_Notes_${TAG_NAME}.docx file found in baseline directory"
      sed -i -E 's|\[!\[Word\]\(images/Word\.png\)\]\(SPECWORD\)||g' docs/release_notes/index.md
    fi
    sed -i 's/PROJECT/'${CI_PROJECT_NAME^^}'/g' docs/release_notes/index.md
    sed -i 's/VERSION/'${TAG_NAME}'/g' docs/release_notes/index.md
    cat docs/release_notes/index.md
    echo "  - Release Notes: 'release_notes/index.md'" >> mkdocs.yml
fi


echo "------ Content of mkdocs.yml after adding download and release notes tabs--------"
cat mkdocs.yml
echo "------ Validate mkdocs.yml after adding download and release notes tabs--------"
@@ -159,10 +198,11 @@ python3 -c "from mkdocs.config import load_config; load_config('mkdocs.yml')" ||
if [ ${CLEAN_WEB_PAGES} == "false" ]; then
    echo "------ Generating site --------"
    echo "Generating docs version ${TAG_NAME}..."
    majorVersion=$(echo ${TAG_NAME} | grep -oE v[0-9]+\. | grep -oE [0-9]+)
    interVersion=$(echo ${TAG_NAME} | cut -d. -f2)
    minorVersion=$(echo ${TAG_NAME} | cut -d. -f3)
    echo "Major version is ${majorVersion}"
    parse_semver "${TAG_NAME}"
    majorVersion=${PARSE_MAJOR}
    interVersion=${PARSE_INTER}
    minorVersion=${PARSE_MINOR}
    echo "Major version is ${majorVersion} (inter=${interVersion}, minor=${minorVersion})"
    if [ -n "${majorVersion}" ]; then
        releaseVersion="latestR${majorVersion}"
        echo "Handling release ${releaseVersion}"
@@ -178,58 +218,60 @@ if [ ${CLEAN_WEB_PAGES} == "false" ]; then
          mike set-default --deploy-prefix public -r $HTTPS_REMOTE -p -b $PAGES_BRANCH latest #That's only needed the first time gl-pages is created
      else
          latestVersionDeployed=$(mike list --deploy-prefix public -r $HTTPS_REMOTE -b $PAGES_BRANCH | grep ${releaseVersion} | cut -d" " -f1)
          latestVersionDeployed_inter=$(echo ${latestVersionDeployed} |cut -d. -f2 )
          latestVersionDeployed_minor=$(echo ${latestVersionDeployed} |cut -d. -f3 )
          parse_semver "${latestVersionDeployed}"
          latestVersionDeployed_inter=${PARSE_INTER}
          latestVersionDeployed_minor=${PARSE_MINOR}
          latestRelease=$(mike list --deploy-prefix public -r $HTTPS_REMOTE -b $PAGES_BRANCH | grep latest\, | grep -o latestR[0-9]*)
          echo "Latest release is ${latestRelease}"
          echo "Latest deployed version for this release is ${latestVersionDeployed}"
          latestReleaseMajor=$((10#${latestRelease#latestR}))
          echo "Latest release is ${latestRelease} (major=${latestReleaseMajor})"
          echo "Latest deployed version for this release is ${latestVersionDeployed} (inter=${latestVersionDeployed_inter}, minor=${latestVersionDeployed_minor})"

          ##Handling versions: update latestRelease and latest (majorVersion updated)
          if [[ "${releaseVersion}" > "${latestRelease}" ]]; then
              echo "Upgrade latest release...deploying version ${TAG_NAME} as latest and ${releaseVersion}"
          if (( majorVersion > latestReleaseMajor )); then
              echo "Case A.1: Upgrade latest release...deploying version ${TAG_NAME} as latest and ${releaseVersion}"
              mike deploy --deploy-prefix public -r $HTTPS_REMOTE -p -b $PAGES_BRANCH -u ${TAG_NAME} ${releaseVersion} latest
          elif [[ "${releaseVersion}" == "${latestRelease}" ]]; then
              if [[ ${latestVersionDeployed_inter} == ${interVersion} ]]; then
                if [[ ${latestVersionDeployed_minor} < ${minorVersion} || ${latestVersionDeployed_minor} == ${minorVersion} ]]; then
                  echo "Upgrade latest release...deploying version ${TAG_NAME} as latest and ${releaseVersion}"
          elif (( majorVersion == latestReleaseMajor )); then
              if (( latestVersionDeployed_inter == interVersion )); then
                if (( latestVersionDeployed_minor < minorVersion || latestVersionDeployed_minor == minorVersion )); then
                  echo "Case B.1: Upgrade latest release...deploying version ${TAG_NAME} as latest and ${releaseVersion}"
                  mike deploy --deploy-prefix public -r $HTTPS_REMOTE -p -b $PAGES_BRANCH -u ${TAG_NAME} ${releaseVersion} latest
                  if [[ ${latestVersionDeployed_minor} < ${minorVersion} ]]; then
                  if (( latestVersionDeployed_minor < minorVersion )); then
                    echo "Hidding version ${latestVersionDeployed}..."
                    mike props --deploy-prefix public -r $HTTPS_REMOTE -p -b $PAGES_BRANCH --set hidden=true "${latestVersionDeployed}"
                  fi
                else
                  echo "Deploying version ${TAG_NAME}"
                  echo "Case B.2: Deploying version ${TAG_NAME}"
                  mike deploy --deploy-prefix public -r $HTTPS_REMOTE -p -b $PAGES_BRANCH -u ${TAG_NAME}
                  echo "Hidding version ${TAG_NAME}..."
                  mike props --deploy-prefix public -r $HTTPS_REMOTE -p -b $PAGES_BRANCH --set hidden=true "${TAG_NAME}"
                fi
              elif [[ ${latestVersionDeployed_inter} < ${interVersion} ]]; then
                echo "Upgrade latest release...deploying version ${TAG_NAME} as latest and ${releaseVersion}"
              elif (( latestVersionDeployed_inter < interVersion )); then
                echo "Case B.3: Upgrade latest release...deploying version ${TAG_NAME} as latest and ${releaseVersion}"
                mike deploy --deploy-prefix public -r $HTTPS_REMOTE -p -b $PAGES_BRANCH -u ${TAG_NAME} ${releaseVersion} latest
              else
                echo "Deploying version ${TAG_NAME}"
                echo "Case B.4: Deploying version ${TAG_NAME}"
                mike deploy --deploy-prefix public -r $HTTPS_REMOTE -p -b $PAGES_BRANCH -u ${TAG_NAME}
              fi
          else
            if [[ ${latestVersionDeployed_inter} == ${interVersion} ]]; then
              if [[ ${latestVersionDeployed_minor} < ${minorVersion} || ${latestVersionDeployed_minor} == ${minorVersion} ]]; then
                echo "Deploying version ${TAG_NAME} as ${releaseVersion}"
            if (( latestVersionDeployed_inter == interVersion )); then
              if (( latestVersionDeployed_minor < minorVersion || latestVersionDeployed_minor == minorVersion )); then
                echo "Case C.1: Deploying version ${TAG_NAME} as ${releaseVersion}"
                mike deploy --deploy-prefix public -r $HTTPS_REMOTE -p -b $PAGES_BRANCH -u ${TAG_NAME} ${releaseVersion}
                if [[ ${latestVersionDeployed_minor} < ${minorVersion} ]]; then
                if (( latestVersionDeployed_minor < minorVersion )); then
                  echo "Hidding version ${latestVersionDeployed}..."
                  mike props --deploy-prefix public -r $HTTPS_REMOTE -p -b $PAGES_BRANCH --set hidden=true "${latestVersionDeployed}"
                fi
              else
                echo "Deploying version ${TAG_NAME}"
                echo "Case C.2: Deploying version ${TAG_NAME}"
                mike deploy --deploy-prefix public -r $HTTPS_REMOTE -p -b $PAGES_BRANCH -u ${TAG_NAME}
                echo "Hidding version ${TAG_NAME}..."
                mike props --deploy-prefix public -r $HTTPS_REMOTE -p -b $PAGES_BRANCH --set hidden=true "${TAG_NAME}"
              fi
            elif [[ ${latestVersionDeployed_inter} < ${interVersion} ]]; then
                echo "Deploying version ${TAG_NAME} as ${releaseVersion}"
            elif (( latestVersionDeployed_inter < interVersion )); then
                echo "Case C.3: Deploying version ${TAG_NAME} as ${releaseVersion}"
                mike deploy --deploy-prefix public -r $HTTPS_REMOTE -p -b $PAGES_BRANCH -u ${TAG_NAME} ${releaseVersion}
            else
                echo "Deploying version ${TAG_NAME}"
                echo "Case C.4: Deploying version ${TAG_NAME}"
                mike deploy --deploy-prefix public -r $HTTPS_REMOTE -p -b $PAGES_BRANCH -u ${TAG_NAME}
            fi
          fi
@@ -245,8 +287,9 @@ if [ ${CLEAN_WEB_PAGES} == "false" ]; then
    fi
else
    echo "------ Removing docs version  }..."
    majorVersion=$(echo ${CLEAN_WEB_PAGES} | grep -oE v[0-9]+\. | grep -oE [0-9]+)
    if [ -n "${majorVersion}" ]; then
    parse_semver "${CLEAN_WEB_PAGES}"
    majorVersion=${PARSE_MAJOR}
    if [[ "${CLEAN_WEB_PAGES}" == v* ]]; then
        previousVersion=$(mike list --deploy-prefix public -r $HTTPS_REMOTE -b $PAGES_BRANCH | grep v${majorVersion} | grep -A1 ${CLEAN_WEB_PAGES} | grep -v ${CLEAN_WEB_PAGES})
        releaseVersion="latestR${majorVersion}"
        echo "Major version is ${majorVersion}"
@@ -264,7 +307,7 @@ else
            mike props --deploy-prefix public -r $HTTPS_REMOTE --allow-empty -p -b $PAGES_BRANCH --set hidden=false ${previousVersion}
        else
            # Look previous release (previous major version)
            majorVersion=$(echo $((--majorVersion)))
            majorVersion=$((majorVersion - 1))
            previousReleaseVersion=$(mike list --deploy-prefix public -r $HTTPS_REMOTE -b $PAGES_BRANCH | grep latestR${majorVersion} | grep -o v[0-9]*\.[0-9]*\.[0-9]*)
            echo "Previous major version is ${majorVersion}"
            echo "Previous release version is ${previousReleaseVersion}"