changelog-well-formed 615 B

12345678910111213141516171819202122232425
  1. #!/usr/bin/env bash
  2. changelogFile=${1:-CHANGELOG.md}
  3. if [ ! -r "$changelogFile" ]; then
  4. echo "Unable to read file $changelogFile" >&2
  5. exit 1
  6. fi
  7. changelogWellFormed=1
  8. # e.g. "## 1.12.3 (2016-10-26)"
  9. VER_LINE_REGEX='^## [0-9]+\.[0-9]+\.[0-9]+(-ce)? \([0-9]+-[0-9]+-[0-9]+\)$'
  10. while read -r line; do
  11. if ! [[ "$line" =~ $VER_LINE_REGEX ]]; then
  12. echo "Malformed changelog $changelogFile line \"$line\"" >&2
  13. changelogWellFormed=0
  14. fi
  15. done < <(grep '^## ' $changelogFile)
  16. if [[ "$changelogWellFormed" == "1" ]]; then
  17. echo "Congratulations! Changelog $changelogFile is well-formed."
  18. else
  19. exit 2
  20. fi