release.sh 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. # Clean up declaration files
  54. find dist/ packages/core-utils/dist/ \
  55. packages/ffmpeg/dist/ \
  56. packages/node-utils/dist/ \
  57. packages/models/dist/ \
  58. \( -name '*.d.ts' -o -name '*.d.ts.map' \) -type f -delete
  59. # Creating the archives
  60. (
  61. # local variables
  62. directories_to_archive=("$directory_name/CREDITS.md" "$directory_name/FAQ.md" \
  63. "$directory_name/LICENSE" "$directory_name/README.md" \
  64. "$directory_name/packages/core-utils/dist/" "$directory_name/packages/core-utils/package.json" \
  65. "$directory_name/packages/ffmpeg/dist/" "$directory_name/packages/ffmpeg/package.json" \
  66. "$directory_name/packages/node-utils/dist/" "$directory_name/packages/node-utils/package.json" \
  67. "$directory_name/packages/models/dist/" "$directory_name/packages/models/package.json" \
  68. "$directory_name/client/dist/" "$directory_name/client/yarn.lock" \
  69. "$directory_name/client/package.json" "$directory_name/config" \
  70. "$directory_name/dist" "$directory_name/package.json" \
  71. "$directory_name/scripts/upgrade.sh" "$directory_name/support" \
  72. "$directory_name/yarn.lock")
  73. # temporary setup
  74. cd ..
  75. ln -s "$peertube_directory" "$directory_name"
  76. # archive creation + signing
  77. zip -9 -r "$peertube_directory/$zip_name" "${directories_to_archive[@]}"
  78. gpg --armor --detach-sign -u "$maintainer_public_key" "$peertube_directory/$zip_name"
  79. XZ_OPT="-e9 -T0" tar cfJ "$peertube_directory/$tar_name" "${directories_to_archive[@]}"
  80. gpg --armor --detach-sign -u "$maintainer_public_key" "$peertube_directory/$tar_name"
  81. # temporary setup destruction
  82. rm "$directory_name"
  83. )
  84. # Creating the release on GitHub, with the created archives
  85. (
  86. git push origin --tag
  87. if [ -z "$github_prerelease_option" ]; then
  88. github-release release --user chocobozzz --repo peertube --tag "$version" --name "$version" --description "$changelog"
  89. else
  90. github-release release --user chocobozzz --repo peertube --tag "$version" --name "$version" --description "$changelog" "$github_prerelease_option"
  91. fi
  92. # Wait for the release to be published, we had some issues when the files were not uploaded because of "unknown release" error
  93. sleep 2
  94. github-release upload --user chocobozzz --repo peertube --tag "$version" --name "$zip_name" --file "$zip_name"
  95. github-release upload --user chocobozzz --repo peertube --tag "$version" --name "$zip_name.asc" --file "$zip_name.asc"
  96. github-release upload --user chocobozzz --repo peertube --tag "$version" --name "$tar_name" --file "$tar_name"
  97. github-release upload --user chocobozzz --repo peertube --tag "$version" --name "$tar_name.asc" --file "$tar_name.asc"
  98. git push origin "$branch"
  99. # Only update master if it is not a pre release
  100. if [ -z "$github_prerelease_option" ]; then
  101. # Update master branch
  102. git checkout master
  103. git merge "$branch"
  104. git push origin master
  105. git checkout "$branch"
  106. # Rebuild properly the server, with the declaration files
  107. npm run build:server
  108. # Release types package
  109. npm run generate-types-package "$version"
  110. cd packages/types-generator/dist
  111. npm publish --access public
  112. fi
  113. )