Files
nova-specs/tools/fast-specs.sh
melanie witt 3c64c66238 Make 'tox -e fast-specs' fail on sphinx warnings
I'm not sure if others will want this but when I made an edit on my
spec and ran 'tox -e fast-specs', my expectation was that it was a fast
way to check whether the edits I made would pass openstack-tox-docs in
the gate. This turned out not to be the case, 'tox -e fast-specs'
showed the "fast-specs: commands succeeded" message but when I uploaded
the change, the openstack-tox-docs job failed because there was a
sphinx parsing error in my spec.

This adds -W to the sphinx-build call to treat warnings as errors to
match 'tox -e docs' and openstack-tox-docs. It also runs sphinx-build
via exec to make the script fail if sphinx-build returns non-zero.

Change-Id: I9de750e7f44a746d4466c522004d0c2a624052e2
2022-03-31 04:45:53 +00:00

67 lines
2.2 KiB
Bash

#!/bin/bash
#
# Build only spec files changed since the last git commit.
#
# Takes no arguments.
#
# Outputs the full path of built files, for paste-into-browser convenience.
#
# How it works:
# - Determines files changed since last commit
# - Filters to only specs (specs/*/*/*.rst)
# - Maps those by release subdir (second part of the path)
# - Builds all the changed specs in each release subdir
#
# Why it's fast:
# Not, as you may think, because we're only building the specific spec files.
# It is actually because we're restricting sphinx-build to only looking at the
# specific subdirectory/ies of those changed files. Even if only building a
# subset of files, sphinx-build normally parses all of them anyway (probably
# for index-building purposes). Since you're normally building (one spec in)
# the latest release's directory, this saves sphinx-build parsing the 600-ish
# specs from previous releases.
# Temp file storing the full path to built specs
tmpf=/tmp/specs.$$
function cleanup {
rm -f $tmpf
}
trap cleanup EXIT
# Map, keyed by release dir name, of spec files thereunder
declare -A specs_by_release
# Look for specs changed since last commit
for f in $(git diff --name-only HEAD~1 | grep -E 'specs/[^/]+/[^/]+/[^/]+\.rst'); do
# echo $f | cut -d/ -f2, but faster
release=${f#*/}
release=${release%%/*}
# doc/source/... has symlinks, and is where sphinx-build expects sources
specs_by_release[$release]=${specs_by_release[$release]}" doc/source/$f"
done
if [[ ${#specs_by_release[@]} -eq 0 ]]; then
echo "No spec files changed, nothing to build."
exit 0
fi
# Build all changed specs per release directory
for release in "${!specs_by_release[@]}"; do
src=doc/source/specs/$release
bld=doc/build/html/specs/$release
files=${specs_by_release[$release]}
echo "fast-specs: Building for ${release}:$files"
exec sphinx-build -W -c doc/source $src $bld $files
# Save the full path to built files. (Wait until the end to output these, so
# they're not lost between subdirectories.)
for f in $files; do
p=$(echo $f | sed 's,/source/,/build/html/,; s/rst$/html/')
realpath $p >> $tmpf
done
done
echo "================"
echo "fast-specs built:"
cat $tmpf
exit 0