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