@@ -20,105 +20,226 @@ set -e
2020
2121REMOTE=" iceberg_docs"
2222
23+
24+
25+ # Function: create_or_update_docs_remote
26+ # Purpose: Ensures the presence of a specified remote repository for documentation.
27+ # If the remote doesn't exist, it adds it using the provided URL.
28+ # Then, it fetches updates from the remote repository.
2329create_or_update_docs_remote () {
24- # check if remote exists before adding it
30+ echo " --> create or update docs remote"
31+
32+ # Check if the remote exists before attempting to add it
2533 git config " remote.${REMOTE} .url" > /dev/null ||
2634 git remote add " ${REMOTE} " https://github.com/apache/iceberg.git
2735
36+ # Fetch updates from the remote repository
2837 git fetch " ${REMOTE} "
2938}
3039
40+
41+ # Function: pull_remote
42+ # Purpose: Pulls updates from a specified branch of a remote repository.
43+ # Arguments:
44+ # $1: Branch name to pull updates from
3145pull_remote () {
46+ echo " --> pull remote"
47+
3248 local BRANCH=" $1 "
33- assert_not_empty " ${BRANCH} "
3449
35- git pull " ${REMOTE} " " ${BRANCH} "
50+ # Ensure the branch argument is not empty
51+ assert_not_empty " ${BRANCH} "
52+
53+ # Perform a pull from the specified branch of the remote repository
54+ git pull " ${REMOTE} " " ${BRANCH} "
3655}
3756
57+ # Function: push_remote
58+ # Purpose: Pushes changes from a local branch to a specified branch of a remote repository.
59+ # Arguments:
60+ # $1: Branch name to push changes to
3861push_remote () {
62+ echo " --> push remote"
63+
3964 local BRANCH=" $1 "
40- assert_not_empty " ${BRANCH} "
4165
42- git push " ${REMOTE} " " ${BRANCH} "
66+ # Ensure the branch argument is not empty
67+ assert_not_empty " ${BRANCH} "
68+
69+ # Push changes to the specified branch of the remote repository
70+ git push " ${REMOTE} " " ${BRANCH} "
4371}
4472
73+ # Function: install_deps
74+ # Purpose: Installs or upgrades dependencies specified in the 'requirements.txt' file using pip.
4575install_deps () {
76+ echo " --> install deps"
77+
78+ # Use pip to install or upgrade dependencies from the 'requirements.txt' file quietly
4679 pip -q install -r requirements.txt --upgrade
4780}
4881
82+ # Function: assert_not_empty
83+ # Purpose: Checks if a provided argument is not empty. If empty, displays an error message and exits with a status code 1.
84+ # Arguments:
85+ # $1: Argument to check for emptiness
4986assert_not_empty () {
50- if [ -z " $1 " ]
51- then
52- echo " No argument supplied"
53- exit 1
54- fi
87+
88+ if [ -z " $1 " ]; then
89+ echo " No argument supplied"
90+
91+ # Exit with an error code if no argument is provided
92+ exit 1
93+ fi
5594}
5695
96+ # Function: get_latest_version
97+ # Purpose: Finds and retrieves the latest version of the documentation based on the directory structure.
98+ # Assumes the documentation versions are numeric folders within 'docs/docs/'.
5799get_latest_version () {
58- basename $( ls -d docs/docs/* / | sort -V | tail -1)
100+ # Find the latest numeric folder within 'docs/docs/' structure
101+ local latest=$( ls -d docs/docs/[0-9]* | sort -V | tail -1)
102+
103+ # Extract the version number from the latest directory path
104+ local latest_version=$( basename " ${latest} " )
105+
106+ # Output the latest version number
107+ echo " ${latest_version} "
59108}
60109
110+ # Function: create_nightly
111+ # Purpose: Creates a symbolic link for a 'nightly' version of the documentation.
61112create_nightly () {
113+ echo " --> create nightly"
114+
115+ # Remove any existing 'nightly' symbolic link to prevent conflicts
62116 rm -f docs/docs/nightly/
117+
118+ # Create a symbolic link pointing to the 'nightly' documentation
63119 ln -s ../nightly docs/docs/nightly
64120}
65121
122+ # Function: create_latest
123+ # Purpose: Creates a 'latest' version of the documentation based on a specified ICEBERG_VERSION.
124+ # Arguments:
125+ # $1: ICEBERG_VERSION - The version number of the documentation to be treated as the latest.
66126create_latest () {
127+ echo " --> create latest"
128+
67129 local ICEBERG_VERSION=" $1 "
68- assert_not_empty " ${ICEBERG_VERSION} "
69130
131+ # Ensure ICEBERG_VERSION is not empty
132+ assert_not_empty " ${ICEBERG_VERSION} "
133+
134+ # Output the provided ICEBERG_VERSION for verification
135+ echo " ${ICEBERG_VERSION} "
136+
137+ # Remove any existing 'latest' directory and recreate it
70138 rm -rf docs/docs/latest/
71139 mkdir docs/docs/latest/
72140
141+ # Create symbolic links and copy configuration files for the 'latest' documentation
73142 ln -s " ../${ICEBERG_VERSION} /docs" docs/docs/latest/docs
74143 cp " docs/docs/${ICEBERG_VERSION} /mkdocs.yml" docs/docs/latest/
75144
76145 cd docs/docs/
77- update_version " latest"
146+
147+ # Update version information within the 'latest' documentation
148+ update_version " latest"
78149 cd -
79150}
80151
152+ # Function: update_version
153+ # Purpose: Updates version information within the mkdocs.yml file for a specified ICEBERG_VERSION.
154+ # Arguments:
155+ # $1: ICEBERG_VERSION - The version number used for updating the mkdocs.yml file.
81156update_version () {
157+ echo " --> update version"
158+
82159 local ICEBERG_VERSION=" $1 "
83- assert_not_empty " ${ICEBERG_VERSION} "
84160
85- sed -i ' ' -E " s/(^site\_name:[[:space:]]+docs\/).*$/\1${ICEBERG_VERSION} /" ${ICEBERG_VERSION} /mkdocs.yml
86- sed -i ' ' -E " s/(^[[:space:]]*-[[:space:]]+Javadoc:.*\/javadoc\/).*$/\1${ICEBERG_VERSION} /" ${ICEBERG_VERSION} /mkdocs.yml
161+ # Ensure ICEBERG_VERSION is not empty
162+ assert_not_empty " ${ICEBERG_VERSION} "
163+
164+
165+
166+ # Update version information within the mkdocs.yml file using sed commands
167+ if [ " $( uname) " == " Darwin" ]
168+ then
169+ sed -i ' ' -E " s/(^site\_name:[[:space:]]+docs\/).*$/\1${ICEBERG_VERSION} /" ${ICEBERG_VERSION} /mkdocs.yml
170+ sed -i ' ' -E " s/(^[[:space:]]*-[[:space:]]+Javadoc:.*\/javadoc\/).*$/\1${ICEBERG_VERSION} /" ${ICEBERG_VERSION} /mkdocs.yml
171+ elif [ " $( expr substr $( uname -s) 1 5) " == " Linux" ]
172+ then
173+ sed -i' ' -E " s/(^site_name:[[:space:]]+docs\/)[^[:space:]]+/\1${ICEBERG_VERSION} /" " ${ICEBERG_VERSION} /mkdocs.yml"
174+ sed -i' ' -E " s/(^[[:space:]]*-[[:space:]]+Javadoc:.*\/javadoc\/).*$/\1${ICEBERG_VERSION} /" " ${ICEBERG_VERSION} /mkdocs.yml"
175+ fi
87176
88- # sed -i '' -E "s/ \- latest: '\!include docs\/docs\/latest\/mkdocs\.yml'/a \- ${ICEBERG_VERSION}: '\!include docs\/docs\/${ICEBERG_VERSION}\/mkdocs\.yml/" ../../mkdocs.yml
89177}
90- # https://squidfunk.github.io/mkdocs-material/setup/setting-up-site-search/#search-exclusion
178+
179+
180+
181+ # Function: search_exclude_versioned_docs
182+ # Purpose: Excludes versioned documentation from search indexing by modifying .md files.
183+ # Arguments:
184+ # $1: ICEBERG_VERSION - The version number of the documentation to exclude from search indexing.
91185search_exclude_versioned_docs () {
186+ echo " --> search exclude version docs"
92187 local ICEBERG_VERSION=" $1 "
93- assert_not_empty " ${ICEBERG_VERSION} "
188+
189+ # Ensure ICEBERG_VERSION is not empty
190+ assert_not_empty " ${ICEBERG_VERSION} "
94191
95192 cd " ${ICEBERG_VERSION} /docs/"
96-
193+
194+ # Modify .md files to exclude versioned documentation from search indexing
97195 python3 -c " import os
98196for f in filter(lambda x: x.endswith('.md'), os.listdir()): lines = open(f).readlines(); open(f, 'w').writelines(lines[:2] + ['search:\n', ' exclude: true\n'] + lines[2:]);"
99-
197+
100198 cd -
101199}
102200
201+ # Function: pull_versioned_docs
202+ # Purpose: Sets up local worktrees for the documentation and performs operations related to different versions.
103203pull_versioned_docs () {
104- create_or_update_docs_remote
204+ echo " --> pull version docs"
205+
206+ # Ensure the remote repository for documentation exists and is up-to-date
207+ create_or_update_docs_remote
208+
209+ # Add local worktrees for documentation and javadoc from the remote repository
105210 git worktree add docs/docs " ${REMOTE} /docs"
106211 git worktree add docs/javadoc " ${REMOTE} /javadoc"
107212
108- create_latest $( get_latest_version)
109- create_nightly
213+ # Retrieve the latest version of documentation for processing
214+ local latest_version=$( get_latest_version)
215+
216+ # Output the latest version for debugging purposes
217+ echo " Latest version is: ${latest_version} "
218+
219+ # Create the 'latest' version of documentation
220+ create_latest " ${latest_version} "
221+
222+ # Create the 'nightly' version of documentation
223+ create_nightly
110224}
111225
226+ # Function: clean
227+ # Purpose: Cleans up artifacts and temporary files generated during documentation management.
112228clean () {
113- set +e # avoid exit if any step in clean fails
229+ echo " --> clean"
114230
115- rm -rf docs/docs/latest & > /dev/null
116- rm -f docs/docs/nightly & > /dev/null
231+ # Temporarily disable script exit on errors to ensure cleanup continues
232+ set +e
117233
234+ # Remove 'latest' and 'nightly' directories and related Git worktrees
235+ rm -rf docs/docs/latest & > /dev/null
236+ rm -f docs/docs/nightly & > /dev/null
118237 git worktree remove docs/docs & > /dev/null
119238 git worktree remove docs/javadoc & > /dev/null
120239
240+ # Remove any additional temporary artifacts (e.g., 'site/' directory)
121241 rm -rf site/ & > /dev/null
122242
123- set -e
243+ set -e # Re-enable script exit on errors
124244}
245+
0 commit comments