87e8eda50c1c5e3d0a5e41414fb8b1eba2ee27ee
[youtube-dl] / devscripts / release.sh
1 #!/bin/bash
2
3 # IMPORTANT: the following assumptions are made
4 # * the GH repo is on the origin remote
5 # * the gh-pages branch is named so locally
6 # * the git config user.signingkey is properly set
7
8 # You will need
9 # pip install coverage nose rsa wheel
10
11 # TODO
12 # release notes
13 # make hash on local files
14
15 set -e
16
17 skip_tests=true
18 buildserver='localhost:8142'
19
20 while true
21 do
22 case "$1" in
23     --run-tests)
24         skip_tests=false
25         shift
26     ;;
27     --buildserver)
28         buildserver="$2"
29         shift 2
30     ;;
31     --*)
32         echo "ERROR: unknown option $1"
33         exit 1
34     ;;
35     *)
36         break
37     ;;
38 esac
39 done
40
41 if [ -z "$1" ]; then echo "ERROR: specify version number like this: $0 1994.09.06"; exit 1; fi
42 version="$1"
43 major_version=$(echo "$version" | sed -n 's#^\([0-9]*\.[0-9]*\.[0-9]*\).*#\1#p')
44 if test "$major_version" '!=' "$(date '+%Y.%m.%d')"; then
45     echo "$version does not start with today's date!"
46     exit 1
47 fi
48
49 if [ ! -z "`git tag | grep "$version"`" ]; then echo 'ERROR: version already present'; exit 1; fi
50 if [ ! -z "`git status --porcelain | grep -v CHANGELOG`" ]; then echo 'ERROR: the working directory is not clean; commit or stash changes'; exit 1; fi
51 useless_files=$(find youtube_dl -type f -not -name '*.py')
52 if [ ! -z "$useless_files" ]; then echo "ERROR: Non-.py files in youtube_dl: $useless_files"; exit 1; fi
53 if [ ! -f "updates_key.pem" ]; then echo 'ERROR: updates_key.pem missing'; exit 1; fi
54 if ! type pandoc >/dev/null 2>/dev/null; then echo 'ERROR: pandoc is missing'; exit 1; fi
55 if ! python3 -c 'import rsa' 2>/dev/null; then echo 'ERROR: python3-rsa is missing'; exit 1; fi
56 if ! python3 -c 'import wheel' 2>/dev/null; then echo 'ERROR: wheel is missing'; exit 1; fi
57
58 /bin/echo -e "\n### First of all, testing..."
59 make clean
60 if $skip_tests ; then
61     echo 'SKIPPING TESTS'
62 else
63     nosetests --verbose --with-coverage --cover-package=youtube_dl --cover-html test --stop || exit 1
64 fi
65
66 /bin/echo -e "\n### Changing version in version.py..."
67 sed -i "s/__version__ = '.*'/__version__ = '$version'/" youtube_dl/version.py
68
69 /bin/echo -e "\n### Committing documentation, templates and youtube_dl/version.py..."
70 make README.md CONTRIBUTING.md .github/ISSUE_TEMPLATE.md supportedsites
71 git add README.md CONTRIBUTING.md .github/ISSUE_TEMPLATE.md docs/supportedsites.md youtube_dl/version.py
72 git commit -m "release $version"
73
74 /bin/echo -e "\n### Now tagging, signing and pushing..."
75 git tag -s -m "Release $version" "$version"
76 git show "$version"
77 read -p "Is it good, can I push? (y/n) " -n 1
78 if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1; fi
79 echo
80 MASTER=$(git rev-parse --abbrev-ref HEAD)
81 git push origin $MASTER:master
82 git push origin "$version"
83
84 /bin/echo -e "\n### OK, now it is time to build the binaries..."
85 REV=$(git rev-parse HEAD)
86 make youtube-dl youtube-dl.tar.gz
87 read -p "VM running? (y/n) " -n 1
88 wget "http://$buildserver/build/rg3/youtube-dl/youtube-dl.exe?rev=$REV" -O youtube-dl.exe
89 mkdir -p "build/$version"
90 mv youtube-dl youtube-dl.exe "build/$version"
91 mv youtube-dl.tar.gz "build/$version/youtube-dl-$version.tar.gz"
92 RELEASE_FILES="youtube-dl youtube-dl.exe youtube-dl-$version.tar.gz"
93 (cd build/$version/ && md5sum $RELEASE_FILES > MD5SUMS)
94 (cd build/$version/ && sha1sum $RELEASE_FILES > SHA1SUMS)
95 (cd build/$version/ && sha256sum $RELEASE_FILES > SHA2-256SUMS)
96 (cd build/$version/ && sha512sum $RELEASE_FILES > SHA2-512SUMS)
97
98 /bin/echo -e "\n### Signing and uploading the new binaries to GitHub..."
99 for f in $RELEASE_FILES; do gpg --passphrase-repeat 5 --detach-sig "build/$version/$f"; done
100
101 ROOT=$(pwd)
102 python devscripts/create-github-release.py $version "$ROOT/build/$version"
103
104 ssh ytdl@yt-dl.org "sh html/update_latest.sh $version"
105
106 /bin/echo -e "\n### Now switching to gh-pages..."
107 git clone --branch gh-pages --single-branch . build/gh-pages
108 (
109     set -e
110     ORIGIN_URL=$(git config --get remote.origin.url)
111     cd build/gh-pages
112     "$ROOT/devscripts/gh-pages/add-version.py" $version
113     "$ROOT/devscripts/gh-pages/update-feed.py"
114     "$ROOT/devscripts/gh-pages/sign-versions.py" < "$ROOT/updates_key.pem"
115     "$ROOT/devscripts/gh-pages/generate-download.py"
116     "$ROOT/devscripts/gh-pages/update-copyright.py"
117     "$ROOT/devscripts/gh-pages/update-sites.py"
118     git add *.html *.html.in update
119     git commit -m "release $version"
120     git push "$ROOT" gh-pages
121     git push "$ORIGIN_URL" gh-pages
122 )
123 rm -rf build
124
125 make pypi-files
126 echo "Uploading to PyPi ..."
127 python setup.py sdist bdist_wheel upload
128 make clean
129
130 /bin/echo -e "\n### DONE!"