release.sh 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. yarn check --integrity --verify-tree
  28. (cd client && yarn check --integrity --verify-tree)
  29. version="v$1"
  30. github_prerelease_option=""
  31. if [[ "$version" = *"-alpha."* ]] || [[ "$version" = *"-beta."* ]] || [[ "$version" = *"-rc."* ]]; then
  32. echo -e "This is a pre-release.\n"
  33. github_prerelease_option="--pre-release"
  34. fi
  35. directory_name="peertube-$version"
  36. zip_name="peertube-$version.zip"
  37. tar_name="peertube-$version.tar.xz"
  38. changelog=$(awk -v version="$version" '/## v/ { printit = $2 == version }; printit;' CHANGELOG.md | grep -v "## $version" | sed '1{/^$/d}')
  39. printf "Changelog will be:\\n\\n%s\\n\\n" "$changelog"
  40. read -p "Are you sure to release? " -n 1 -r
  41. echo
  42. if [[ ! $REPLY =~ ^[Yy]$ ]]; then
  43. exit 0
  44. fi
  45. (
  46. cd client
  47. npm version --no-git-tag-version --no-commit-hooks "$1"
  48. )
  49. npm version -f --no-git-tag-version --no-commit-hooks "$1"
  50. git commit package.json client/package.json ./support/doc/api/openapi.yaml -m "Bumped to version $version"
  51. git tag -s -a "$version" -m "$version"
  52. npm run build -- --source-map
  53. rm -f "./client/dist/en-US/stats.json"
  54. rm -f "./client/dist/embed-stats.json"
  55. # Clean up declaration files
  56. find dist/ packages/core-utils/dist/ \
  57. packages/ffmpeg/dist/ \
  58. packages/node-utils/dist/ \
  59. packages/models/dist/ \
  60. \( -name '*.d.ts' -o -name '*.d.ts.map' \) -type f -delete
  61. # Creating the archives
  62. (
  63. # local variables
  64. directories_to_archive=("$directory_name/CREDITS.md" "$directory_name/FAQ.md" \
  65. "$directory_name/LICENSE" "$directory_name/README.md" \
  66. "$directory_name/packages/core-utils/dist/" "$directory_name/packages/core-utils/package.json" \
  67. "$directory_name/packages/ffmpeg/dist/" "$directory_name/packages/ffmpeg/package.json" \
  68. "$directory_name/packages/node-utils/dist/" "$directory_name/packages/node-utils/package.json" \
  69. "$directory_name/packages/models/dist/" "$directory_name/packages/models/package.json" \
  70. "$directory_name/packages/transcription/dist/" "$directory_name/packages/transcription/package.json" \
  71. "$directory_name/client/dist/" "$directory_name/client/yarn.lock" \
  72. "$directory_name/client/package.json" "$directory_name/config" \
  73. "$directory_name/dist" "$directory_name/package.json" \
  74. "$directory_name/scripts/upgrade.sh" "$directory_name/support/doc" "$directory_name/support/freebsd" \
  75. "$directory_name/support/init.d" "$directory_name/support/nginx" "$directory_name/support/openapi" \
  76. "$directory_name/support/sysctl.d" "$directory_name/support/systemd" \
  77. "$directory_name/yarn.lock")
  78. # temporary setup
  79. cd ..
  80. ln -s "$peertube_directory" "$directory_name"
  81. # archive creation + signing
  82. zip -9 -r "$peertube_directory/$zip_name" "${directories_to_archive[@]}"
  83. gpg --armor --detach-sign -u "$maintainer_public_key" "$peertube_directory/$zip_name"
  84. XZ_OPT="-e9 -T0" tar cfJ "$peertube_directory/$tar_name" "${directories_to_archive[@]}"
  85. gpg --armor --detach-sign -u "$maintainer_public_key" "$peertube_directory/$tar_name"
  86. # temporary setup destruction
  87. rm "$directory_name"
  88. )
  89. # Creating the release on GitHub, with the created archives
  90. (
  91. git push origin --tag
  92. if [ -z "$github_prerelease_option" ]; then
  93. github-release release --user chocobozzz --repo peertube --tag "$version" --name "$version" --description "$changelog"
  94. else
  95. github-release release --user chocobozzz --repo peertube --tag "$version" --name "$version" --description "$changelog" "$github_prerelease_option"
  96. fi
  97. # Wait for the release to be published, we had some issues when the files were not uploaded because of "unknown release" error
  98. sleep 2
  99. github-release upload --user chocobozzz --repo peertube --tag "$version" --name "$zip_name" --file "$zip_name"
  100. github-release upload --user chocobozzz --repo peertube --tag "$version" --name "$zip_name.asc" --file "$zip_name.asc"
  101. github-release upload --user chocobozzz --repo peertube --tag "$version" --name "$tar_name" --file "$tar_name"
  102. github-release upload --user chocobozzz --repo peertube --tag "$version" --name "$tar_name.asc" --file "$tar_name.asc"
  103. git push origin "$branch"
  104. # Only update master if it is not a pre release
  105. if [ -z "$github_prerelease_option" ]; then
  106. # Update master branch
  107. git checkout master
  108. git merge "$branch"
  109. git push origin master
  110. git checkout "$branch"
  111. # Rebuild properly the server, with the declaration files
  112. npm run build:server
  113. # Release types package
  114. npm run generate-types-package "$version"
  115. cd packages/types-generator/dist
  116. npm publish --access public
  117. fi
  118. )