A Python parser for MediaWiki wikicode https://mwparserfromhell.readthedocs.io/
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #! /usr/bin/env bash
  2. if [[ -z "$1" ]]; then
  3. echo "usage: $0 1.2.3"
  4. exit 1
  5. fi
  6. VERSION=$1
  7. SCRIPT_DIR=$(dirname "$0")
  8. RELEASE_DATE=$(date +"%B %d, %Y")
  9. check_git() {
  10. if [[ -n "$(git status --porcelain --untracked-files=no)" ]]; then
  11. echo "Aborting: dirty working directory."
  12. exit 1
  13. fi
  14. if [[ "$(git rev-parse --abbrev-ref HEAD)" != "develop" ]]; then
  15. echo "Aborting: not on develop."
  16. exit 1
  17. fi
  18. echo -n "Are you absolutely ready to release? [yN] "
  19. read confirm
  20. if [[ ${confirm,,} != "y" ]]; then
  21. exit 1
  22. fi
  23. }
  24. update_version() {
  25. echo -n "Updating mwparserfromhell.__version__..."
  26. sed -e 's/__version__ = .*/__version__ = "'$VERSION'"/' -i "" mwparserfromhell/__init__.py
  27. echo " done."
  28. }
  29. update_changelog() {
  30. filename="CHANGELOG"
  31. echo -n "Updating $filename..."
  32. sed -e '1s/.*/v'$VERSION' (released '$RELEASE_DATE'):/' -i "" $filename
  33. echo " done."
  34. }
  35. update_docs_changelog() {
  36. filename="docs/changelog.rst"
  37. echo -n "Updating $filename..."
  38. dashes=$(seq 1 $(expr ${#VERSION} + 1) | sed 's/.*/-/' | tr -d '\n')
  39. previous_lineno=$(expr $(grep -n -e "^---" $filename | sed '2q;d' | cut -d ':' -f 1) - 1)
  40. previous_version=$(sed $previous_lineno'q;d' $filename)
  41. sed \
  42. -e '4s/.*/v'$VERSION \
  43. -e '5s/.*/'$dashes \
  44. -e '7s/.*/`Released '$RELEASE_DATE' <https:\/\/github.com\/earwig\/mwparserfromhell\/tree\/v'$VERSION'>`_/' \
  45. -e '8s/.*/(`changes <https:\/\/github.com\/earwig\/mwparserfromhell\/compare\/v'$previous_version'...v'$VERSION'>`__):/' \
  46. -i "" $filename
  47. echo " done."
  48. }
  49. do_git_stuff() {
  50. echo -n "Git: committing, tagging, and merging release..."
  51. git commit -qam "release/$VERSION"
  52. git tag v$VERSION -s -m "version $VERSION"
  53. git checkout -q master
  54. git merge -q --no-ff develop -m "Merge branch 'develop'"
  55. echo -n " pushing..."
  56. git push -q --tags origin master
  57. git checkout -q develop
  58. git push -q origin develop
  59. echo " done."
  60. }
  61. build_sdist() {
  62. echo -n "Uploading to PyPI..."
  63. python setup.py register sdist upload -s
  64. python setup.py upload_docs
  65. echo " done."
  66. }
  67. post_release() {
  68. echo
  69. echo "*** Release completed."
  70. echo "*** Update: https://github.com/earwig/mwparserfromhell/releases/tag/v$VERSION"
  71. echo "*** Verify: https://pypi.python.org/pypi/mwparserfromhell"
  72. echo "*** Verify: https://mwparserfromhell.readthedocs.org"
  73. echo "*** Press enter to sanity-check the release."
  74. read
  75. }
  76. test_release() {
  77. echo
  78. echo "Checking mwparserfromhell v$VERSION..."
  79. echo -n "Creating a virtualenv..."
  80. virtdir="mwparser-test-env"
  81. virtualenv -q $virtdir
  82. cd $virtdir
  83. source bin/activate
  84. echo " done."
  85. echo -n "Installing mwparserfromhell with pip..."
  86. pip -q install mwparserfromhell
  87. echo " done."
  88. echo -n "Checking version..."
  89. reported_version=$(python -c 'print __import__("mwparserfromhell").__version__')
  90. if [[ "$reported_version" != "$VERSION" ]]; then
  91. echo " error."
  92. echo "*** ERROR: mwparserfromhell is reporting its version as $reported_version, not $VERSION!"
  93. deactivate
  94. cd ..
  95. rm -rf $virtdir
  96. exit 1
  97. else
  98. echo " done."
  99. fi
  100. pip -q uninstall -y mwparserfromhell
  101. echo -n "Downloading mwparserfromhell source tarball and GPG signature..."
  102. curl -sL "https://pypi.python.org/packages/source/m/mwparserfromhell/mwparserfromhell-$VERSION.tar.gz" -o "mwparserfromhell.tar.gz"
  103. curl -sL "https://pypi.python.org/packages/source/m/mwparserfromhell/mwparserfromhell-$VERSION.tar.gz.asc" -o "mwparserfromhell.tar.gz.asc"
  104. echo " done."
  105. echo "Verifying tarball..."
  106. gpg --verify mwparserfromhell.tar.gz.asc
  107. if [[ "$?" != "0" ]]; then
  108. echo "*** ERROR: GPG signature verification failed!"
  109. deactivate
  110. cd ..
  111. rm -rf $virtdir
  112. exit 1
  113. fi
  114. tar -xf mwparserfromhell.tar.gz
  115. rm mwparserfromhell.tar.gz mwparserfromhell.tar.gz.asc
  116. cd mwparserfromhell-$VERSION
  117. echo "Running unit tests..."
  118. python setup.py -q test
  119. if [[ "$?" != "0" ]]; then
  120. echo "*** ERROR: Unit tests failed!"
  121. deactivate
  122. cd ../..
  123. rm -rf $virtdir
  124. exit 1
  125. fi
  126. echo -n "Everything looks good. Cleaning up..."
  127. deactivate
  128. cd ../..
  129. rm -rf $virtdir
  130. echo " done."
  131. }
  132. echo "Preparing mwparserfromhell v$VERSION..."
  133. cd "$SCRIPT_DIR/.."
  134. check_git
  135. update_version
  136. update_changelog
  137. update_docs_changelog
  138. do_git_stuff
  139. post_release
  140. test_release
  141. echo "All done."
  142. exit 0