1
0

check-newsfragment.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env bash
  2. #
  3. # A script which checks that an appropriate news file has been added on this
  4. # branch.
  5. echo -e "+++ \033[32mChecking newsfragment\033[m"
  6. set -e
  7. # make sure that origin/develop is up to date
  8. git remote set-branches --add origin develop
  9. git fetch -q origin develop
  10. pr="$PULL_REQUEST_NUMBER"
  11. # if there are changes in the debian directory, check that the debian changelog
  12. # has been updated
  13. if ! git diff --quiet FETCH_HEAD... -- debian; then
  14. if git diff --quiet FETCH_HEAD... -- debian/changelog; then
  15. echo "Updates to debian directory, but no update to the changelog." >&2
  16. echo "!! Please see the contributing guide for help writing your changelog entry:" >&2
  17. echo "https://matrix-org.github.io/synapse/latest/development/contributing_guide.html#debian-changelog" >&2
  18. exit 1
  19. fi
  20. fi
  21. # if there are changes *outside* the debian directory, check that the
  22. # newsfragments have been updated.
  23. if ! git diff --name-only FETCH_HEAD... | grep -qv '^debian/'; then
  24. exit 0
  25. fi
  26. # Print a link to the contributing guide if the user makes a mistake
  27. CONTRIBUTING_GUIDE_TEXT="!! Please see the contributing guide for help writing your changelog entry:
  28. https://matrix-org.github.io/synapse/latest/development/contributing_guide.html#changelog"
  29. # If check-newsfragment returns a non-zero exit code, print the contributing guide and exit
  30. python -m towncrier.check --compare-with=origin/develop || (echo -e "$CONTRIBUTING_GUIDE_TEXT" >&2 && exit 1)
  31. echo
  32. echo "--------------------------"
  33. echo
  34. matched=0
  35. for f in $(git diff --diff-filter=d --name-only FETCH_HEAD... -- changelog.d); do
  36. # check that any added newsfiles on this branch end with a full stop.
  37. lastchar=$(tr -d '\n' < "$f" | tail -c 1)
  38. if [ "$lastchar" != '.' ] && [ "$lastchar" != '!' ]; then
  39. echo -e "\e[31mERROR: newsfragment $f does not end with a '.' or '!'\e[39m" >&2
  40. echo -e "$CONTRIBUTING_GUIDE_TEXT" >&2
  41. exit 1
  42. fi
  43. # see if this newsfile corresponds to the right PR
  44. [[ -n "$pr" && "$f" == changelog.d/"$pr".* ]] && matched=1
  45. done
  46. if [[ -n "$pr" && "$matched" -eq 0 ]]; then
  47. echo -e "\e[31mERROR: Did not find a news fragment with the right number: expected changelog.d/$pr.*.\e[39m" >&2
  48. echo -e "$CONTRIBUTING_GUIDE_TEXT" >&2
  49. exit 1
  50. fi