Skip to content

Add various tests

Add various tests #482

Workflow file for this run

name: Inyoka CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-24.04
env:
DEFAULT_BRANCH: 'refs/heads/staging'
REQUIREMENTS_FILE: extra/requirements/linux-py${{ matrix.python-version }}-development.txt
strategy:
matrix:
python-version: ['3.12']
database: ['postgresql', 'sqlite']
theme: ['', 'theme-ubuntuusers']
include:
- python-version: 3.12
database: 'postgresql'
theme: ''
build_docs: true
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
# - name: Dump github.event.pull_request context
# env:
# GITHUB_CONTEXT: ${{ toJSON(github.event.pull_request) }}
# run: echo "$GITHUB_CONTEXT"
- name: Checkout theme from repo branch # (e.g. staging)
id: checkout-branch
continue-on-error: true
if: ${{ !github.event.pull_request && matrix.theme != '' }}
uses: actions/checkout@v4
with:
repository: inyokaproject/${{ matrix.theme }}
ref: ${{ github.ref }}
path: ${{ matrix.theme }}
persist-credentials: false
- name: Checkout theme in PR
id: checkout-pr
continue-on-error: true
if: ${{ github.event.pull_request && matrix.theme != '' }}
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.owner.login }}/${{ matrix.theme }}
ref: ${{ github.head_ref }}
path: ${{ matrix.theme }}
persist-credentials: false
- name: "Checkout fallback theme: repo theme-ubuntuusers, staging branch"
if: ${{ matrix.theme != '' && (steps.checkout-branch.outcome == 'failure' || steps.checkout-pr.outcome == 'failure') }}
uses: actions/checkout@v4
with:
repository: inyokaproject/${{ matrix.theme }}
ref: staging
path: ${{ matrix.theme }}
persist-credentials: false
# if theme == '', the default theme inside inyoka is used
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: 'extra/requirements/*.txt'
- name: Build virtualenv
run: |
python -m venv ~/venv
. ~/venv/bin/activate
python -m pip install --upgrade pip
pip install --no-deps --require-hashes -r ${{ env.REQUIREMENTS_FILE }}
- name: Build static files
run: |
npm ci
npm run all
- name: Link theme
working-directory: ./${{ matrix.theme }}
if: ${{ matrix.theme != '' }}
run: |
. ~/venv/bin/activate
pip install -e .
- name: Build static files theme
working-directory: ./${{ matrix.theme }}
if: ${{ matrix.theme != '' }}
run: |
npm ci
npm run all
- name: Start postgres
if: ${{ matrix.database == 'postgresql' }}
run: |
cat << '__EOF__' | sudo tee /etc/postgresql/16/main/pg_hba.conf > /dev/null
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
__EOF__
sudo systemctl start postgresql.service
pg_isready
- name: Install redis (server and cli)
run: |
sudo apt-get install redis-server
- name: Check for missing migrations (postgresql)
if: ${{ matrix.database == 'postgresql' }}
run: |
. ~/venv/bin/activate
python manage.py makemigrations --check --dry-run --settings tests.settings.${{ matrix.database }}_staticdbname
- name: Check for missing migrations (no postgresql)
if: ${{ matrix.database != 'postgresql' }}
run: |
. ~/venv/bin/activate
python manage.py makemigrations --check --dry-run --settings tests.settings.${{ matrix.database }}
- name: Run Tests
env:
PYTHONWARNINGS: 'always'
INYOKA_THEME: ${{ matrix.theme }}
run: |
. ~/venv/bin/activate
coverage run manage.py test --settings tests.settings.${{ matrix.database }}
coverage html
- name: Save coverage report for tests
uses: actions/upload-artifact@v4
with:
name: coverage-py${{ matrix.python-version }}-${{ matrix.database }}-${{ matrix.theme }}
path: htmlcov
- name: Run BDD tests
if: ${{ matrix.database == 'postgresql' }}
env:
DJANGO_SETTINGS_MODULE: 'tests.bdd.settings.headless'
INYOKA_THEME: ${{ matrix.theme }}
COVERAGE_RCFILE: 'tests/bdd/settings/.coveragerc'
run: |
. ~/venv/bin/activate
cat << '__EOF__' | sudo tee -a /etc/hosts > /dev/null
127.0.0.1 ubuntuusers.local forum.ubuntuusers.local paste.ubuntuusers.local wiki.ubuntuusers.local planet.ubuntuusers.local ikhaya.ubuntuusers.local static.ubuntuusers.local media.ubuntuusers.local
__EOF__
python manage.py collectstatic --noinput
coverage run -m behave --tags=-skip
coverage html -d bdd_coverage
- name: Save BDD results
if: ${{ matrix.database == 'postgresql' }}
uses: actions/upload-artifact@v4
with:
name: BDD-coverage-py${{ matrix.python-version }}-${{ matrix.database }}-${{ matrix.theme }}
path: bdd_coverage
- name: Build documentation
if: ${{ matrix.build_docs }}
env:
DJANGO_SETTINGS_MODULE: tests.settings.${{ matrix.database }}
INYOKA_THEME: ${{ matrix.theme }}
run: |
. ~/venv/bin/activate
make -C docs html
- name: Save documentation
if: ${{ matrix.build_docs }}
uses: actions/upload-artifact@v4
with:
name: 'Inyoka_Documentation'
path: docs/build/html
- name: Lint
run: |
. ~/venv/bin/activate
ruff check
- name: Save statics
if: ${{ startsWith(github.ref, 'refs/tags/') && matrix.build_docs }}
uses: actions/upload-artifact@v4
with:
name: 'Static_files'
path: inyoka/static-collected
# Deploy documentation to GitHub Pages
deploy_docu:
if: github.ref_name == 'staging'
needs: test
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
pages: write
id-token: write
actions: read
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Download documentation artifact from previous job
uses: actions/download-artifact@v4
with:
name: 'Inyoka_Documentation'
path: 'docs'
- name: Upload artifact for GitHub pages
uses: actions/upload-pages-artifact@v3
with:
path: 'docs'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4