diff --git a/.ci/docker-compose-ci.yml b/.ci/docker-compose-ci.yml index f28b89dd130..b41c0605207 100644 --- a/.ci/docker-compose-ci.yml +++ b/.ci/docker-compose-ci.yml @@ -10,7 +10,11 @@ services: MYSQL_ROOT_PASSWORD: "password" MYSQL_DATABASE: "ecommerce" ecommerce: - image: edxops/ecommerce:latest + build: + context: ../. + target: dev + args: + PYTHON_VERSION: $PYTHON_VERSION container_name: ecommerce_testing volumes: - ..:/edx/app/ecommerce/ecommerce diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4d11de37d26..4e85bb45b79 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,47 +11,53 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - include: - - django-env: django32 - testname: quality-and-jobs - targets: PYTHON_ENV=py38 requirements.js check_translations_up_to_date validate_translations clean_static static quality validate_js check_keywords - - django-env: django32 - testname: test-python - targets: PYTHON_ENV=py38 requirements.js clean_static static validate_python - - django-env: django32 - testname: acceptance-python - targets: PYTHON_ENV=py38 requirements.js clean_static static acceptance - + python-version: ['py38', 'py311', 'py312'] + django-env: ['django32'] + test: ['quality-and-jobs', 'test-python', acceptance-python] steps: - uses: actions/checkout@v2 + - name: Setup and Format Python Version + id: format_python_version + shell: bash + run: | + # Remove 'py' and insert a dot to format the version + FORMATTED_VERSION=${{ matrix.python-version }} # e.g., py38 + FORMATTED_VERSION=${FORMATTED_VERSION/py3/3.} # becomes 3.8 + + # Set environment variables + echo "PYTHON_VERSION=$FORMATTED_VERSION" >> $GITHUB_ENV + + - name: Check Python Version + run: | + echo "Using Python Version: $PYTHON_VERSION" - name: Start container run: | - docker-compose -f ./.ci/docker-compose-ci.yml up -d + PYTHON_VERSION=$PYTHON_VERSION docker compose -f ./.ci/docker-compose-ci.yml up -d - name: Install dependencies run: | docker exec -t ecommerce_testing bash -c " cd /edx/app/ecommerce/ecommerce/ && - python3 -m pip install tox + python$PYTHON_VERSION -m pip install tox " - name: Run tests run: | docker exec -t -e CI=1 ecommerce_testing bash -c " cd /edx/app/ecommerce/ecommerce/ && PATH=\$PATH:/edx/app/ecommerce/nodeenvs/ecommerce/bin:/snap/bin - DJANGO_ENV=${{ matrix.django-env }} make ${{ matrix.targets }} + DJANGO_ENV=${{ matrix.django-env }} PYTHON_ENV=${{ matrix.python-version }} make ${{ matrix.test }} " - name: Run coverage - if: matrix.testname == 'test-python' + if: matrix.test == 'test-python' run: | docker exec ecommerce_testing /edx/app/ecommerce/ecommerce/.ci/run_coverage.sh - name: Setup Python - if: matrix.testname == 'test-python' + if: matrix.test == 'test-python' && matrix.python-version == 'py38' uses: actions/setup-python@v2 with: python-version: "3.8" architecture: x64 - name: Report coverage - if: matrix.testname == 'test-python' + if: matrix.test == 'test-python' && matrix.python-version == 'py38' uses: codecov/codecov-action@v3 with: flags: unittests @@ -59,11 +65,14 @@ jobs: docs: runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.8', '3.11', '3.12'] steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: - python-version: "3.8" + python-version: ${{matrix.python-version}} architecture: x64 - name: Install Dependencies run: pip install -r requirements/docs.txt -r requirements/tox.txt diff --git a/Dockerfile b/Dockerfile index 8a06c2ad9b3..d121cb11e1f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,22 @@ FROM ubuntu:focal as app +# Define 3.12 as default but it changes to the PYTHON_VERSION passed as argument +ARG PYTHON_VERSION=3.12 + ENV DEBIAN_FRONTEND noninteractive # System requirements. RUN apt update && \ + apt-get install -y software-properties-common && \ + apt-add-repository -y ppa:deadsnakes/ppa && \ apt-get install -qy \ curl \ gettext \ git \ language-pack-en \ build-essential \ - python3.8-dev \ - python3-virtualenv \ - python3.8-distutils \ + python${PYTHON_VERSION} \ + python${PYTHON_VERSION}-dev \ + python${PYTHON_VERSION}-distutils \ libmysqlclient-dev \ libssl-dev \ libcairo2-dev && \ @@ -34,11 +39,15 @@ ARG ECOMMERCE_NODEENV_DIR="${ECOMMERCE_APP_DIR}/nodeenvs/${SERVICE_NAME}" ENV ECOMMERCE_CFG "${COMMON_CFG_DIR}/ecommerce.yml" ENV ECOMMERCE_CODE_DIR "${ECOMMERCE_CODE_DIR}" ENV ECOMMERCE_APP_DIR "${ECOMMERCE_APP_DIR}" +ENV PYTHON_VERSION "${PYTHON_VERSION}" + +RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python${PYTHON_VERSION} +RUN pip install virtualenv # Add virtual env and node env to PATH, in order to activate them ENV PATH "${ECOMMERCE_VENV_DIR}/bin:${ECOMMERCE_NODEENV_DIR}/bin:$PATH" -RUN virtualenv -p python3.8 --always-copy ${ECOMMERCE_VENV_DIR} +RUN virtualenv -p python${PYTHON_VERSION} --always-copy ${ECOMMERCE_VENV_DIR} RUN pip install nodeenv diff --git a/Makefile b/Makefile index bdf5d197510..e5bb4b69e92 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ NODE_BIN=./node_modules/.bin DIFF_COVER_BASE_BRANCH=master -PYTHON_ENV=py38 +PYTHON_ENV=$(if $(PYTHON_ENV),$(PYTHON_ENV),py312) DJANGO_ENV_VAR=$(if $(DJANGO_ENV),$(DJANGO_ENV),django32) help: @@ -173,6 +173,15 @@ upgrade: $(COMMON_CONSTRAINTS_TXT) docs: tox -e docs +quality-and-jobs: + requirements.js check_translations_up_to_date validate_translations clean_static static quality validate_js check_keywords + +test-python: + requirements.js clean_static static validate_python + +acceptance-python: + requirements.js clean_static static acceptance + # Targets in a Makefile which do not produce an output file with the same name as the target name .PHONY: help requirements migrate serve clean validate_python quality validate_js validate html_coverage e2e \ extract_translations dummy_translations compile_translations fake_translations pull_translations \ diff --git a/tox.ini b/tox.ini index c84ff81e9a2..f831eb3d4e1 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] skipsdist=True -envlist = py38-django32-{static,pylint,tests,theme_static,check_keywords},py38-{isort,pycodestyle,extract_translations,dummy_translations,compile_translations, detect_changed_translations,validate_translations},docs +envlist = py{38, 311, 312}-django32-{static,pylint,tests,theme_static,check_keywords},py{38, 311, 312}-{isort,pycodestyle,extract_translations,dummy_translations,compile_translations, detect_changed_translations,validate_translations},docs [pytest] addopts = --ds=ecommerce.settings.test --cov=ecommerce --cov-report term --cov-config=.coveragerc --no-cov-on-fail -p no:randomly --no-migrations -m "not acceptance" @@ -13,6 +13,8 @@ envdir= # Use the same environment for all commands running under a specific python version py35: {toxworkdir}/py35 py38: {toxworkdir}/py38 + py311: {toxworkdir}/py311 + py312: {toxworkdir}/py312 passenv = CONN_MAX_AGE DB_ENGINE