release.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #!/bin/bash
  2. set -eu
  3. shutdown() {
  4. # Get our process group id
  5. # shellcheck disable=SC2009
  6. PGID=$(ps -o pgid= $$ | grep -o "[0-9]*")
  7. # Kill it in a new new process group
  8. setsid kill -- -"$PGID"
  9. exit 0
  10. }
  11. trap "shutdown" SIGINT SIGTERM
  12. if [ -z "$1" ]; then
  13. echo "Need version as argument"
  14. exit -1
  15. fi
  16. if [ -z "$GITHUB_TOKEN" ]; then
  17. echo "Need GITHUB_TOKEN env set."
  18. exit -1
  19. fi
  20. maintainer_public_key=${MAINTAINER_GPG:-"583A612D890159BE"}
  21. branch=$(git symbolic-ref --short -q HEAD)
  22. if [ "$branch" != "develop" ] && [[ "$branch" != release/* ]]; then
  23. echo "Need to be on develop or release branch."
  24. exit -1
  25. fi
  26. version="v$1"
  27. github_prerelease_option=""
  28. if [[ "$version" = *"-alpha."* ]] || [[ "$version" = *"-beta."* ]] || [[ "$version" = *"-rc."* ]]; then
  29. echo -e "This is a pre-release.\n"
  30. github_prerelease_option="--pre-release"
  31. fi
  32. directory_name="peertube-$version"
  33. zip_name="peertube-$version.zip"
  34. tar_name="peertube-$version.tar.xz"
  35. changelog=$(awk -v version="$version" '/## v/ { printit = $2 == version }; printit;' CHANGELOG.md | grep -v "## $version" | sed '1{/^$/d}')
  36. printf "Changelog will be:\\n\\n%s\\n\\n" "$changelog"
  37. read -p "Are you sure to release? " -n 1 -r
  38. echo
  39. if [[ ! $REPLY =~ ^[Yy]$ ]]; then
  40. exit 0
  41. fi
  42. (
  43. cd client
  44. npm version --no-git-tag-version --no-commit-hooks "$1"
  45. )
  46. npm version -f --no-git-tag-version --no-commit-hooks "$1"
  47. git commit package.json client/package.json ./support/doc/api/openapi.yaml -m "Bumped to version $version"
  48. git tag -s -a "$version" -m "$version"
  49. npm run build -- --source-map
  50. rm -f "./client/dist/en-US/stats.json"
  51. rm -f "./client/dist/embed-stats.json"
  52. # Creating the archives
  53. (
  54. # local variables
  55. directories_to_archive=("$directory_name/CREDITS.md" "$directory_name/FAQ.md" \
  56. "$directory_name/LICENSE" "$directory_name/README.md" \
  57. "$directory_name/client/dist/" "$directory_name/client/yarn.lock" \
  58. "$directory_name/client/package.json" "$directory_name/config" \
  59. "$directory_name/dist" "$directory_name/package.json" \
  60. "$directory_name/scripts" "$directory_name/support" \
  61. "$directory_name/yarn.lock")
  62. # temporary setup
  63. cd ..
  64. ln -s "PeerTube" "$directory_name"
  65. # archive creation + signing
  66. zip -9 -r "PeerTube/$zip_name" "${directories_to_archive[@]}"
  67. gpg --armor --detach-sign -u "$maintainer_public_key" "PeerTube/$zip_name"
  68. XZ_OPT="-e9 -T0" tar cfJ "PeerTube/$tar_name" "${directories_to_archive[@]}"
  69. gpg --armor --detach-sign -u "$maintainer_public_key" "PeerTube/$tar_name"
  70. # temporary setup destruction
  71. rm "$directory_name"
  72. )
  73. # Creating the release on GitHub, with the created archives
  74. (
  75. git push origin --tag
  76. if [ -z "$github_prerelease_option" ]; then
  77. github-release release --user chocobozzz --repo peertube --tag "$version" --name "$version" --description "$changelog"
  78. else
  79. github-release release --user chocobozzz --repo peertube --tag "$version" --name "$version" --description "$changelog" "$github_prerelease_option"
  80. fi
  81. # Wait for the release to be published, we had some issues when the files were not uploaded because of "unknown release" error
  82. sleep 2
  83. github-release upload --user chocobozzz --repo peertube --tag "$version" --name "$zip_name" --file "$zip_name"
  84. github-release upload --user chocobozzz --repo peertube --tag "$version" --name "$zip_name.asc" --file "$zip_name.asc"
  85. github-release upload --user chocobozzz --repo peertube --tag "$version" --name "$tar_name" --file "$tar_name"
  86. github-release upload --user chocobozzz --repo peertube --tag "$version" --name "$tar_name.asc" --file "$tar_name.asc"
  87. git push origin "$branch"
  88. # Only update master if it is not a pre release
  89. if [ -z "$github_prerelease_option" ]; then
  90. # Update master branch
  91. git checkout master
  92. git merge "$branch"
  93. git push origin master
  94. git checkout "$branch"
  95. # Release types package
  96. npm run generate-types-package "$version"
  97. cd packages/types/dist
  98. npm publish --access public
  99. fi
  100. )