A Python parser for MediaWiki wikicode https://mwparserfromhell.readthedocs.io/
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

154 wiersze
4.2 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_appveyor() {
  26. filename="appveyor.yml"
  27. echo -n "Updating $filename..."
  28. sed -e "s/version: .*/version: $VERSION-b{build}/" -i "" $filename
  29. echo " done."
  30. }
  31. update_changelog() {
  32. filename="CHANGELOG"
  33. echo -n "Updating $filename..."
  34. sed -e "1s/.*/v$VERSION (released $RELEASE_DATE):/" -i "" $filename
  35. echo " done."
  36. }
  37. update_docs_changelog() {
  38. filename="docs/changelog.rst"
  39. echo -n "Updating $filename..."
  40. dashes=$(seq 1 $(expr ${#VERSION} + 1) | sed 's/.*/-/' | tr -d '\n')
  41. previous_lineno=$(expr $(grep -n -e "^---" $filename | sed '2q;d' | cut -d ':' -f 1) - 1)
  42. previous_version=$(sed $previous_lineno'q;d' $filename)
  43. sed \
  44. -e "4s/.*/v$VERSION/" \
  45. -e "5s/.*/$dashes/" \
  46. -e "7s/.*/\`Released $RELEASE_DATE <https:\/\/github.com\/earwig\/mwparserfromhell\/tree\/v$VERSION>\`_/" \
  47. -e "8s/.*/(\`changes <https:\/\/github.com\/earwig\/mwparserfromhell\/compare\/$previous_version...v$VERSION>\`__):/" \
  48. -i "" $filename
  49. echo " done."
  50. }
  51. do_git_stuff() {
  52. echo -n "Ready to commit and push? [yN] "
  53. read confirm
  54. if [[ ${confirm,,} != "y" ]]; then
  55. exit 1
  56. fi
  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 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..."
  107. curl -sL "https://pypi.io/packages/source/m/mwparserfromhell/mwparserfromhell-$VERSION.tar.gz" -o "mwparserfromhell.tar.gz"
  108. echo " done."
  109. tar -xf mwparserfromhell.tar.gz
  110. rm mwparserfromhell.tar.gz
  111. cd mwparserfromhell-$VERSION
  112. echo "Running unit tests..."
  113. python setup.py -q install
  114. python -m pytest
  115. if [[ "$?" != "0" ]]; then
  116. echo "*** ERROR: Unit tests failed!"
  117. deactivate
  118. cd ../..
  119. rm -rf $virtdir
  120. exit 1
  121. fi
  122. echo -n "Everything looks good. Cleaning up..."
  123. deactivate
  124. cd ../..
  125. rm -rf $virtdir
  126. echo " done."
  127. }
  128. echo "Preparing mwparserfromhell v$VERSION..."
  129. cd "$SCRIPT_DIR/.."
  130. check_git
  131. update_appveyor
  132. update_changelog
  133. update_docs_changelog
  134. do_git_stuff
  135. upload_to_pypi
  136. post_release
  137. test_release
  138. echo "All done."
  139. exit 0