Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
build: add python 3.11 and python 3.12 ci checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Danyal-Faheem committed May 3, 2024
1 parent fe47e90 commit 7caffb5
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 25 deletions.
6 changes: 5 additions & 1 deletion .ci/docker-compose-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 27 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,59 +11,68 @@ 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
fail_ci_if_error: false

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
Expand Down
17 changes: 13 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 && \
Expand All @@ -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

Expand Down
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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 \
Expand Down
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand Down

0 comments on commit 7caffb5

Please sign in to comment.