From 7162c64d050ae8d2266b7fb170f72ebb4ef814b1 Mon Sep 17 00:00:00 2001 From: Mateusz Jakub Fila Date: Tue, 17 Dec 2024 17:21:46 +0100 Subject: [PATCH 1/5] add `--force` option to fetch script --- .github/scripts/fetch_external_sources.sh | 29 +++++++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/.github/scripts/fetch_external_sources.sh b/.github/scripts/fetch_external_sources.sh index 0e41600..50340b5 100755 --- a/.github/scripts/fetch_external_sources.sh +++ b/.github/scripts/fetch_external_sources.sh @@ -1,9 +1,28 @@ #!/usr/bin/env bash # Script that tries to automatically fetch further documentation from other # github repositories, where it simply assumes that they are available under the -# same name. Runs through our ususal suspects of github organizations while +# same name. Runs through our usual suspects of github organizations while # trying to do so +# Initialize force option +FORCE=false + +# Parse command line arguments +for arg in "$@"; do + case $arg in + --force|-f) FORCE=true ;; + --help|-h) + echo "Usage: $0 [--force|-f] [--help|-h]" + echo "" + echo "Options:" + echo " --force, -f Force fetching files even if they already exist" + echo " --help, -h Display this help message" + exit 0 + ;; + *) echo "Unknown parameter passed: $arg"; exit 1 ;; + esac +done + # Try to fetch a file from a github repository try_fetch() { local org=${1} @@ -30,8 +49,8 @@ fetch_for_file() { if [ -n "${line}" ] && [[ "${line}" == *.md ]] || [[ "${line}" == *.png ]]; then # If the file exists do nothing, otherwise pull it in from github local file_to_fetch=${file_dir}/${line} - if ! ls "${file_to_fetch}" > /dev/null 2>&1; then - echo "${line} does not exist. Trying to fetch it from github" + if [ "${FORCE}" = true ] || ! ls "${file_to_fetch}" > /dev/null 2>&1; then + echo "${line} does not exist or force option is enabled. Trying to fetch it from github" local outputdir=$(dirname ${file_to_fetch}) mkdir -p ${outputdir} # make the directory for the output @@ -39,13 +58,13 @@ fetch_for_file() { for org in key4hep HEP-FCC AIDASoft iLCSoft; do echo "Trying to fetch from github organization: '${org}'" if try_fetch ${org} ${line} ${file_dir}; then - echo "Fetched succesfully from organization '${org}'" + echo "Fetched successfully from organization '${org}'" break fi done fi - # Check again if we hav succesfully fetched the file + # Check again if we have successfully fetched the file if ! ls "${file_to_fetch}" > /dev/null 2>&1; then echo "Could not fetch file '${line}' from external sources" 1>&2 exit 1 From 60214b3afe7ac19d6d95ef3ac5edb517d83ea08a Mon Sep 17 00:00:00 2001 From: Mateusz Jakub Fila Date: Wed, 18 Dec 2024 08:54:44 +0100 Subject: [PATCH 2/5] split missing file and forceful fetch scenarios --- .github/scripts/fetch_external_sources.sh | 31 +++++++++++++---------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/.github/scripts/fetch_external_sources.sh b/.github/scripts/fetch_external_sources.sh index 50340b5..cb09244 100755 --- a/.github/scripts/fetch_external_sources.sh +++ b/.github/scripts/fetch_external_sources.sh @@ -49,21 +49,26 @@ fetch_for_file() { if [ -n "${line}" ] && [[ "${line}" == *.md ]] || [[ "${line}" == *.png ]]; then # If the file exists do nothing, otherwise pull it in from github local file_to_fetch=${file_dir}/${line} - if [ "${FORCE}" = true ] || ! ls "${file_to_fetch}" > /dev/null 2>&1; then - echo "${line} does not exist or force option is enabled. Trying to fetch it from github" - local outputdir=$(dirname ${file_to_fetch}) - mkdir -p ${outputdir} # make the directory for the output - - # Try a few github organizations - for org in key4hep HEP-FCC AIDASoft iLCSoft; do - echo "Trying to fetch from github organization: '${org}'" - if try_fetch ${org} ${line} ${file_dir}; then - echo "Fetched successfully from organization '${org}'" - break - fi - done + if [ "${FORCE}" = true ]; then + echo "Force option enabled. Trying to fetch '${line}' from github" + elif ! ls "${file_to_fetch}" > /dev/null 2>&1; then + echo "${line} does not exist. Trying to fetch it from github" + else + continue fi + local outputdir=$(dirname ${file_to_fetch}) + mkdir -p ${outputdir} # make the directory for the output + + # Try a few github organizations + for org in key4hep HEP-FCC AIDASoft iLCSoft; do + echo "Trying to fetch from github organization: '${org}'" + if try_fetch ${org} ${line} ${file_dir}; then + echo "Fetched successfully from organization '${org}'" + break + fi + done + # Check again if we have successfully fetched the file if ! ls "${file_to_fetch}" > /dev/null 2>&1; then echo "Could not fetch file '${line}' from external sources" 1>&2 From 44baa3ba0b44450a0d20e324065f06fe1e34da9e Mon Sep 17 00:00:00 2001 From: Mateusz Jakub Fila Date: Wed, 18 Dec 2024 08:54:51 +0100 Subject: [PATCH 3/5] update readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 7ff25cf..caee2d6 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ First fetch the documentation pages from other key4hep repositories: .github/scripts/fetch_external_sources.sh ``` +If the sources already exist but you want to update them, use the `--force` option. + Then build the site locally: ```sh From 52a073bec02b173bacf80b7c294cb43e6275db62 Mon Sep 17 00:00:00 2001 From: Mateusz Jakub Fila Date: Wed, 18 Dec 2024 15:09:51 +0100 Subject: [PATCH 4/5] print usage on argparse error --- .github/scripts/fetch_external_sources.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/scripts/fetch_external_sources.sh b/.github/scripts/fetch_external_sources.sh index cb09244..5081c1b 100755 --- a/.github/scripts/fetch_external_sources.sh +++ b/.github/scripts/fetch_external_sources.sh @@ -7,19 +7,28 @@ # Initialize force option FORCE=false +# Display usage message +display_usage() { + echo "Usage: $0 [--force|-f] [--help|-h]" +} + # Parse command line arguments for arg in "$@"; do case $arg in --force|-f) FORCE=true ;; --help|-h) - echo "Usage: $0 [--force|-f] [--help|-h]" + display_usage echo "" echo "Options:" echo " --force, -f Force fetching files even if they already exist" echo " --help, -h Display this help message" exit 0 ;; - *) echo "Unknown parameter passed: $arg"; exit 1 ;; + *) + echo "Unknown parameter passed: $arg" + display_usage + exit 1 + ;; esac done From 73500b30761f6e620f40ce0d4c16583cd839b948 Mon Sep 17 00:00:00 2001 From: Mateusz Jakub Fila Date: Wed, 18 Dec 2024 15:10:42 +0100 Subject: [PATCH 5/5] print script basename instead of full path in usage --- .github/scripts/fetch_external_sources.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/fetch_external_sources.sh b/.github/scripts/fetch_external_sources.sh index 5081c1b..b77cd5f 100755 --- a/.github/scripts/fetch_external_sources.sh +++ b/.github/scripts/fetch_external_sources.sh @@ -9,7 +9,7 @@ FORCE=false # Display usage message display_usage() { - echo "Usage: $0 [--force|-f] [--help|-h]" + echo "Usage: $(basename $0) [--force|-f] [--help|-h]" } # Parse command line arguments