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

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