1- #! /usr/bin/env sh
1+ #! /usr/bin/env bash
22
33set -o errexit
44set -o nounset
5+ set -o pipefail
56
67# shellcheck disable=SC2034
78ERR_ARGUMENT_EVAL=2
@@ -18,6 +19,12 @@ GITHUB_TOKEN_PATH="$(pwd)/.github-personal-access-token"
1819# shellcheck disable=SC2034
1920HOME_LAB_DOCS_CONFIGURATION_FILE_PATH=" config/mkdocs/home-lab-docs/mkdocs.yml"
2021
22+ # shellcheck disable=SC2034
23+ MKDOCS_IGNORE_IF_ONLY_CHANGED_FILES=(
24+ " docs/sitemap.xml"
25+ " docs/sitemap.xml.gz"
26+ )
27+
2128_DOCKER_INTERACTIVE_TTY_OPTION=
2229if [ -t 0 ]; then
2330 _DOCKER_INTERACTIVE_TTY_OPTION=" -it"
@@ -40,7 +47,7 @@ is_container_runtime_available() {
4047}
4148
4249activate_python_virtual_environment () {
43- VENV_PATH=" ${1} "
50+ local VENV_PATH=" ${1} "
4451
4552 if [ -z " ${VIRTUAL_ENV-} " ]; then
4653 echo " Activating the virtual environment in ${VENV_PATH} "
@@ -54,7 +61,7 @@ activate_python_virtual_environment() {
5461}
5562
5663is_python_virtual_environment_up_to_date () {
57- PYTHON_VIRTUAL_ENVIRONMENT_CHECK_RETURN_CODE=0
64+ local PYTHON_VIRTUAL_ENVIRONMENT_CHECK_RETURN_CODE=0
5865 if [ ! -e " ${1} " ]; then
5966 # The virtual environment doesn't exist, so it can't be up to date by definition
6067 PYTHON_VIRTUAL_ENVIRONMENT_CHECK_RETURN_CODE=1
@@ -74,9 +81,9 @@ is_python_virtual_environment_up_to_date() {
7481}
7582
7683create_and_activate_python_virtual_environment () {
77- PYTHON_VIRTUAL_ENVIRONMENT_PATH=" ${1} "
78- PIP_REQUIREMENTS_PATH=" ${2:- " " } "
79- _FORCE_UPDATE_PYTHON_VIRTUAL_ENVIRONMENT=" ${3:- " false" } "
84+ local PYTHON_VIRTUAL_ENVIRONMENT_PATH=" ${1} "
85+ local PIP_REQUIREMENTS_PATH=" ${2:- " " } "
86+ local _FORCE_UPDATE_PYTHON_VIRTUAL_ENVIRONMENT=" ${3:- " false" } "
8087
8188 if [ -e " ${PYTHON_VIRTUAL_ENVIRONMENT_PATH} " ] && ! is_python_virtual_environment_up_to_date " ${PYTHON_VIRTUAL_ENVIRONMENT_PATH} " && [ " ${_FORCE_UPDATE_PYTHON_VIRTUAL_ENVIRONMENT} " = " true" ]; then
8289 echo " The ${PYTHON_VIRTUAL_ENVIRONMENT_PATH} virtual environment already exists but it's not up to date. Deleting it..."
@@ -123,3 +130,34 @@ check_github_token_file() {
123130 exit " ${ERR_MISSING_GITHUB_TOKEN_FILE} "
124131 fi
125132}
133+
134+ check_if_uncommitted_files_only_include_files () {
135+ local -a FILES_TO_CHECK=(" $@ " )
136+ local -a CHANGED_FILES
137+
138+ git status
139+
140+ readarray -d ' ' -t CHANGED_FILES < <( git diff-files -z --name-only)
141+ readarray -d ' ' -t SORTED_CHANGED_FILES < <( printf ' %s\0' " ${CHANGED_FILES[@]} " | sort -z)
142+
143+ echo " Changed files (${# SORTED_CHANGED_FILES[@]} ) in working directory:"
144+ echo " ${SORTED_CHANGED_FILES[*]} "
145+
146+ readarray -d ' ' -t SORTED_FILES_TO_CHECK < <( printf ' %s\0' " ${FILES_TO_CHECK[@]} " | sort -z)
147+
148+ if [[ " ${SORTED_CHANGED_FILES[*]} " == " ${SORTED_FILES_TO_CHECK[*]} " ]]; then
149+ echo " Working directory contains only the files to check"
150+ return 0
151+ else
152+ echo " Working directory doesn't contain only the files to check"
153+ return 1
154+ fi
155+ }
156+
157+ check_if_uncommitted_files_only_include_files_to_ignore () {
158+ if check_if_uncommitted_files_only_include_files " ${MKDOCS_IGNORE_IF_ONLY_CHANGED_FILES[@]} " ; then
159+ return 0
160+ else
161+ return 1
162+ fi
163+ }
0 commit comments