#!/bin/sh -e

if [ -d 'venv' ] ; then
    PREFIX="venv/bin/"
else
    PREFIX=""
fi

if [ ! -z "$GITHUB_ACTIONS" ]; then
  git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
  git config --local user.name "GitHub Action"

  VERSION=`grep __version__ ./uvicorn/__init__.py | grep -o '[0-9][^"]*'`

  if [ "refs/tags/${VERSION}" != "${GITHUB_REF}" ] ; then
    echo "GitHub Ref '${GITHUB_REF}' did not match package version '${VERSION}'"
    exit 1
  fi
fi

set -x

find uvicorn -type f -name "*.py[co]" -delete
find uvicorn -type d -name __pycache__ -delete

${PREFIX}pip install twine wheel mkdocs mkdocs-material mkautodoc
${PREFIX}python setup.py sdist bdist_wheel
${PREFIX}twine upload dist/*
${PREFIX}mkdocs gh-deploy --force
