<commit_before>#!/usr/bin/env bash
# Script for build preview of this repo like in https://kyma-project.io/docs/ on every PR.
# For more information, please contact with: @m00g3n @pPrecel

set -eo pipefail

on_error() {
    echo -e "${RED}✗ Failed${NC}"
    exit 1
}
trap on_error ERR

readonly KYMA_PROJECT_IO_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

readonly WEBSITE_DIR="website"
readonly WEBSITE_REPO="https://github.com/kyma-project/website"

readonly BUILD_DIR="${KYMA_PROJECT_IO_DIR}/${WEBSITE_DIR}"
readonly PUBLIC_DIR="${KYMA_PROJECT_IO_DIR}/${WEBSITE_DIR}/public"
readonly DOCS_DIR="$( cd "${KYMA_PROJECT_IO_DIR}/../docs" && pwd )"

# Colors
readonly RED='\033[0;31m'
readonly GREEN='\033[0;32m'
readonly YELLOW='\033[0;33m'
readonly NC='\033[0m' # No Color

pass() {
  local message="$1"
  echo -e "${GREEN}√ ${message}${NC}"
}

step() {
  local message="$1"
  echo -e "\\n${YELLOW}${message}${NC}"
}

remove-cached-content() {
  ( rm -rf "${BUILD_DIR}" ) || true
}

merge-kyma() {
  git config --global user.email "<EMAIL>"
  git config --global user.name "CI/CD"
  step "Newest commit"
  git log --max-count=1

  git checkout -B pull-request
  git checkout main
  step "Last commit from main"
  git log --max-count=1

  git merge pull-request
}

copy-website-repo() {
  git clone -b "website-2.0" --single-branch "${WEBSITE_REPO}" "${WEBSITE_DIR}"
}

build-preview() {
  export APP_PREVIEW_SOURCE_DIR="${KYMA_PROJECT_IO_DIR}/.."
  export APP_DOCS_BRANCHES="preview"
  export APP_PREPARE_FOR_REPO="kyma"
  make -C "${BUILD_DIR}" netlify-docs-preview
}

copy-build-result() {
  mkdir -p "${DOCS_DIR}/.kyma-project-io/"
  cp -rp "${PUBLIC_DIR}/" "${DOCS_DIR}/.kyma-project-io/"
 
  #  DEBUG
  tree "${BUILD_DIR}"/content/docs
  cat "${BUILD_DIR}"/content/docs/kyma/versions.json
  #  DEBUG
  echo "/ /docs/kyma/preview/" > "${DOCS_DIR}"/.kyma-project-io/public/_redirects
}

main() {
  step "Remove website cached content"
  remove-cached-content
  pass "Removed"
<commit_msg>Use main branch from website (#12262)<commit_after>#!/usr/bin/env bash
# Script for build preview of this repo like in https://kyma-project.io/docs/ on every PR.
# For more information, please contact with: @m00g3n @pPrecel

set -eo pipefail

on_error() {
    echo -e "${RED}✗ Failed${NC}"
    exit 1
}
trap on_error ERR

readonly KYMA_PROJECT_IO_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

readonly WEBSITE_DIR="website"
readonly WEBSITE_REPO="https://github.com/kyma-project/website"

readonly BUILD_DIR="${KYMA_PROJECT_IO_DIR}/${WEBSITE_DIR}"
readonly PUBLIC_DIR="${KYMA_PROJECT_IO_DIR}/${WEBSITE_DIR}/public"
readonly DOCS_DIR="$( cd "${KYMA_PROJECT_IO_DIR}/../docs" && pwd )"

# Colors
readonly RED='\033[0;31m'
readonly GREEN='\033[0;32m'
readonly YELLOW='\033[0;33m'
readonly NC='\033[0m' # No Color

pass() {
  local message="$1"
  echo -e "${GREEN}√ ${message}${NC}"
}

step() {
  local message="$1"
  echo -e "\\n${YELLOW}${message}${NC}"
}

remove-cached-content() {
  ( rm -rf "${BUILD_DIR}" ) || true
}

merge-kyma() {
  git config --global user.email "<EMAIL>"
  git config --global user.name "CI/CD"
  step "Newest commit"
  git log --max-count=1

  git checkout -B pull-request
  git checkout main
  step "Last commit from main"
  git log --max-count=1

  step "merging changes from pull request to main"
  git merge pull-request
}

copy-website-repo() {
  git clone -b "main" --single-branch "${WEBSITE_REPO}" "${WEBSITE_DIR}"
}

build-preview() {
  export APP_PREVIEW_SOURCE_DIR="${KYMA_PROJECT_IO_DIR}/.."
  export APP_DOCS_BRANCHES="preview"
  export APP_PREPARE_FOR_REPO="kyma"
  make -C "${BUILD_DIR}" netlify-docs-preview
}

copy-build-result() {
  mkdir -p "${DOCS_DIR}/.kyma-project-io/"
  cp -rp "${PUBLIC_DIR}/" "${DOCS_DIR}/.kyma-project-io/"
 
  #  DEBUG
  tree "${BUILD_DIR}"/content/docs
  cat "${BUILD_DIR}"/content/docs/kyma/versions.json
  #  DEBUG
  echo "/ /docs/kyma/preview/" > "${DOCS_DIR}"/.kyma-project-io/public/_redirects
}

main() {
  step "Remove website cached content"
  remove-cached-content
  pass "Removed"

{'fraction_non_alphanumeric': 0.17657170923379176, 'fraction_numerical': 0.01694499017681729, 'mean_word_length': 4.168781725888325, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1058350', 'n_tokens_mistral': 1669, 'n_tokens_neox': 1544, 'n_words': 341}