Skip to content

Merge branch 'bedpres_leaderboard' of github.com:Nabla-NTNU/nablaweb … #758

Merge branch 'bedpres_leaderboard' of github.com:Nabla-NTNU/nablaweb …

Merge branch 'bedpres_leaderboard' of github.com:Nabla-NTNU/nablaweb … #758

Workflow file for this run

name: Python testing
on: [push, workflow_dispatch]
jobs:
test:
env:
# Have the venv be in the project folder so it is easier to cache
PIPENV_VENV_IN_PROJECT: true
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
python_version: [3.9]
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python_version }}
- name: Install pipenv
run: |
python -m pip install --upgrade pip
pip install pipenv
# Cache the venv between runs. Duplicated from linting.yaml
- name: Cache virtualenv
id: cache-venv
uses: actions/cache@v3
env:
CACHE_NAME: CACHE_VIRTUALENV
with:
path: .venv
# The cache action does not as of now (Oct. 2020) support clearing the cache.
# If the cache becomes stale for any reason one can clear it by changing
# the value of the secret `PIPENV_CACHE_VERSION` in the repository settings
key: >
cache_version_${{ secrets.PIPENV_CACHE_VERSION}}-${{ runner.os }}-${{ env.CACHE_NAME }}-python${{ matrix.python_version }}-${{ hashFiles('Pipfile.lock') }}
# Fallbacks to partially restore cache
restore-keys: |
cache_version_${{ secrets.PIPENV_CACHE_VERSION}}-${{ runner.os }}-${{ env.CACHE_NAME }}-python${{ matrix.python_version }}-
- name: Install dependencies
if: steps.cache-venv.outputs.cache-hit != 'true'
run: |
# Use copies instead of symlinks to be more portable
python -m venv --copies .venv
# Install dependencies into the newly created venv
pipenv install --deploy --dev
- name: Allow reading and writing PDFs (linux only)
# Edit imagemagick's policy file to allow reading and writing PDFs
# This is needed to create Nablad instances, which is done during testing
# Also install ghostscript, which imagemagick uses to read/write PDFs
if: runner.os == 'Linux'
run: |
configure_path=$(convert -list configure | sed -n -e 's/CONFIGURE_PATH[[:space:]]*//p' || true)
temp_file="$(sudo mktemp)"
# sed -i is a gnu extension. Beware
sudo sed -i -e 's/<policy domain="coder" rights=".*" pattern="PDF" \/>/<policy domain="coder" rights="read | write" pattern="PDF" \/>/w '"$temp_file" "$configure_path/policy.xml"
if [ ! -s "$temp_file" ]; then
echo 'Failed to edit policy file to allow reading/writing PDFs!'
echo 'Below are the contents of `policy.xml`'
echo 'For PDF processing to work it should be edited to have a line like:'
echo ' "<policy domain="coder" rights="read | write" pattern="PDF" \/>"'
echo
cat "$configure_path/policy.xml"
exit 1
fi
sudo apt-get update
sudo apt-get install ghostscript
- name: Exclude tests that need ImageMagick (non-linux)
# ImageMagick does not come pre-installed on mac- and windows runners, so we skip
# tests that need it on those hosts. This is done by excluding a specific test tag,
# which is set on the test that needs ImageMagick
if: runner.os != 'Linux'
run: |
echo 'exclude_tag=needs_imagemagick' >> $GITHUB_ENV
- name: Run tests
# Tests are run in parallel, which may cause issues if the tests aren't propertly isolated
run: |
pipenv run python manage.py test --parallel --exclude-tag="$exclude_tag"