-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit
More file actions
executable file
·38 lines (35 loc) · 1.69 KB
/
Copy pathpre-commit
File metadata and controls
executable file
·38 lines (35 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
#
# A precommit hook that checks for breaking changes to our docs. It will:
# * run markdown-autodocs to make sure there are no changes in linked code
# snippets that haven't been ported over to the docs. If there are new
# changes after running markdown-autodocs, abort the commit and ask the
# user to manually review the changes.
# * run an npm build on the documentation to make sure it compiles correctly
# (no broken links, etc.)
REPO_TOP_LEVEL="$(git rev-parse --show-toplevel)"
source ${REPO_TOP_LEVEL}/public/submodules/dev-tools/pre-commit-print-error
# Run a build to check for breaking changes.
# This step can take a while, and changes outside of the documentation directory
# shouldn't affect this build, so let's check the commit and only run the build
# if there are relevant files touched.
documentation_files_in_commit=$(git diff --cached --name-only --diff-filter=ACM HEAD | grep reboot/documentation)
if [ ! -z "$documentation_files_in_commit" ]; then
# The install command is noisy; silence its output. If it
# fails, it'll send the error to STDERR, which will still appear in the
# console to assist in fixing the code.
echo "Installing documentation dependencies..."
npm install --prefix ${REPO_TOP_LEVEL}/reboot/documentation > /dev/null
if [ ! $? -eq 0 ]; then
print_error "Documentation dependency installation failed"
exit 1
fi
# Log noisy build command to STDOUT so we know which warnings to safely
# ignore.
echo "Running documentation build..."
npm run build --prefix ${REPO_TOP_LEVEL}/reboot/documentation
if [ ! $? -eq 0 ]; then
print_error "Documentation build failed"
exit 1
fi
fi