release.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. peertube_directory=$(basename $(pwd))
  22. branch=$(git symbolic-ref --short -q HEAD)
  23. if [ "$branch" != "develop" ] && [[ "$branch" != release/* ]]; then
  24. echo "Need to be on develop or release branch."
  25. exit -1
  26. fi
  27. version="v$1"
  28. github_prerelease_option=""
  29. if [[ "$version" = *"-alpha."* ]] || [[ "$version" = *"-beta."* ]] || [[ "$version" = *"-rc."* ]]; then
  30. echo -e "This is a pre-release.\n"
  31. github_prerelease_option="--pre-release"
  32. fi
  33. directory_name="peertube-$version"
  34. zip_name="peertube-$version.zip"
  35. tar_name="peertube-$version.tar.xz"
  36. changelog=$(awk -v version="$version" '/## v/ { printit = $2 == version }; printit;' CHANGELOG.md | grep -v "## $version" | sed '1{/^$/d}')
  37. printf "Changelog will be:\\n\\n%s\\n\\n" "$changelog"
  38. read -p "Are you sure to release? " -n 1 -r
  39. echo
  40. if [[ ! $REPLY =~ ^[Yy]$ ]]; then
  41. exit 0
  42. fi
  43. (
  44. cd client
  45. npm version --no-git-tag-version --no-commit-hooks "$1"
  46. )
  47. npm version -f --no-git-tag-version --no-commit-hooks "$1"
  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 -- --source-map
  51. rm -f "./client/dist/en-US/stats.json"
  52. rm -f "./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/yarn.lock")
  63. # temporary setup
  64. cd ..
  65. ln -s "$peertube_directory" "$directory_name"
  66. # archive creation + signing
  67. zip -9 -r "$peertube_directory/$zip_name" "${directories_to_archive[@]}"
  68. gpg --armor --detach-sign -u "$maintainer_public_key" "$peertube_directory/$zip_name"
  69. XZ_OPT="-e9 -T0" tar cfJ "$peertube_directory/$tar_name" "${directories_to_archive[@]}"
  70. gpg --armor --detach-sign -u "$maintainer_public_key" "$peertube_directory/$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. # Wait for the release to be published, we had some issues when the files were not uploaded because of "unknown release" error
  83. sleep 2
  84. github-release upload --user chocobozzz --repo peertube --tag "$version" --name "$zip_name" --file "$zip_name"
  85. github-release upload --user chocobozzz --repo peertube --tag "$version" --name "$zip_name.asc" --file "$zip_name.asc"
  86. github-release upload --user chocobozzz --repo peertube --tag "$version" --name "$tar_name" --file "$tar_name"
  87. github-release upload --user chocobozzz --repo peertube --tag "$version" --name "$tar_name.asc" --file "$tar_name.asc"
  88. git push origin "$branch"
  89. # Only update master if it is not a pre release
  90. if [ -z "$github_prerelease_option" ]; then
  91. # Update master branch
  92. git checkout master
  93. git merge "$branch"
  94. git push origin master
  95. git checkout "$branch"
  96. # Release types package
  97. npm run generate-types-package "$version"
  98. cd packages/types/dist
  99. npm publish --access public
  100. fi
  101. )