A Python parser for MediaWiki wikicode https://mwparserfromhell.readthedocs.io/
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

161 lines
4.4 KiB

  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 "Ready to commit and push? [yN] "
  58. read confirm
  59. if [[ ${confirm,,} != "y" ]]; then
  60. exit 1
  61. fi
  62. echo -n "Git: committing, tagging, and merging release..."
  63. git commit -qam "release/$VERSION"
  64. git tag v$VERSION -s -m "version $VERSION"
  65. echo -n " pushing..."
  66. git push -q --tags origin main
  67. echo " done."
  68. }
  69. upload_to_pypi() {
  70. echo -n "PyPI: uploading source tarball..."
  71. python setup.py -q sdist
  72. twine upload dist/mwparserfromhell-$VERSION*
  73. echo " done."
  74. }
  75. post_release() {
  76. echo
  77. echo "*** Release completed."
  78. echo "*** Update: https://github.com/earwig/mwparserfromhell/releases/tag/v$VERSION"
  79. echo "*** Verify: https://pypi.org/project/mwparserfromhell"
  80. echo "*** Verify: https://ci.appveyor.com/project/earwig/mwparserfromhell"
  81. echo "*** Verify: https://mwparserfromhell.readthedocs.io"
  82. echo "*** Press enter to sanity-check the release."
  83. read
  84. }
  85. test_release() {
  86. echo
  87. echo "Checking mwparserfromhell v$VERSION..."
  88. echo -n "Creating a virtualenv..."
  89. virtdir="mwparser-test-env"
  90. python -m venv $virtdir
  91. cd $virtdir
  92. source bin/activate
  93. echo " done."
  94. echo -n "Installing mwparserfromhell with pip..."
  95. pip -q install --upgrade pip
  96. pip -q install mwparserfromhell pytest
  97. echo " done."
  98. echo -n "Checking version..."
  99. reported_version=$(python -c 'print(__import__("mwparserfromhell").__version__)')
  100. if [[ "$reported_version" != "$VERSION" ]]; then
  101. echo " error."
  102. echo "*** ERROR: mwparserfromhell is reporting its version as $reported_version, not $VERSION!"
  103. deactivate
  104. cd ..
  105. rm -rf $virtdir
  106. exit 1
  107. else
  108. echo " done."
  109. fi
  110. pip -q uninstall -y mwparserfromhell
  111. echo -n "Downloading mwparserfromhell source tarball..."
  112. curl -sL "https://pypi.io/packages/source/m/mwparserfromhell/mwparserfromhell-$VERSION.tar.gz" -o "mwparserfromhell.tar.gz"
  113. echo " done."
  114. tar -xf mwparserfromhell.tar.gz
  115. rm mwparserfromhell.tar.gz
  116. cd mwparserfromhell-$VERSION
  117. echo "Running unit tests..."
  118. python setup.py -q install
  119. python -m pytest
  120. if [[ "$?" != "0" ]]; then
  121. echo "*** ERROR: Unit tests failed!"
  122. deactivate
  123. cd ../..
  124. rm -rf $virtdir
  125. exit 1
  126. fi
  127. echo -n "Everything looks good. Cleaning up..."
  128. deactivate
  129. cd ../..
  130. rm -rf $virtdir
  131. echo " done."
  132. }
  133. echo "Preparing mwparserfromhell v$VERSION..."
  134. cd "$SCRIPT_DIR/.."
  135. check_git
  136. update_version
  137. update_appveyor
  138. update_changelog
  139. update_docs_changelog
  140. do_git_stuff
  141. upload_to_pypi
  142. post_release
  143. test_release
  144. echo "All done."
  145. exit 0