1414# ./scripts/dev/update_docs_snippets.sh
1515#
1616# To customize directories run
17- # MCK_DIR=<path to MCK repository> DOCS_DIR=<path to docs repository> scripts/dev/update_docs_snippets.sh
17+ # MCK_DIR=<path to MCK repository> \
18+ # DOCS_DIR=<path to docs repository> \
19+ # scripts/dev/update_docs_snippets.sh
1820#
1921# Examples:
22+ #
2023# MCK_DIR=~/mdb/mongodb-kubernetes DOCS_DIR=~/mdb/docs-k8s-operator scripts/dev/update_docs_snippets.sh
24+ #
25+ # Create snippets PR from a 69038706b0fce50007f25a9d evg patch run
2126# MCK_DIR=$(pwd) MCK_BRANCH=archive-snippets-outputs DOCS_DIR=~/mdb/docs-mongodb-internal \
2227# version_id=69038706b0fce50007f25a9d scripts/dev/update_docs_snippets.sh
28+ #
29+ # Update a previously created snippets PR in a branch: MCK-snippets-update-690cf87c07b9040007901fac
30+ # with the updates from another patch_id=690d2946d131f20007fecfe1
31+ # MCK_DIR=~/mdb/mongodb-kubernetes \
32+ # DOCS_DIR=~/mdb/docs-mongodb-internal \
33+ # OUTPUTS_VERSION_ID=690d2946d131f20007fecfe1 \
34+ # DOCS_PR_BRANCH=MCK-snippets-update-690cf87c07b9040007901fac \
35+ # scripts/dev/update_docs_snippets.sh
2336
2437set -eou pipefail
2538
39+ test " ${MDB_BASH_DEBUG:- 0} " -eq 1 && set -x
40+
2641OUTPUTS_VERSION_ID=${OUTPUTS_VERSION_ID:- ${version_id:? } }
42+ # MCK repo dir
2743MCK_DIR=${MCK_DIR:- " mongodb-kubernetes" }
44+ # Docs repo dir
2845DOCS_DIR=${DOCS_DIR:- " docs-mongodb-internal" }
46+ # Branch on which to base snippets branch
2947DOCS_BRANCH=${DOCS_BRANCH:- " main" }
48+ # Version directory in docs repo (upcoming, current, etc.)
3049DOCS_VERSION=${DOCS_VERSION:- " upcoming" }
31- DOCS_INCLUDE_CODE_EXAMPLES_DIR=" ${DOCS_DIR} /content/kubernetes/${DOCS_VERSION} /source/includes/code-examples"
50+ # Branch name for snippets
51+ DOCS_PR_BRANCH=${DOCS_PR_BRANCH:- " MCK-snippets-update-${OUTPUTS_VERSION_ID} " }
52+
53+ docs_include_code_examples_dir=" ${DOCS_DIR} /content/kubernetes/${DOCS_VERSION} /source/includes/code-examples"
3254
3355function prepare_repositories() {
3456 pushd " ${DOCS_DIR} "
@@ -41,8 +63,8 @@ function prepare_repositories() {
4163 git checkout " ${DOCS_BRANCH} "
4264 git reset --hard " origin/${DOCS_BRANCH} "
4365
44- git branch " MCK-snippets-update- ${OUTPUTS_VERSION_ID }" || true
45- git checkout " MCK-snippets-update- ${OUTPUTS_VERSION_ID }"
66+ git branch " ${DOCS_PR_BRANCH }" || true
67+ git checkout " ${DOCS_PR_BRANCH }"
4668
4769 popd
4870}
@@ -52,16 +74,17 @@ function download_snippets_outputs() {
5274 evg_version_id=$2
5375 echo " Downloading snippets outputs from s3 to ${dir} "
5476 aws s3 sync ' s3://operator-e2e-artifacts/snippets_outputs/' " ${dir} /" --exclude ' *' --include " ${evg_version_id} *"
55- mkdir -p " ${dir} / ${evg_version_id} "
56- cd " ${dir} / ${evg_version_id} "
77+ mkdir -p " ${dir} "
78+ cd " ${dir} "
5779 for f in * .tgz; do
58- tar -xvf " ${f} "
80+ if [[ -f ${f} ]]; then
81+ tar -xvf " ${f} "
82+ fi
5983 done
6084
6185 outputs_dir=" scripts/code_snippets/tests/outputs"
6286 if [[ ! -d " ${outputs_dir} " ]]; then
6387 echo " No snippets were downloaded"
64- ls -al
6588 return 1
6689 fi
6790}
@@ -73,7 +96,7 @@ function prepare_docs_pr() {
7396 return 1
7497 fi
7598
76- git add " ${DOCS_INCLUDE_CODE_EXAMPLES_DIR } "
99+ git add " ${docs_include_code_examples_dir } "
77100 git commit -m " Update sample files from MCK"
78101 git push
79102 popd
@@ -83,23 +106,24 @@ pushd ../
83106prepare_repositories
84107
85108tmp_dir=$( mktemp -d)
86- download_snippets_outputs " ${tmp_dir} " " ${OUTPUTS_VERSION_ID} "
87- outputs_dir=" ${tmp_dir} / ${OUTPUTS_VERSION_ID } /scripts/code_snippets/tests/outputs"
109+ if download_snippets_outputs " ${tmp_dir} " " ${OUTPUTS_VERSION_ID} " ; then
110+ outputs_dir=" ${tmp_dir} /scripts/code_snippets/tests/outputs"
88111
89- for test_dir in " ${outputs_dir} " /test_* ; do
90- echo " Replacing outputs for test: ${test_dir} "
91- rm -rf " ${DOCS_INCLUDE_CODE_EXAMPLES_DIR } /outputs/$( basename " ${test_dir} " ) "
92- cp -r " ${test_dir} " " ${DOCS_INCLUDE_CODE_EXAMPLES_DIR } /outputs/$( basename " ${test_dir} " ) "
93- done
112+ for test_dir in " ${outputs_dir} " /test_* ; do
113+ echo " Replacing outputs for test: ${test_dir} "
114+ rm -rf " ${docs_include_code_examples_dir } /outputs/$( basename " ${test_dir} " ) "
115+ cp -r " ${test_dir} " " ${docs_include_code_examples_dir } /outputs/$( basename " ${test_dir} " ) "
116+ done
94117
95- echo " ${outputs_dir} "
96- tree " ${outputs_dir} "
118+ echo " ${outputs_dir} "
119+ tree " ${outputs_dir} "
120+ fi
97121
98- rm -rf " ${DOCS_INCLUDE_CODE_EXAMPLES_DIR } /reference-architectures"
99- cp -r " ${MCK_DIR} /public/architectures" " ${DOCS_INCLUDE_CODE_EXAMPLES_DIR } /reference-architectures"
122+ rm -rf " ${docs_include_code_examples_dir } /reference-architectures"
123+ cp -r " ${MCK_DIR} /public/architectures" " ${docs_include_code_examples_dir } /reference-architectures"
100124
101- rm -rf " ${DOCS_INCLUDE_CODE_EXAMPLES_DIR } /search"
102- cp -r " ${MCK_DIR} /docs/search" " ${DOCS_INCLUDE_CODE_EXAMPLES_DIR } /search"
125+ rm -rf " ${docs_include_code_examples_dir } /search"
126+ cp -r " ${MCK_DIR} /docs/search" " ${docs_include_code_examples_dir } /search"
103127
104128prepare_docs_pr
105129popd
0 commit comments