#!/bin/bash

release=${1:-"tag"}

if [ "$release" == "tag" ]
  then
    git fetch
    tag=$(git describe --tags "$(git rev-list --tags --max-count=1)")
    git checkout "$tag"
    git pull
fi

if [ "$release" != "tag" ]
  then
    git fetch
    git checkout "$release"
    git pull
fi

composer install
composer dump-env prod
bin/console doctrine:database:create --if-not-exists
bin/console doctrine:migrations:migrate -n
bin/console cache:clear
bin/console cache:warmup
chown -R www-data:www-data .
