Skip to content

Commit

Permalink
Run markdown-autodocs as part of check-style.sh. (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
stuhood authored Apr 2, 2024
1 parent d730c12 commit 79ffb6a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
4 changes: 3 additions & 1 deletion check-code-style/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,18 @@ runs:
chmod +x ./buildifier-linux-amd64
sudo mv ./buildifier-linux-amd64 /usr/local/bin/buildifier
# Install prettier.
# Install prettier and markdown-autodocs.
NODE_VERSION=16
NPM_VERSION=8.19.2
PRETTIER_VERSION=2.7.1
MARKDOWN_AUTODOCS_VERSION=1.0.133
curl -fsSL https://deb.nodesource.com/setup_${NODE_VERSION}.x | sudo bash -
sudo apt-get update
sudo apt-get install -y nodejs
sudo rm -rf /var/lib/apt/lists/*
sudo npm install -g npm@${NPM_VERSION}
sudo npm install -g prettier@${PRETTIER_VERSION}
sudo npm install -g markdown-autodocs@${MARKDOWN_AUTODOCS_VERSION}
shell: bash

Expand Down
25 changes: 22 additions & 3 deletions check-style.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
# * buildifier;
# * yapf;
# * isort;
# * prettier.
# * prettier;
# * markdown-autodocs.
#
# The script has two modes in which it can operate:
# * pre-commit - checks only the file in the current commit.
Expand Down Expand Up @@ -74,6 +75,13 @@ get_files_by_extension() {
echo $affected_files | tr ' ' '\n' | egrep $filter
}

# Helper function to get a checksum of a file list.
# Calculates a per-file checksum, sorts by filename, and then returns a sum over
# the sums.
calculate_checksum() {
sha256sum $@ | sort -k 2 | sha256sum
}

# Check files that we can clang-format.
clang_format_files=$(get_files_by_extension .cc .cpp .h .hpp .proto)
if [ ! -z "${clang_format_files}" ]; then
Expand Down Expand Up @@ -127,11 +135,22 @@ if [ ! -z "${python_files}" ]; then
run_check isort --check --diff ${python_files}
fi

# Check files that we can check with prettier.
# Turns out it is all of them.
# Check "any" file.
if [ ! -z "${affected_files}" ]; then
# Run prettier.
run_check prettier --ignore-unknown --check --loglevel=warn ${affected_files}

# Check documentation snippets (which can be affected by changes in any other file).
markdown_files=$(find . -type f -iname '*.md')
pre_autodocs_checksum=$(calculate_checksum $markdown_files)
run_check markdown-autodocs -c code-block -o ${markdown_files} > /dev/null
post_autodocs_checksum=$(calculate_checksum $markdown_files)
if [ "$pre_autodocs_checksum" != "$post_autodocs_checksum" ]; then
echo "There are code changes after running 'markdown-autodocs'."
echo "Please review the new changes, determine if they should be part of this commit, and if so, add them to the commit before continuing."

status_code=1
fi
fi

# Return the cummulative status code. The status code will be zero if all checks
Expand Down

0 comments on commit 79ffb6a

Please sign in to comment.