2
1

release.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. ./scripts/openapi-peertube-version.sh
  48. git commit package.json client/package.json ./support/doc/api/openapi.yaml -m "Bumped to version $version"
  49. git tag -s -a "$version" -m "$version"
  50. npm run build
  51. rm "./client/dist/en_US/stats.json"
  52. rm "./client/dist/embed-stats.json"
  53. # Creating the archives
  54. (
  55. # local variables
  56. directories_to_archive=("$directory_name/CREDITS.md" "$directory_name/FAQ.md" \
  57. "$directory_name/LICENSE" "$directory_name/README.md" \
  58. "$directory_name/client/dist/" "$directory_name/client/yarn.lock" \
  59. "$directory_name/client/package.json" "$directory_name/config" \
  60. "$directory_name/dist" "$directory_name/package.json" \
  61. "$directory_name/scripts" "$directory_name/support" \
  62. "$directory_name/tsconfig.json" "$directory_name/yarn.lock")
  63. # temporary setup
  64. cd ..
  65. ln -s "PeerTube" "$directory_name"
  66. # archive creation + signing
  67. zip -r "PeerTube/$zip_name" "${directories_to_archive[@]}"
  68. gpg --armor --detach-sign -u "$maintainer_public_key" "PeerTube/$zip_name"
  69. XZ_OPT=-e9 tar cfJ "PeerTube/$tar_name" "${directories_to_archive[@]}"
  70. gpg --armor --detach-sign -u "$maintainer_public_key" "PeerTube/$tar_name"
  71. # temporary setup destruction
  72. rm "$directory_name"
  73. )
  74. # Creating the release on GitHub, with the created archives
  75. (
  76. git push origin --tag
  77. if [ -z "$github_prerelease_option" ]; then
  78. github-release release --user chocobozzz --repo peertube --tag "$version" --name "$version" --description "$changelog"
  79. else
  80. github-release release --user chocobozzz --repo peertube --tag "$version" --name "$version" --description "$changelog" "$github_prerelease_option"
  81. fi
  82. github-release upload --user chocobozzz --repo peertube --tag "$version" --name "$zip_name" --file "$zip_name"
  83. github-release upload --user chocobozzz --repo peertube --tag "$version" --name "$zip_name.asc" --file "$zip_name.asc"
  84. github-release upload --user chocobozzz --repo peertube --tag "$version" --name "$tar_name" --file "$tar_name"
  85. github-release upload --user chocobozzz --repo peertube --tag "$version" --name "$tar_name.asc" --file "$tar_name.asc"
  86. git push origin "$branch"
  87. # Only update master if it is not a pre release
  88. if [ -z "$github_prerelease_option" ]; then
  89. # Update master branch
  90. git checkout master
  91. git merge "$branch"
  92. git push origin master
  93. git checkout "$branch"
  94. fi
  95. )