Skip to content

Commit

Permalink
Updated release and tests mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
omab committed May 30, 2020
1 parent 842f929 commit 5af7222
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -49,3 +49,5 @@ changelog.sh
\#*\#

.python-version

files/local.env
25 changes: 10 additions & 15 deletions Makefile
@@ -1,25 +1,20 @@
build:
@ python setup.py sdist
@ python setup.py bdist_wheel --python-tag py2
@ BUILD_VERSION=2 python setup.py sdist
@ BUILD_VERSION=2 python setup.py bdist_wheel --python-tag py2
@ BUILD_VERSION=3 python setup.py bdist_wheel --python-tag py3

publish:
@ python setup.py sdist upload
@ python setup.py bdist_wheel --python-tag py2 upload
@ BUILD_VERSION=3 python setup.py bdist_wheel --python-tag py3 upload
@ twine upload dist/*

release:
@ docker-compose run social-release

tests:
@ docker-compose run social-tests

clean:
@ find . -name '*.py[co]' -delete
@ find . -name '__pycache__' -delete
@ rm -rf *.egg-info dist build

docker-tox-build:
@ docker inspect omab/psa-social-app-django >/dev/null 2>&1 || ( \
docker build -t omab/psa-social-app-django . \
)

docker-tox: docker-tox-build
@ docker run -it --rm \
--name psa-social-app-django-test \
-v "`pwd`:/src" \
omab/psa-social-app-django tox
.PHONY: tests
27 changes: 27 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,27 @@
version: "3.7"

services:
social-release:
image: omab/social-auth-release
build:
context: .
dockerfile: ./files/release/Dockerfile
environment:
- PROJECT_NAME=social-app-django
- PROJECT_DIR=social_django
env_file:
- ./files/local.env
volumes:
- .:/code

social-tests:
image: omab/social-auth-tests
build:
context: .
dockerfile: ./files/tests/Dockerfile
args:
- PYTHON_VERSIONS=2.7.17 3.5.9 3.6.10 3.7.7 3.8.2 3.9-dev
environment:
- PYTHON_VERSIONS=2.7.17 3.5.9 3.6.10 3.7.7 3.8.2 3.9-dev
volumes:
- .:/code
2 changes: 2 additions & 0 deletions files/local.env.template
@@ -0,0 +1,2 @@
PYPI_USERNAME=
PYPI_PASSWORD=
15 changes: 15 additions & 0 deletions files/release/Dockerfile
@@ -0,0 +1,15 @@
FROM python:3.8.2-slim-buster

RUN apt-get update && \
apt-get install -y --no-install-recommends make gettext git curl && \
pip install -U pip && \
pip install -U setuptools && \
pip install -U twine

COPY ./files/release/pypirc.template /
COPY ./files/release/entrypoint.sh /
ADD . /code

WORKDIR /code

ENTRYPOINT ["/entrypoint.sh"]
42 changes: 42 additions & 0 deletions files/release/entrypoint.sh
@@ -0,0 +1,42 @@
#!/usr/bin/env bash

set -e

if [ -z "${PYPI_USERNAME}" ] || [ -z "${PYPI_PASSWORD}" ]; then
echo "====================================================================="
echo "Error: missing PYPI_USERNAME or PYPI_PASSWORD environment values"
echo "====================================================================="
exit 1;
fi

if [ -z "${PROJECT_DIR}" ] || [ -z "${PROJECT_NAME}" ]; then
echo "====================================================================="
echo "Error: missing PROJECT_DIR or PROJECT_NAME environment values"
echo "====================================================================="
exit 1;
fi

envsubst < /pypirc.template > ~/.pypirc

# This will fail if tag doesn't exist
CURRENT_VERSION=$(head -n1 ${PROJECT_DIR}/__init__.py | awk '{print $3}' | sed 's/[^0-9\.]//g')
CURRENT_TAG=$(git describe --tags --abbrev=0)

if [ "${CURRENT_VERSION}" != "${CURRENT_TAG}" ]; then
echo "====================================================================="
echo "Error: version '${CURRENT_VERSION}' not tagged"
echo "====================================================================="
exit 1;
fi

PYPI_URL="https://pypi.org/project/${PROJECT_NAME}/${CURRENT_VERSION}/"
VERSION_PAGE_STATUS=$(curl -s -I ${PYPI_URL} | head -n1 | awk '{print $2}')

if [ "${VERSION_PAGE_STATUS}" == "200" ]; then
echo "====================================================================="
echo "Error: version '${CURRENT_VERSION}' already exists"
echo "====================================================================="
exit 1;
fi

make clean build publish
7 changes: 7 additions & 0 deletions files/release/pypirc.template
@@ -0,0 +1,7 @@
[distutils]
index-servers =
pypi

[pypi]
username: ${PYPI_USERNAME}
password: ${PYPI_PASSWORD}
22 changes: 22 additions & 0 deletions files/tests/Dockerfile
@@ -0,0 +1,22 @@
FROM python:3.8.2-slim-buster

ARG PYTHON_VERSIONS=${PYTHON_VERSIONS}
ENV PYTHON_VERSIONS=${PYTHON_VERSIONS}

RUN apt-get update && \
apt-get install -y --no-install-recommends \
make git pkg-config ca-certificates wget curl llvm build-essential \
python-openssl libssl-dev zlib1g-dev libbz2-dev libreadline-dev \
libsqlite3-dev libncurses5-dev libncursesw5-dev xz-utils libxml2-dev \
libxmlsec1-dev libffi-dev tk-dev liblzma-dev

COPY ./files/tests/pyenv.sh /
RUN /pyenv.sh

COPY ./files/tests/entrypoint.sh /

ADD . /code

WORKDIR /code

ENTRYPOINT ["/entrypoint.sh"]
10 changes: 10 additions & 0 deletions files/tests/entrypoint.sh
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

set -e

export PATH=~/.pyenv/shims:~/.pyenv/bin:${PATH}
export PYENV_ROOT=~/.pyenv

eval "$(pyenv init -)"

tox
20 changes: 20 additions & 0 deletions files/tests/pyenv.sh
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

set -e

export PATH=~/.pyenv/shims:~/.pyenv/bin:${PATH}
export PYENV_ROOT=~/.pyenv
export PYTHON_VERSIONS=${PYTHON_VERSIONS}

curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash

eval "$(pyenv init -)"

for version in ${PYTHON_VERSIONS}; do
pyenv install "${version}"
pyenv local "${version}"
pip install --upgrade setuptools pip tox
pyenv local --unset
done

pyenv local ${PYTHON_VERSIONS}

0 comments on commit 5af7222

Please sign in to comment.