Move /var/www/peertube to $PEERTUBE_PATH in upgrade.sh
[oweals/peertube.git] / scripts / release.sh
1 #!/bin/bash
2
3 set -eu
4
5 shutdown() {
6   # Get our process group id
7   # shellcheck disable=SC2009
8   PGID=$(ps -o pgid= $$ | grep -o "[0-9]*")
9
10   # Kill it in a new new process group
11   setsid kill -- -"$PGID"
12   exit 0
13 }
14
15 trap "shutdown" SIGINT SIGTERM
16
17 if [ -z "$1" ]; then
18   echo "Need version as argument"
19   exit -1
20 fi
21
22 if [ -z "$GITHUB_TOKEN" ]; then
23   echo "Need GITHUB_TOKEN env set."
24   exit -1
25 fi
26
27 branch=$(git symbolic-ref --short -q HEAD)
28 if [ "$branch" != "develop" ]; then
29   echo "Need to be on develop branch."
30   exit -1
31 fi
32
33 version="v$1"
34 directory_name="peertube-$version"
35 zip_name="peertube-$version.zip"
36 tar_name="peertube-$version.tar.xz"
37
38 changelog=$(awk -v version="$version" '/## v/ { printit = $2 == version }; printit;' CHANGELOG.md | grep -v "$version" | sed '1{/^$/d}')
39
40 printf "Changelog will be:\\n%s\\n" "$changelog"
41
42 read -p "Are you sure to release? " -n 1 -r
43 echo
44 if [[ ! $REPLY =~ ^[Yy]$ ]]
45 then
46   exit 0
47 fi
48
49 (
50   cd client
51   npm version --no-git-tag-version --no-commit-hooks "$1"
52 )
53
54 npm version -f --no-git-tag-version --no-commit-hooks "$1"
55
56 git commit package.json client/package.json -m "Bumped to version $version"
57 git tag -s -a "$version" -m "$version"
58
59 npm run build
60 rm "./client/dist/stats.json"
61
62 # Creating the archives
63 (
64   # local variables
65   directories_to_archive=("$directory_name/CREDITS.md" "$directory_name/FAQ.md" \
66                           "$directory_name/LICENSE" "$directory_name/README.md" \
67                           "$directory_name/client/dist/" "$directory_name/client/yarn.lock" \
68                           "$directory_name/client/package.json" "$directory_name/config" \
69                           "$directory_name/dist" "$directory_name/package.json" \
70                           "$directory_name/scripts" "$directory_name/support" \
71                           "$directory_name/tsconfig.json" "$directory_name/yarn.lock")
72   maintainer_public_key="583A612D890159BE"
73
74   # temporary setup
75   cd ..
76   ln -s "PeerTube" "$directory_name"
77
78   # archive creation + signing
79   zip -r "PeerTube/$zip_name" "${directories_to_archive[@]}"
80   gpg --armor --detach-sign -u "$maintainer_public_key" "PeerTube/$zip_name"
81   XZ_OPT=-e9 tar cfJ "PeerTube/$tar_name" "${directories_to_archive[@]}"
82   gpg --armor --detach-sign -u "$maintainer_public_key" "PeerTube/$tar_name"
83
84   # temporary setup destruction
85   rm "$directory_name"
86 )
87
88 # Creating the release on GitHub, with the created archives
89 (
90   git push origin --tag
91
92   github-release release --user chocobozzz --repo peertube --tag "$version" --name "$version" --description "$changelog"
93   github-release upload --user chocobozzz --repo peertube --tag "$version" --name "$zip_name" --file "$zip_name"
94   github-release upload --user chocobozzz --repo peertube --tag "$version" --name "$zip_name.asc" --file "$zip_name.asc"
95   github-release upload --user chocobozzz --repo peertube --tag "$version" --name "$tar_name" --file "$tar_name"
96   github-release upload --user chocobozzz --repo peertube --tag "$version" --name "$tar_name.asc" --file "$tar_name.asc"
97
98   git push origin develop
99
100   # Update master branch
101   git checkout master
102   git rebase develop
103   git push origin master
104   git checkout develop
105 )