Skip to content

Commit

Permalink
Merge pull request #1061 from afuetterer/e2e-tests
Browse files Browse the repository at this point in the history
refactor: improve e2e test performance
  • Loading branch information
MyPyDavid authored Aug 8, 2024
2 parents 817d513 + 15ddb5e commit 4937a40
Show file tree
Hide file tree
Showing 8 changed files with 240 additions and 211 deletions.
217 changes: 126 additions & 91 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,47 +38,111 @@ jobs:
# Ref: https://github.com/rdmorganiser/.github/blob/main/.github/workflows/_lint.yml
uses: rdmorganiser/.github/.github/workflows/_lint.yml@main

build-wheel:
name: Build python wheel
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
# update the version
- name: Get short commit SHA
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
SHA="${{ github.event.pull_request.head.sha }}"
else
SHA="${{ github.sha }}"
fi
echo "SHA=$(git rev-parse --short $SHA)" >> $GITHUB_ENV
- name: Get current version (MAJOR.MINOR.PATCH)
id: current-version
run: echo "current_version=$(grep -Po '(?<=__version__ = ")[\d\w.]+(?=")' rdmo/__init__.py)" >> $GITHUB_OUTPUT
- name: Generate new version (current version + SHA)
id: new-version
run: echo "new_version=${{ steps.current-version.outputs.current_version }}+$SHA" >> $GITHUB_OUTPUT
- name: Update version in rdmo/__init__.py
run: |
sed -i "s/__version__ = .*/__version__ = \"${{ steps.new-version.outputs.new_version }}\"/" rdmo/__init__.py
# build the webpack bundle
- uses: actions/setup-node@v4
with:
node-version: 18
cache: npm
- run: npm install && npm run build:prod
# build the wheel
- uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: pip
- run: |
python -m pip install --upgrade pip build[uv] twine
python -m pip --version
- name: Build the wheel
run: python -m build --installer=uv
- name: Check the metadata of wheel and sdist
run: python -m twine check --strict dist/*
- name: Install package from built wheel
run: python -m pip install --no-compile dist/rdmo*.whl # do not create __pycache__/*.pyc files
- name: Write info to step summary
run: |
{
echo -e "# ✓ Wheel successfully built (v${{ steps.new-version.outputs.new_version }})\n\n"
echo '<details><summary>Information about installed wheel</summary>'
echo -e "\n\`\`\`console"
echo "$ python -m pip show --files --verbose rdmo"
python -m pip show --files --verbose rdmo
echo -e "\`\`\`\n</details>"
} >> $GITHUB_STEP_SUMMARY
- name: Upload wheel as artifact
uses: actions/upload-artifact@v4
with:
name: wheel
path: dist/rdmo*.whl
if-no-files-found: error
retention-days: 30

test:
name: "Test (Python: ${{ matrix.python-version }}, DB: ${{ matrix.db-backend }})"
needs: build-wheel
runs-on: ubuntu-24.04
strategy:
matrix:
python-version: ['3.8', '3.12']
db-backend: [mysql, postgres]
name: "Test (Python: ${{ matrix.python-version }}, DB: ${{ matrix.db-backend }})"
needs: lint
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip
- name: Download wheel
uses: actions/download-artifact@v4
with:
name: wheel
path: dist
- name: Install Dependencies
run: |
sudo apt update
sudo apt install --yes pandoc texlive-xetex librsvg2-bin
python -m pip install --upgrade pip
sudo apt-get update && sudo apt-get install --yes pandoc texlive-xetex librsvg2-bin
pandoc --version
- name: Install rdmo[mysql] and start mysql
python -m pip install --upgrade pip
python -m pip --version
- name: Install rdmo[mysql] from wheel and start mysql
run: |
python -m pip install --editable .[ci,mysql]
python -m pip install "$(ls dist/*.whl)[ci,mysql]"
sudo systemctl start mysql.service
if: matrix.db-backend == 'mysql'
- name: Install rdmo[postgres] and start postgresql
- name: Install rdmo[postgres] from wheel and start postgresql
run: |
python -m pip install --editable .[ci,postgres]
python -m pip install "$(ls dist/*.whl)[ci,postgres]"
sudo systemctl start postgresql.service
pg_isready
sudo -u postgres psql --command="CREATE USER postgres_user PASSWORD 'postgres_password' CREATEDB"
if: matrix.db-backend == 'postgres'
- name: Prepare Env
run: |
cp -r testing/media testing/media_root
mkdir testing/log
cp -r testing/media testing/media_root && mkdir testing/log
- name: Run package status tests first
run: |
pytest rdmo/core/tests/test_package_status.py::test_package_json_and_pre_commit_versions_match \
--nomigrations --verbose
pytest rdmo/core/tests/test_package_status.py --nomigrations --verbose
if: matrix.python-version == '3.12' && matrix.db-backend == 'postgres'
- name: Run Tests
run: |
Expand All @@ -90,30 +154,55 @@ jobs:
with:
flag-name: '${{ matrix.db-backend }}: ${{ matrix.python-version }}'
parallel: true
# end-to-end tests
- uses: actions/setup-node@v4

test-e2e:
name: "End-to-end Test (Python: ${{ matrix.python-version }}, DB: ${{ matrix.db-backend }})"
needs: build-wheel
runs-on: ubuntu-24.04
strategy:
matrix:
python-version: ['3.12']
db-backend: [postgres]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
node-version: 18
cache: npm
if: matrix.python-version == '3.12' && matrix.db-backend == 'postgres'
python-version: ${{ matrix.python-version }}
cache: pip
- name: Download wheel
uses: actions/download-artifact@v4
with:
name: wheel
path: dist
- name: Install Dependencies
run: |
sudo apt-get update && sudo apt install --yes pandoc texlive-xetex librsvg2-bin
python -m pip install --upgrade pip
- name: Install rdmo[postgres] from wheel and start postgresql
run: |
python -m pip install "$(ls dist/*.whl)[ci,postgres]"
sudo systemctl start postgresql.service
pg_isready
sudo -u postgres psql --command="CREATE USER postgres_user PASSWORD 'postgres_password' CREATEDB"
- name: Prepare Env
run: |
cp -r testing/media testing/media_root && mkdir testing/log
- name: Install e2e tests dependencies
run: |
npm install
npm run build:prod
playwright install chromium
if: matrix.python-version == '3.12' && matrix.db-backend == 'postgres'
playwright install --with-deps chromium
- run: mkdir screenshots
- name: Collect static files into static root (only required if rdmo is installed from wheel)
run: python testing/manage.py collectstatic --noinput
- name: Run end-to-end tests
run: pytest -p randomly -p no:cacheprovider --reuse-db --numprocesses=auto --dist=loadscope -m e2e --nomigrations
if: matrix.python-version == '3.12' && matrix.db-backend == 'postgres'
env:
DJANGO_DEBUG: True
GITHUB_DB_BACKEND: ${{ matrix.db-backend }}
- uses: actions/upload-artifact@v4
with:
name: screenshots
path: screenshots/*.png
if: matrix.python-version == '3.12' && matrix.db-backend == 'postgres'

coveralls:
name: Indicate completion to coveralls
Expand All @@ -126,68 +215,6 @@ jobs:
with:
parallel-finished: true

build-wheel:
name: Build python wheel
needs: test
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
# update the version
- name: Get short commit SHA
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
SHA="${{ github.event.pull_request.head.sha }}"
else
SHA="${{ github.sha }}"
fi
echo "SHA=$(git rev-parse --short $SHA)" >> $GITHUB_ENV
- name: Get current version (MAJOR.MINOR.PATCH)
id: current-version
run: echo "current_version=$(grep -Po '(?<=__version__ = ")[\d\w.]+(?=")' rdmo/__init__.py)" >> $GITHUB_OUTPUT
- name: Generate new version (current version + SHA)
id: new-version
run: echo "new_version=${{ steps.current-version.outputs.current_version }}+$SHA" >> $GITHUB_OUTPUT
- name: Update version in rdmo/__init__.py
run: |
sed -i "s/__version__ = .*/__version__ = \"${{ steps.new-version.outputs.new_version }}\"/" rdmo/__init__.py
# build the webpack bundle
- uses: actions/setup-node@v4
with:
node-version: 18
cache: npm
- run: npm install && npm run build:prod
# build the wheel
- uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: pip
- run: |
python -m pip install --upgrade pip build[uv] twine
pip --version
- name: Build the wheel
run: python -m build --installer=uv
- name: Check the metadata of wheel and sdist
run: python -m twine check --strict dist/*
- name: Install package from built wheel
run: python -m pip install --no-compile dist/rdmo*.whl # do not create __pycache__/*.pyc files
- name: Write info to step summary
run: |
{
echo -e "# ✓ Wheel successfully built (v${{ steps.new-version.outputs.new_version }})\n\n"
echo '<details><summary>Information about installed wheel</summary>'
echo -e "\n\`\`\`console"
echo "$ python -m pip show --files --verbose rdmo"
python -m pip show --files --verbose rdmo
echo -e "\`\`\`\n</details>"
} >> $GITHUB_STEP_SUMMARY
- name: Upload wheel as artifact
uses: actions/upload-artifact@v4
with:
name: wheel
path: dist/rdmo*.whl
if-no-files-found: error
retention-days: 30

dev-setup:
# Ref: structlog (MIT licensed) <https://github.com/hynek/structlog/blob/main/.github/workflows/ci.yml>
name: "Test dev setup on ${{ matrix.os }}"
Expand All @@ -206,19 +233,26 @@ jobs:

dependencies:
name: Test installation of all dependencies
needs: build-wheel
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
- name: Download wheel
uses: actions/download-artifact@v4
with:
name: wheel
path: dist
- name: Install os requirements for python-ldap
run: |
sudo apt update
sudo apt install --yes libldap2-dev libsasl2-dev
run: sudo apt-get update && sudo apt-get install --yes libldap2-dev libsasl2-dev
- run: python -m pip install --upgrade pip
- run: python -m pip install .[allauth,ci,dev,gunicorn,ldap,mysql,postgres,pytest]
- name: Install rdmo wheel with all optional dependency groups
run: python -m pip install --no-compile "$(ls dist/*.whl)[allauth,ci,dev,gunicorn,ldap,mysql,postgres,pytest]"
- name: Verify installed packages have compatible dependencies
run: python -m pip check
- uses: actions/setup-node@v4
with:
node-version: 18
Expand Down Expand Up @@ -254,9 +288,10 @@ jobs:
if: always()
needs:
- lint
- build-wheel
- test
- coveralls
- build-wheel
- test-e2e
- dev-setup
- dependencies
runs-on: ubuntu-24.04
Expand Down
49 changes: 0 additions & 49 deletions rdmo/management/tests/conftest.py

This file was deleted.

Empty file.
Loading

0 comments on commit 4937a40

Please sign in to comment.