<commit_before>################################################################################
# This file provides Squeak support for smalltalkCI. It is used in the context
# of a smalltalkCI build and it is not meant to be executed by itself.
################################################################################

readonly BASE_DOWNLOAD="${GITHUB_REPO_URL}/releases/download"

################################################################################
# Download Squeak image.
################################################################################
squeak::download_image() {
  local smalltalk_name=$1
  local download_name
  local git_tag

  case "${smalltalk_name}" in
    "Squeak64-5.3")
      download_name="Squeak64-5.3-19438.tar.gz"
      git_tag="v2.9.4"
      ;;
    "Squeak64-5.2")
      download_name="Squeak64-5.2-18236.tar.gz"
      git_tag="v2.9.4"
      ;;
    "Squeak64-5.1")
      download_name="Squeak64-5.1-16555.tar.gz"
      git_tag="v2.9.4"
      ;;
    "Squeak32-5.3")
      download_name="Squeak32-5.3-19438.tar.gz"
      git_tag="v2.9.4"
      ;;
    "Squeak32-5.2"|"Squeak-5.2"|"Squeak5.2")
      download_name="Squeak32-5.2-18236.tar.gz"
      git_tag="v2.9.4"
      ;;
    "Squeak32-5.1"|"Squeak-5.1"|"Squeak5.1")
      download_name="Squeak32-5.1-16555.tar.gz"
      git_tag="v2.9.4"
      ;;
    "Squeak32-5.0"|"Squeak-5.0"|"Squeak5.0")
      download_name="Squeak-5.0.tar.gz"
      git_tag="v2.7.5"
      ;;
    "Squeak32-4.6"|"Squeak-4.6"|"Squeak4.6")
      download_name="Squeak-4.6.tar.gz"
      git_tag="v2.7.5"
      ;;
    "Squeak32-4.5"|"Squeak-4.5"|"Squeak4.5")
      download_name="Squeak-4.5.tar.gz"
      git_tag="v2.7.5"
      ;;
    *)
      print_error_and_exit "Unsupported Squeak version '${smalltalk_name}'."
      ;;
  esac

  squeak::download_prepared_image "${download_name}" "${git_tag}"
}

################################################################################
# Download image and extract it.
################################################################################
squeak::download_prepared_image() {
  local download_name=$1
  local git_tag=$2
  local target="${SMALLTALK_CI_CACHE}/${download_name}"

  if ! is_file "${target}"; then
    fold_start download_image "Downloading '${download_name}' testing image..."
      download_file "${BASE_DOWNLOAD}/${git_tag}/${download_name}" "${target}"
    fold_end download_image
  fi

  print_info "Extracting image..."
  extract_file "${target}" "${SMALLTALK_CI_BUILD}"
  # TODO: cleanup soon, some archives still include TravisCI.(image|changes)
  if ! is_file "${SMALLTALK_CI_IMAGE}"; then 
    mv "${SMALLTALK_CI_BUILD}"/*.image "${SMALLTALK_CI_IMAGE}"
    mv "${SMALLTALK_CI_BUILD}"/*.changes "${SMALLTALK_CI_CHANGES}"
  fi

  if ! is_file "${SMALLTALK_CI_IMAGE}"; then
    print_error_and_exit "Failed to prepare image at '${SMALLTALK_CI_IMAGE}'."
  fi
}

################################################################################
# Download trunk image and extract it.
################################################################################
squeak::download_trunk_image() {
  local target
  local download_name
  local git_tag="v2.9.2" # 32bit/64bit are kept in sync
  local update_level="19536" # 32bit/64bit are kept in sync

  if is_64bit; then
    download_name="Squeak64-trunk-${update_level}.tar.gz"
  else
    download_name="Squeak32-trunk-${update_level}.tar.gz"
  fi
  target="${SMALLTALK_CI_BUILD}/${download_name}"

  fold_start download_image "Downloading ${config_smalltalk} image..."
    download_file "${BASE_DOWNLOAD}/${git_tag}/${download_name}" "${target}"
    extract_file "${target}" "${SMALLTALK_CI_BUILD}"
    mv "${SMALLTALK_CI_BUILD}"/*.image "${SMALLTALK_CI_IMAGE}"
    mv "${SMALLTALK_CI_BUILD}"/*.changes "${SMALLTALK_CI_CHANGES}"
  fold_end download_image

  if ! is_file "${SMALLTALK_CI_IMAGE}"; then
    print_error_and_exit "Unable to download image at '${SMALLTALK_CI_IMAGE}'."
  fi
}

################################################################################
# Ensure Metacello is installed and image is up-to-date.
################################################################################
squeak::prepare_image() {
  local status=0
  
  fold_start prepare_image "Preparing ${config_smalltalk} image for CI..."
    cp "${SMALLTALK_CI_HOME}/squeak/prepare.st" \<commit_msg>Upgrade Squeak trunk images to 20447<commit_after>################################################################################
# This file provides Squeak support for smalltalkCI. It is used in the context
# of a smalltalkCI build and it is not meant to be executed by itself.
################################################################################

readonly BASE_DOWNLOAD="${GITHUB_REPO_URL}/releases/download"

################################################################################
# Download Squeak image.
################################################################################
squeak::download_image() {
  local smalltalk_name=$1
  local download_name
  local git_tag

  case "${smalltalk_name}" in
    "Squeak64-5.3")
      download_name="Squeak64-5.3-19438.tar.gz"
      git_tag="v2.9.4"
      ;;
    "Squeak64-5.2")
      download_name="Squeak64-5.2-18236.tar.gz"
      git_tag="v2.9.4"
      ;;
    "Squeak64-5.1")
      download_name="Squeak64-5.1-16555.tar.gz"
      git_tag="v2.9.4"
      ;;
    "Squeak32-5.3")
      download_name="Squeak32-5.3-19438.tar.gz"
      git_tag="v2.9.4"
      ;;
    "Squeak32-5.2"|"Squeak-5.2"|"Squeak5.2")
      download_name="Squeak32-5.2-18236.tar.gz"
      git_tag="v2.9.4"
      ;;
    "Squeak32-5.1"|"Squeak-5.1"|"Squeak5.1")
      download_name="Squeak32-5.1-16555.tar.gz"
      git_tag="v2.9.4"
      ;;
    "Squeak32-5.0"|"Squeak-5.0"|"Squeak5.0")
      download_name="Squeak-5.0.tar.gz"
      git_tag="v2.7.5"
      ;;
    "Squeak32-4.6"|"Squeak-4.6"|"Squeak4.6")
      download_name="Squeak-4.6.tar.gz"
      git_tag="v2.7.5"
      ;;
    "Squeak32-4.5"|"Squeak-4.5"|"Squeak4.5")
      download_name="Squeak-4.5.tar.gz"
      git_tag="v2.7.5"
      ;;
    *)
      print_error_and_exit "Unsupported Squeak version '${smalltalk_name}'."
      ;;
  esac

  squeak::download_prepared_image "${download_name}" "${git_tag}"
}

################################################################################
# Download image and extract it.
################################################################################
squeak::download_prepared_image() {
  local download_name=$1
  local git_tag=$2
  local target="${SMALLTALK_CI_CACHE}/${download_name}"

  if ! is_file "${target}"; then
    fold_start download_image "Downloading '${download_name}' testing image..."
      download_file "${BASE_DOWNLOAD}/${git_tag}/${download_name}" "${target}"
    fold_end download_image
  fi

  print_info "Extracting image..."
  extract_file "${target}" "${SMALLTALK_CI_BUILD}"
  # TODO: cleanup soon, some archives still include TravisCI.(image|changes)
  if ! is_file "${SMALLTALK_CI_IMAGE}"; then 
    mv "${SMALLTALK_CI_BUILD}"/*.image "${SMALLTALK_CI_IMAGE}"
    mv "${SMALLTALK_CI_BUILD}"/*.changes "${SMALLTALK_CI_CHANGES}"
  fi

  if ! is_file "${SMALLTALK_CI_IMAGE}"; then
    print_error_and_exit "Failed to prepare image at '${SMALLTALK_CI_IMAGE}'."
  fi
}

################################################################################
# Download trunk image and extract it.
################################################################################
squeak::download_trunk_image() {
  local target
  local download_name
  local git_tag="v2.9.6" # 32bit/64bit are kept in sync
  local update_level="20447" # 32bit/64bit are kept in sync

  if is_64bit; then
    download_name="Squeak64-trunk-${update_level}.tar.gz"
  else
    download_name="Squeak32-trunk-${update_level}.tar.gz"
  fi
  target="${SMALLTALK_CI_BUILD}/${download_name}"

  fold_start download_image "Downloading ${config_smalltalk} image..."
    download_file "${BASE_DOWNLOAD}/${git_tag}/${download_name}" "${target}"
    extract_file "${target}" "${SMALLTALK_CI_BUILD}"
    mv "${SMALLTALK_CI_BUILD}"/*.image "${SMALLTALK_CI_IMAGE}"
    mv "${SMALLTALK_CI_BUILD}"/*.changes "${SMALLTALK_CI_CHANGES}"
  fold_end download_image

  if ! is_file "${SMALLTALK_CI_IMAGE}"; then
    print_error_and_exit "Unable to download image at '${SMALLTALK_CI_IMAGE}'."
  fi
}

################################################################################
# Ensure Metacello is installed and image is up-to-date.
################################################################################
squeak::prepare_image() {
  local status=0
  
  fold_start prepare_image "Preparing ${config_smalltalk} image for CI..."
    cp "${SMALLTALK_CI_HOME}/squeak/prepare.st" \
{'fraction_non_alphanumeric': 0.30888206527919937, 'fraction_numerical': 0.03900830205845559, 'mean_word_length': 4.6882276843467015, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 74, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1944867', 'n_tokens_mistral': 3150, 'n_tokens_neox': 2900, 'n_words': 461}