#!/bin/bash
version="$1"

if [ -z "$version" ]; then
    echo "Release what version?"
    exit 1
fi

git checkout -tb compat-release
git apply - <<EOF
diff --git a/.travis.yml b/.travis.yml
index 8ce8de4..498628e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -5,6 +5,7 @@ cache:
     - $HOME/.composer/cache
 
 php:
+  - 5.6
   - 7.0
   - 7.1
   - nightly
@@ -13,7 +14,7 @@ matrix:
   allow_failures:
     - php: nightly
   include:
-    - php: 7.0
+    - php: 5.6
       env: 'COMPOSER_FLAGS="--prefer-stable --prefer-lowest"'
 
 before_script:
EOF

composer run php5ize
composer run test

if [ $? -gt 0 ]; then
    echo "Tests failed, aborting release $version!"
    exit 1
fi

git commit -a -m "Release $version for PHP 5.x"
git tag $version
git push -u origin
git push --tags
git checkout master
git branch -D compat-release
git push origin :compat-release

echo "Version $version released! Tweet that noise!"

