Skip to content

Commit

Permalink
release.sh improvements: options, ppa-friendly naming
Browse files Browse the repository at this point in the history
* Configure with real option processing rather than environment vars;
* We don't (shouldn't) have bashisms, so use a /bin/sh shebang;
* Headless option for skipping GUI tests;
* Optional Debian-style tarball naming scheme, for PPA making;
* Configurable output location, again for PPAs;
* Make .tar.gz/.tar.bz2 outputs optional;
* Better tempfile management;
* Add a help option.

Addresses part of mypaint#191: any PPA debianization will be
reliant on tarballs with special names. Plus I want to make the script
nicer.
  • Loading branch information
achadwick committed Feb 10, 2015
1 parent 5fa2cab commit 68670ab
Showing 1 changed file with 133 additions and 40 deletions.
173 changes: 133 additions & 40 deletions release.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,105 @@
#!/bin/bash
# Make a tarball release from git, running tests.
# This does roughly what 'make distcheck' would do if we were using autotools.
#
# Usage:
# $ sh release.sh
#
# Environment:
# SKIP_GITCHECK allow running with uncommitted changes
# SKIP_TESTS avoid running the tests
# SKIP_CLEANUP don't clean up the export location
#
# Only skip phases when debugging the export process itself.
#!/bin/sh
#: Make tarball releases from git, running tests. This does roughly
#: what 'make distcheck' would do if we were using autotools.
#:
#: Usage:
#: $ ./release.sh [OPTIONS] [--] [OUTPUTDIR]
#:
#: Options:
#: --help show this message and exit ok
#: --no-gitcheck allow running with uncommitted changes
#: --no-tests avoid running the tests
#: --no-cleanup don't clean up the export location
#: --headless don't do anything requiring graphical output
#: --debian-naming outputs are debian-style .orig.tar.Xs (for PPAs)
#: --gzip-tarball make the optional .tar.gz tarball
#: --bzip2-tarball make the optional .tar.bz2 tarball
#:
#: This script must be run from the top-level directory of a MyPaint
#: git checkout. By default, it makes just one .tar.xz output file
#: in the current working directory.
#:
#: Only skip tests and checks when debugging the export process itself.

set -e

SKIP_GITCHECK=false
SKIP_TESTS=false
SKIP_CLEANUP=false
DEBIAN_NAMING=false
GZIP_TARBALL=false
BZIP2_TARBALL=false
OUTPUT_DIR="$(pwd)"

while test $# -gt 0; do
case "$1" in
--help)
grep '^#:' $0
exit 0;
;;
--no-gitcheck)
SKIP_GITCHECK=true
shift
;;
--no-tests)
SKIP_TESTS=true
shift
;;
--no-cleanup)
SKIP_CLEANUP=true
shift
;;
--debian-naming)
DEBIAN_NAMING=true
shift
;;
--gzip-tarball)
GZIP_TARBALL=true
shift
;;
--bzip2-tarball)
BZIP2_TARBALL=true
shift
;;
--headless)
HEADLESS=true
shift
;;
--)
shift
break
;;
-*)
echo >&2 "Unknown option $1 (try running with --help)"
exit 1
;;
*)
break
;;
esac
done
if test $# -gt 0; then
OUTPUT_DIR="$1"
shift
fi
if test $# -gt 0; then
echo >&2 "Trailing junk in args: \"$@\" (try running with --help)"
exit 1
fi


if ! test -d .git; then
echo "Not at the root of a git repository"
exit 1
fi
if test "x$SKIP_GITCHECK" = "x"; then
if ! $SKIP_GITCHECK; then
if ! git diff --quiet; then
echo "You have local changes, stage them first with 'git add'!"
exit 1
fi
fi

# Base version; a string like "1.1.0" for stable releases or "1.1.1-activedev"
# Base version; a string like "1.1.0" for stable releases or "1.1.1-alpha"
# when making prereleases during the active development cycle.
base_version="`python lib/meta.py`"
echo "Version $base_version"
Expand All @@ -49,14 +123,23 @@ if echo $base_version | grep -q -- "-"; then
fi

orig_dir="$(pwd)"
tarball_basename="mypaint-$tarball_version"
exportdir_basename="mypaint-$tarball_version"
exportdir_path="/tmp/$exportdir_basename"
tarball_output_dir="$(pwd)"

# Construct release tmpdir
# Tarball naming
if $DEBIAN_NAMING; then
tarball_version=`echo $tarball_version | sed -e 's/-/~/'`
tarball_basename="mypaint_${tarball_version}.orig.tar"
else
tarball_basename="mypaint-${tarball_version}.tar"
fi

# Base version name is used for the directory
rm -rf "$exportdir_path"
exportdir_basename="mypaint-$base_version"
exportdir_location="/tmp/.mypaint-export-$$"
exportdir_path="$exportdir_location/$exportdir_basename"

# Construct release tmpdir
rm -rf "$exportdir_location"
mkdir -p "$exportdir_location"
git checkout-index -a -f --prefix="$exportdir_path/"

# Include submodules into release tarball
Expand All @@ -67,9 +150,10 @@ for submod_path in $submodule_paths; do
git checkout-index -a -f --prefix="$exportdir_path/$submod_path/")
done

# Tidy up release tmpdir, and record info in it about what was used. If the
# release_info file exists in a build tree, scons will use it in the generated
# ./mypaint script in place of information it would otherwise glean from .git
# Tidy up release tmpdir, and record info in it about what was used. If
# the release_info file exists in a build tree, scons will write it into
# the generated ./mypaint script in place of information it would
# otherwise glean from .git. The format is valid Python and shell.
cd "$exportdir_path"
rm -f release.sh
rm -f .travis.yml
Expand All @@ -84,46 +168,55 @@ echo >>release_info "MYPAINT_VERSION_CEREMONIAL = '$long_version'"
cd ..

# Create tarballs of release dir before we do any test builds
tarball="$tarball_output_dir/$exportdir_basename.tar"
mkdir -p "$OUTPUT_DIR"
tarball="$OUTPUT_DIR/$tarball_basename"
rm -f "$tarball"
tar -cvf "$tarball" "$exportdir_basename"

echo "Making $tarball.gz ..."
gzip -9 --keep --force "$tarball"
echo "Making $tarball.bz2 ..."
bzip2 -9 --keep --force "$tarball"
if $GZIP_TARBALL; then
echo "Making $tarball.gz ..."
gzip -9 --keep --force "$tarball"
fi

if $BZIP2_TARBALL; then
echo "Making $tarball.bz2 ..."
bzip2 -9 --keep --force "$tarball"
fi

echo "Making $tarball.xz ..."
xz -9 --force "$tarball"

# Build the release and test it
if test "x$SKIP_TESTS" = "x"; then
if $SKIP_TESTS; then
echo "Skipping debug build and tests"
else
echo "Making debug build inside $exportdir_path ..."
cd "$exportdir_path"
scons debug=true
echo "Running tests ..."
python tests/test_mypaintlib.py
python tests/test_compositeops.py
python tests/test_rendering.py
python tests/test_performance.py -a -c 1
python tests/test_memory_leak.py -a -e
if ! $HEADLESS; then
python tests/test_performance.py -a -c 1
python tests/test_memory_leak.py -a -e
fi
echo "Done testing."
else
echo "Skipping debug build and tests (SKIP_TESTS)"
fi

# Clean up
cd "$orig_dir"
cat "$exportdir_path/release_info"
if test "x$SKIP_CLEANUP" = "x"; then
echo "Cleaning up $exportdir_path ..."
rm -fr "$exportdir_path"
if $SKIP_CLEANUP; then
echo "Skipping cleanup of $exportdir_location"
else
echo "Skipping cleanup of $exportdir_path (SKIP_CLEANUP)"
echo "Cleaning up $exportdir_location ..."
rm -fr "$exportdir_location"
fi

# Results, notices about tagging
ls -sSh "$tarball".gz
ls -sSh "$tarball".bz2
$GZIP_TARBALL && ls -sSh "$tarball".gz
$BZIP2_TARBALL && ls -sSh "$tarball".bz2
ls -sSh "$tarball".xz
if $is_prerelease; then
echo "Prereleases are generally not tagged in git, with the exception of"
Expand Down

0 comments on commit 68670ab

Please sign in to comment.