#!/usr/bin/env bash

set -euo pipefail

if [[ $# -lt 1 || -z "${1}" ]]; then
  printf 'Usage: %s <tag>\n' "./release.sh"
  exit 1
fi

tag="$1"
branch="$(git branch --show-current)"

if [[ "$branch" != "develop" ]]; then
  printf 'Error: must be on develop (current: %s)\n' "$branch"
  exit 1
fi

if [[ -n "$(git status --porcelain)" ]]; then
  printf 'Error: git worktree is not clean\n'
  exit 1
fi

php wp-cli app:build $tag

git add -A
git commit -m "build $tag"
git push origin develop

echo "Ready to release"
