A Python parser for MediaWiki wikicode https://mwparserfromhell.readthedocs.io/
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

136 linhas
3.8 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_changelog() {
  26. filename="CHANGELOG"
  27. echo -n "Updating $filename..."
  28. sed -e "1s/.*/v$VERSION (released $RELEASE_DATE):/" -i "" $filename
  29. echo " done."
  30. }
  31. update_docs_changelog() {
  32. filename="docs/changelog.rst"
  33. echo -n "Updating $filename..."
  34. dashes=$(seq 1 $(expr ${#VERSION} + 1) | sed 's/.*/-/' | tr -d '\n')
  35. previous_lineno=$(expr $(grep -n -e "^---" $filename | sed '2q;d' | cut -d ':' -f 1) - 1)
  36. previous_version=$(sed $previous_lineno'q;d' $filename)
  37. sed \
  38. -e "4s/.*/v$VERSION/" \
  39. -e "5s/.*/$dashes/" \
  40. -e "7s/.*/\`Released $RELEASE_DATE <https:\/\/github.com\/earwig\/mwparserfromhell\/tree\/v$VERSION>\`_/" \
  41. -e "8s/.*/(\`changes <https:\/\/github.com\/earwig\/mwparserfromhell\/compare\/$previous_version...v$VERSION>\`__):/" \
  42. -i "" $filename
  43. echo " done."
  44. }
  45. do_git_stuff() {
  46. echo -n "Ready to commit and push? [yN] "
  47. read confirm
  48. if [[ ${confirm,,} != "y" ]]; then
  49. exit 1
  50. fi
  51. echo -n "Git: committing, tagging, and merging release..."
  52. git commit -qam "release/$VERSION"
  53. git tag v$VERSION -s -m "version $VERSION"
  54. echo -n " pushing..."
  55. git push -q --tags origin main
  56. echo " done."
  57. }
  58. post_release() {
  59. echo
  60. echo "*** Release completed."
  61. echo "*** Update: https://github.com/earwig/mwparserfromhell/releases/tag/v$VERSION"
  62. echo "*** Verify: https://pypi.org/project/mwparserfromhell"
  63. echo "*** Verify: https://github.com/earwig/mwparserfromhell/actions"
  64. echo "*** Verify: https://mwparserfromhell.readthedocs.io"
  65. echo "*** Press enter to sanity-check the release."
  66. read
  67. }
  68. test_release() {
  69. echo
  70. echo "Checking mwparserfromhell v$VERSION..."
  71. echo -n "Creating a virtualenv..."
  72. virtdir="mwparser-test-env"
  73. python -m venv $virtdir
  74. cd $virtdir
  75. source bin/activate
  76. echo " done."
  77. echo -n "Installing mwparserfromhell with pip..."
  78. pip -q install --upgrade pip
  79. pip -q install mwparserfromhell pytest
  80. echo " done."
  81. echo -n "Checking version..."
  82. reported_version=$(python -c 'print(__import__("mwparserfromhell").__version__)')
  83. if [[ "$reported_version" != "$VERSION" ]]; then
  84. echo " error."
  85. echo "*** ERROR: mwparserfromhell is reporting its version as $reported_version, not $VERSION!"
  86. deactivate
  87. cd ..
  88. rm -rf $virtdir
  89. exit 1
  90. else
  91. echo " done."
  92. fi
  93. pip -q uninstall -y mwparserfromhell
  94. deactivate
  95. echo -n "Downloading mwparserfromhell source tarball..."
  96. curl -sL "https://files.pythonhosted.org/packages/source/m/mwparserfromhell/mwparserfromhell-$VERSION.tar.gz" -o "mwparserfromhell.tar.gz"
  97. echo " done."
  98. tar -xf mwparserfromhell.tar.gz
  99. rm mwparserfromhell.tar.gz
  100. cd mwparserfromhell-$VERSION
  101. echo "Running unit tests..."
  102. uv run pytest
  103. if [[ "$?" != "0" ]]; then
  104. echo "*** ERROR: Unit tests failed!"
  105. cd ../..
  106. rm -rf $virtdir
  107. exit 1
  108. fi
  109. echo -n "Everything looks good. Cleaning up..."
  110. cd ../..
  111. rm -rf $virtdir
  112. echo " done."
  113. }
  114. echo "Preparing mwparserfromhell v$VERSION..."
  115. cd "$SCRIPT_DIR/.."
  116. check_git
  117. update_changelog
  118. update_docs_changelog
  119. do_git_stuff
  120. post_release
  121. test_release
  122. echo "All done."
  123. exit 0