Skip to content

Instantly share code, notes, and snippets.

@PMarci
Last active February 3, 2022 13:57
Show Gist options
  • Save PMarci/59500c1512fcd67c940f326620242e62 to your computer and use it in GitHub Desktop.
Save PMarci/59500c1512fcd67c940f326620242e62 to your computer and use it in GitHub Desktop.
Moves the contents of relative path $dir to $old_dir, under a folder for the current project version, excluding $old_dir, as it's a subfolder of $dir
#!/bin/bash
old_dir="old"
dir="public"
echo "Determining version..."
if [ "$(command -v xmllint)" ]; then
echo "using XMLlint."
version="$(xmllint --xpath '/*[local-name()="project"]/*[local-name()="version"]/text()' pom.xml)"
else
echo "using Maven."
version="$(mvn -q \
-Dexec.executable=echo \
-Dexec.args='${project.version}' \
--non-recursive \
exec:exec)"
fi
if [ -n "$version" ] && [ -f "./${dir}/index.html" ]; then
new_dir="${dir}/${old_dir}/${version}"
echo "Copying documentation version $version to $new_dir..."
if [ -f "./${new_dir}/index.html" ]; then
echo "Overwriting existing files in $new_dir..."
fi
mkdir -p "./$new_dir"
echo '{ "version" : "'"$version"'" }' >> "./$new_dir/version.json"
folders="$(find ./$dir -mindepth 1 -type d \( -path "**/$old_dir/**" -o -path "**/$old_dir" \) -prune -o -printf "%P\n")"
for folder in $folders; do
# echo "Copying $folder to ./${new_dir}/${folder}..."
cp -r -f "./${dir}/${folder}" "./${new_dir}/${folder}"
done
echo "Copying of documentation version $version done."
elif [ -n "$version" ]; then
echo "No documentation under $dir found, skipping copy."
else
echo "Version could not be determined from pom.xml."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment