github.com/thanos-io/thanos@v0.32.5/scripts/website/websitepreprocess.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # Regexp take from https://semver.org/
     4  # If we want to limit those we can sort, and have only head -n X of them etc
     5  RELEASE_FILTER_RE="release-(0|[1-9]\d*)\.(0|[1-9]\d*)$"
     6  WEBSITE_DIR="website"
     7  ORIGINAL_CONTENT_DIR="docs"
     8  FILES="${WEBSITE_DIR}/docs-pre-processed/*"
     9  MDOX_CONFIG=".mdox.yaml"
    10  MDOX_PREV_CONFIG=".mdox.prev-release.yaml"
    11  
    12  # Support gtar and ggrep on OSX (installed via brew), falling back to tar and grep. On Linux
    13  # systems gtar or ggrep won't be installed, so will use tar and grep as expected.
    14  TAR=$(which gtar 2>/dev/null || which tar)
    15  GREP=$(which ggrep 2>/dev/null || which grep)
    16  
    17  # Exported for use in .mdox.prev-release.yaml
    18  export OUTPUT_CONTENT_DIR="${WEBSITE_DIR}/docs-pre-processed"
    19  
    20  git remote add upstream https://github.com/thanos-io/thanos.git
    21  git remote add origin https://github.com/thanos-io/thanos.git
    22  git remote -v
    23  git fetch origin
    24  
    25  RELEASE_BRANCHES=$(git branch --all | $GREP -P "remotes/origin/${RELEASE_FILTER_RE}" | egrep --invert-match '(:?HEAD|main)$' | sort -V)
    26  echo ">> chosen $(echo ${RELEASE_BRANCHES}) releases to deploy docs from"
    27  
    28  # preprocess tip separately
    29  rm -rf ${OUTPUT_CONTENT_DIR}
    30  PATH=$PATH:$GOBIN
    31  # Exported for use in .mdox.yaml.
    32  export INPUT_DIR="docs"
    33  export OUTPUT_DIR="${OUTPUT_CONTENT_DIR}/tip"
    34  export EXTERNAL_GLOB_REL="../"
    35  $MDOX transform --log.level=debug --config-file=$MDOX_CONFIG
    36  scripts/website/mdoxpostprocess.sh "${OUTPUT_CONTENT_DIR}/tip" 100000
    37  
    38  #create variable for weight value
    39  WEIGHT_VALUE=0
    40  
    41  for branchRef in ${RELEASE_BRANCHES}; do
    42    WEIGHT_VALUE=$((WEIGHT_VALUE + 1))
    43    branchName=${branchRef##*/}
    44    # Exported for use in .mdox.prev-release.yaml
    45    export tags=${branchName/release-/v}
    46    echo ">> cloning docs for versioning ${tags}"
    47    mkdir -p "${OUTPUT_CONTENT_DIR}/${tags}-git-docs"
    48    git archive --format=tar "refs/${branchRef}" | $TAR -C${OUTPUT_CONTENT_DIR}/${tags}-git-docs -x "docs/" --strip-components=1
    49    # Frontmatter isn't present after v0.22 so .mdox.yaml is used after that.
    50    if [[ $WEIGHT_VALUE -gt 22 ]]; then
    51      # Exported for use in .mdox.yaml.
    52      export INPUT_DIR="${OUTPUT_CONTENT_DIR}/${tags}-git-docs"
    53      export OUTPUT_DIR="${OUTPUT_CONTENT_DIR}/${tags}"
    54      export EXTERNAL_GLOB_REL="../../../"
    55      $MDOX transform --log.level=debug --config-file=$MDOX_CONFIG
    56    else
    57      $MDOX transform --log.level=debug --config-file=$MDOX_PREV_CONFIG
    58    fi
    59    scripts/website/mdoxpostprocess.sh "${OUTPUT_CONTENT_DIR}/${tags}" ${WEIGHT_VALUE}
    60    rm -rf ${OUTPUT_CONTENT_DIR}/${tags}-git-docs
    61  done