11#! /usr/bin/env bash
22
3- # script to update code snippets file from MCK in docs repository
3+ # Script to create PR in docs repository with updates of code snippets and outputs.
4+ # Prerequisites:
5+ # * OUTPUTS_VERSION_ID - evergreen version id from a snippets run, which archives outputs from tests to s3:
6+ # * evergreen patch -p mongodb-kubernetes -v public_kind_code_snippets -v public_gke_code_snippets -t all -f -y -u --browse
7+ # * or generally any test run (i.e. public run executed as part of a tag)
8+ # * 10gen/docs-mongodb-internal repository cloned to DOCS_DIR
9+ # It copies (replaces whole directories):
10+ # * snippets scripts (from the current branch)
11+ # * snippets outputs archived from s3
412# Usage:
513# cd <mongodb-kubernetes directory>
614# ./scripts/dev/update_docs_snippets.sh
715#
816# To customize directories run
9- # MCK_DIR=<path to MCK repository> DOCS_DIR=<path to docs repository> ./update_docs_snippets.sh
10- # Example:
11- # MCK_DIR=~/mdb/mongodb-kubernetes DOCS_DIR=~/mdb/docs-k8s-operator ./update_docs_snippets.sh
17+ # MCK_DIR=<path to MCK repository> DOCS_DIR=<path to docs repository> scripts/dev/update_docs_snippets.sh
18+ #
19+ # Examples:
20+ # MCK_DIR=~/mdb/mongodb-kubernetes DOCS_DIR=~/mdb/docs-k8s-operator scripts/dev/update_docs_snippets.sh
21+ # MCK_DIR=$(pwd) MCK_BRANCH=archive-snippets-outputs DOCS_DIR=~/mdb/docs-mongodb-internal \
22+ # version_id=69038706b0fce50007f25a9d scripts/dev/update_docs_snippets.sh
1223
1324set -eou pipefail
14- set -x
1525
26+ OUTPUTS_VERSION_ID=${OUTPUTS_VERSION_ID:- ${version_id:? } }
1627MCK_DIR=${MCK_DIR:- " mongodb-kubernetes" }
17- MCK_BRANCH=${MCK_BRANCH:- " master" }
1828DOCS_DIR=${DOCS_DIR:- " docs-mongodb-internal" }
1929DOCS_BRANCH=${DOCS_BRANCH:- " main" }
2030DOCS_VERSION=${DOCS_VERSION:- " upcoming" }
@@ -31,8 +41,8 @@ function prepare_repositories() {
3141 git checkout " ${DOCS_BRANCH} "
3242 git reset --hard " origin/${DOCS_BRANCH} "
3343
34- git branch " MCK-snippets-update-${version_id } " || true
35- git checkout " MCK-snippets-update-${version_id } "
44+ git branch " MCK-snippets-update-${OUTPUTS_VERSION_ID } " || true
45+ git checkout " MCK-snippets-update-${OUTPUTS_VERSION_ID } "
3646
3747 popd
3848}
@@ -56,19 +66,6 @@ function download_snippets_outputs() {
5666 fi
5767}
5868
59- function copy_files() {
60- local src_dir=" $1 "
61- local dst_dir=" $2 "
62-
63- rm -rf " ${dst_dir} "
64- mkdir -p " ${dst_dir} "
65-
66- cp -r " ${src_dir} /code_snippets" " ${dst_dir} " 2> /dev/null || true
67- cp -r " ${src_dir} /output" " ${dst_dir} " 2> /dev/null || true
68- cp " ${src_dir} /env_variables.sh" " ${dst_dir} " 2> /dev/null || true
69- cp -r " ${src_dir} /yamls" " ${dst_dir} " 2> /dev/null || true
70- }
71-
7269function prepare_docs_pr() {
7370 pushd " ${DOCS_DIR} "
7471 if [[ -z " $( git status --porcelain) " ]]; then
@@ -86,10 +83,10 @@ pushd ../
8683prepare_repositories
8784
8885tmp_dir=$( mktemp -d)
89- download_snippets_outputs " ${tmp_dir} " " ${version_id } "
90- outputs_dir=" ${tmp_dir} /${version_id } /scripts/code_snippets/tests/outputs"
86+ download_snippets_outputs " ${tmp_dir} " " ${OUTPUTS_VERSION_ID } "
87+ outputs_dir=" ${tmp_dir} /${OUTPUTS_VERSION_ID } /scripts/code_snippets/tests/outputs"
9188
92- for test_dir in ${outputs_dir} /test_* ; do
89+ for test_dir in " ${outputs_dir} " /test_* ; do
9390 echo " Replacing outputs for test: ${test_dir} "
9491 rm -rf " ${DOCS_INCLUDE_CODE_EXAMPLES_DIR} /outputs/$( basename " ${test_dir} " ) "
9592 cp -r " ${test_dir} " " ${DOCS_INCLUDE_CODE_EXAMPLES_DIR} /outputs/$( basename " ${test_dir} " ) "
0 commit comments