Skip to content

Commit

Permalink
Add CI test to ensure that README.md files are present and correct
Browse files Browse the repository at this point in the history
Checking readmes takes up non-trivial maintainer time, and is
prone to error. This script adds a check to the CI which ensures
that PRs are only accepted if their README.md files are
present and correct.

It begins by isolating the exercises already impacted by the PR,
so that upstream changes to unrelated exercises don't cause undue
difficulty. It then simply ensures that the README.md within
the PR is identical to the one generated by `configlet generate`.

Outputs lists of exercises with missing or incorrect READMEs,
so people for whom CI fails due to this test not passing should
have an easy time understanding what went wrong and how to fix it.
  • Loading branch information
coriolinus committed Nov 5, 2017
1 parent 5bae530 commit 99242c6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ script:
- "sh ./_test/ensure-stubs-compile.sh"
- "sh ./_test/count-ignores.sh"
- "./bin/fetch-configlet"
- "sh ./_test/ensure-readmes-are-updated.sh"
- "./bin/configlet lint ."
sudo: false
rust:
Expand Down
36 changes: 36 additions & 0 deletions _test/ensure-readmes-are-updated.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
if [ ! -x bin/configlet ]; then
echo "Improper configuration; configlet should exist in bin/ when this script is run"
echo "Ping a Rust track maintainer to fix this"
exit 1
fi

newline=$'\n '

missing_readmes=""
wrong_readmes=""
for exercise in $(git diff --name-only master..$(git rev-parse --abbrev-ref HEAD) | grep exercises/ | cut -d'/' -f2 -s | sort -fu); do
echo "Checking readme for $exercise"
readme_path="exercises/${exercise}/README.md"
if [ ! -f $readme_path ]; then
missing_readmes="$missing_readmes$newline$exercise"
else
existing_readme_checksum=$(md5sum $readme_path | cut -d' ' -f1)
# generate the new README
bin/configlet generate . --only "$exercise"
generated_readme_checksum=$(md5sum $readme_path | cut -d' ' -f1)

if [ $existing_readme_checksum != $generated_readme_checksum ]; then
wrong_readmes="$wrong_readmes$newline$exercise"
fi
fi
done

if [ -n "$missing_readmes" ]; then
echo "Exercises missing README.md:$missing_readmes"
fi
if [ -n "$wrong_readmes" ]; then
echo "Exercises with out-of-date README.md:$wrong_readmes"
fi
if [ -n "$missing_readmes" -o -n "$wrong_readmes" ]; then
exit 1
fi

0 comments on commit 99242c6

Please sign in to comment.