Improve test skipping functionality
[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_test=false
18 if [ "$1" = '--skip-test' ]; then
19     skip_test=true
20     shift
21 fi
22 if [ -z "$1" ]; then echo "ERROR: specify version number like this: $0 1994.09.06"; exit 1; fi
23 version="$1"
24 if [ ! -z "`git tag | grep "$version"`" ]; then echo 'ERROR: version already present'; exit 1; fi
25 if [ ! -z "`git status --porcelain | grep -v CHANGELOG`" ]; then echo 'ERROR: the working directory is not clean; commit or stash changes'; exit 1; fi
26 if [ ! -f "updates_key.pem" ]; then echo 'ERROR: updates_key.pem missing'; exit 1; fi
27
28 /bin/echo -e "\n### First of all, testing..."
29 make cleanall
30 if $skip_tests; then
31     echo 'SKIPPING TESTS'
32 else
33     nosetests --verbose --with-coverage --cover-package=youtube_dl --cover-html test --stop || exit 1
34 fi
35
36 /bin/echo -e "\n### Changing version in version.py..."
37 sed -i "s/__version__ = '.*'/__version__ = '$version'/" youtube_dl/version.py
38
39 /bin/echo -e "\n### Committing CHANGELOG README.md and youtube_dl/version.py..."
40 make README.md
41 git add CHANGELOG README.md youtube_dl/version.py
42 git commit -m "release $version"
43
44 /bin/echo -e "\n### Now tagging, signing and pushing..."
45 git tag -s -m "Release $version" "$version"
46 git show "$version"
47 read -p "Is it good, can I push? (y/n) " -n 1
48 if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1; fi
49 echo
50 MASTER=$(git rev-parse --abbrev-ref HEAD)
51 git push origin $MASTER:master
52 git push origin "$version"
53
54 /bin/echo -e "\n### OK, now it is time to build the binaries..."
55 REV=$(git rev-parse HEAD)
56 make youtube-dl youtube-dl.tar.gz
57 wget "http://jeromelaheurte.net:8142/download/rg3/youtube-dl/youtube-dl.exe?rev=$REV" -O youtube-dl.exe || \
58         wget "http://jeromelaheurte.net:8142/build/rg3/youtube-dl/youtube-dl.exe?rev=$REV" -O youtube-dl.exe
59 mkdir -p "build/$version"
60 mv youtube-dl youtube-dl.exe "build/$version"
61 mv youtube-dl.tar.gz "build/$version/youtube-dl-$version.tar.gz"
62 RELEASE_FILES="youtube-dl youtube-dl.exe youtube-dl-$version.tar.gz"
63 (cd build/$version/ && md5sum $RELEASE_FILES > MD5SUMS)
64 (cd build/$version/ && sha1sum $RELEASE_FILES > SHA1SUMS)
65 (cd build/$version/ && sha256sum $RELEASE_FILES > SHA2-256SUMS)
66 (cd build/$version/ && sha512sum $RELEASE_FILES > SHA2-512SUMS)
67 git checkout HEAD -- youtube-dl youtube-dl.exe
68
69 /bin/echo -e "\n### Signing and uploading the new binaries to youtube-dl.org..."
70 for f in $RELEASE_FILES; do gpg --detach-sig "build/$version/$f"; done
71 scp -r "build/$version" ytdl@youtube-dl.org:html/downloads/
72
73 /bin/echo -e "\n### Now switching to gh-pages..."
74 git clone --branch gh-pages --single-branch . build/gh-pages
75 ROOT=$(pwd)
76 (
77     set -e
78     ORIGIN_URL=$(git config --get remote.origin.url)
79     cd build/gh-pages
80     "$ROOT/devscripts/gh-pages/add-version.py" $version
81     "$ROOT/devscripts/gh-pages/update-feed.py"
82     "$ROOT/devscripts/gh-pages/sign-versions.py" < "$ROOT/updates_key.pem"
83     "$ROOT/devscripts/gh-pages/generate-download.py"
84     "$ROOT/devscripts/gh-pages/update-copyright.py"
85     git add *.html *.html.in update
86     git commit -m "release $version"
87     git show HEAD
88     read -p "Is it good, can I push? (y/n) " -n 1
89     if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1; fi
90     echo
91     git push "$ROOT" gh-pages
92     git push "$ORIGIN_URL" gh-pages
93 )
94 rm -rf build
95
96 make pypi-files
97 echo "Uploading to PyPi ..."
98 python setup.py sdist upload
99 make clean
100
101 /bin/echo -e "\n### DONE!"