release.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. branch=$(git symbolic-ref --short -q HEAD)
  21. if [ "$branch" != "develop" ] && [[ "$branch" != feature/* ]]; then
  22. echo "Need to be on develop or release branch."
  23. exit -1
  24. fi
  25. version="v$1"
  26. github_prerelease_option=""
  27. if [[ "$version" = *".pre."* ]]; then
  28. echo "This is a pre-release."
  29. github_prerelease_option="--pre-release"
  30. fi
  31. directory_name="peertube-$version"
  32. zip_name="peertube-$version.zip"
  33. tar_name="peertube-$version.tar.xz"
  34. changelog=$(awk -v version="$version" '/## v/ { printit = $2 == version }; printit;' CHANGELOG.md | grep -v "$version" | sed '1{/^$/d}')
  35. printf "Changelog will be:\\n%s\\n" "$changelog"
  36. read -p "Are you sure to release? " -n 1 -r
  37. echo
  38. if [[ ! $REPLY =~ ^[Yy]$ ]]; then
  39. exit 0
  40. fi
  41. (
  42. cd client
  43. npm version --no-git-tag-version --no-commit-hooks "$1"
  44. )
  45. npm version -f --no-git-tag-version --no-commit-hooks "$1"
  46. git commit package.json client/package.json -m "Bumped to version $version"
  47. git tag -s -a "$version" -m "$version"
  48. npm run build
  49. rm "./client/dist/en_US/stats.json"
  50. rm "./client/dist/embed-stats.json"
  51. # Creating the archives
  52. (
  53. # local variables
  54. directories_to_archive=("$directory_name/CREDITS.md" "$directory_name/FAQ.md" \
  55. "$directory_name/LICENSE" "$directory_name/README.md" \
  56. "$directory_name/client/dist/" "$directory_name/client/yarn.lock" \
  57. "$directory_name/client/package.json" "$directory_name/config" \
  58. "$directory_name/dist" "$directory_name/package.json" \
  59. "$directory_name/scripts" "$directory_name/support" \
  60. "$directory_name/tsconfig.json" "$directory_name/yarn.lock")
  61. maintainer_public_key="583A612D890159BE"
  62. # temporary setup
  63. cd ..
  64. ln -s "PeerTube" "$directory_name"
  65. # archive creation + signing
  66. zip -r "PeerTube/$zip_name" "${directories_to_archive[@]}"
  67. gpg --armor --detach-sign -u "$maintainer_public_key" "PeerTube/$zip_name"
  68. XZ_OPT=-e9 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. github-release upload --user chocobozzz --repo peertube --tag "$version" --name "$zip_name" --file "$zip_name"
  82. github-release upload --user chocobozzz --repo peertube --tag "$version" --name "$zip_name.asc" --file "$zip_name.asc"
  83. github-release upload --user chocobozzz --repo peertube --tag "$version" --name "$tar_name" --file "$tar_name"
  84. github-release upload --user chocobozzz --repo peertube --tag "$version" --name "$tar_name.asc" --file "$tar_name.asc"
  85. git push origin "$branch"
  86. # Only update master if it is not a pre release
  87. if [ -z "$github_prerelease_option" ]; then
  88. # Update master branch
  89. git checkout master
  90. git merge "$branch"
  91. git push origin master
  92. git checkout "$branch"
  93. fi
  94. )