Skip to content

feat: add writable permission handling to folder tree selection #8251

feat: add writable permission handling to folder tree selection

feat: add writable permission handling to folder tree selection #8251

name: API Tests
permissions:
contents: read
on:
pull_request:
branches: [main, develop]
types: [opened, synchronize]
paths:
- "backend/**"
- ".github/workflows/backend-api-tests.yml"
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
GITHUB_WORKFLOW: github_actions
PYTHON_VERSION: "3.14"
UBUNTU_VERSION: "ubuntu-24.04"
BACKEND_DIR: ./backend
jobs:
# JOB 1: Build DB and Cache Deps
setup:
runs-on: ubuntu-24.04
env:
DJANGO_DEBUG: "True"
DB_HOST: localhost
EMAIL_HOST: localhost
EMAIL_PORT: 1025
EMAIL_HOST_USER: ""
EMAIL_HOST_PASSWORD: ""
DEFAULT_FROM_EMAIL: "ciso-assistant@alsigo.net"
CISO_ASSISTANT_SUPERUSER_EMAIL: ""
CISO_ASSISTANT_URL: http://127.0.0.1:5173
strategy:
max-parallel: 4
matrix:
python-version: ["3.14"]
steps:
- uses: actions/checkout@v3
- name: Set up python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: "pip"
- name: Install Poetry
run: |
pipx install poetry
poetry config virtualenvs.in-project true
- name: Cache Virtualenv
id: cache-venv
uses: actions/cache@v4
with:
path: ${{ env.BACKEND_DIR }}/.venv
key: venv-${{ runner.os }}-${{ hashFiles('backend/poetry.lock') }}
- name: Install dependencies
working-directory: ${{ env.BACKEND_DIR }}
run: poetry install
- name: Run migrations
working-directory: ${{ env.BACKEND_DIR }}
run: poetry run python manage.py migrate
- name: Upload Database
uses: actions/upload-artifact@v4
with:
name: prebuilt-db
path: ${{ env.BACKEND_DIR }}/db/ciso-assistant.sqlite3
retention-days: 1
# JOB 2: Generate Matrix
list-files:
runs-on: ubuntu-24.04
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v3
- name: Find Test Files
id: set-matrix
working-directory: ${{ env.BACKEND_DIR }}
run: |
FILES=$(find app_tests/api -name "test_*.py" ! -name "test_utils.py" | sort | jq -R -s -c 'split("\n")[:-1]')
echo "matrix=$FILES" >> $GITHUB_OUTPUT
# JOB 3: Run Parallel Tests
test:
needs: [setup, list-files]
runs-on: ubuntu-24.04
strategy:
fail-fast: false
max-parallel: 8
matrix:
test-file: ${{ fromJson(needs.list-files.outputs.matrix) }}
env:
DJANGO_DEBUG: "True"
DB_HOST: localhost
EMAIL_HOST: localhost
EMAIL_PORT: 1025
EMAIL_HOST_USER: ""
EMAIL_HOST_PASSWORD: ""
DEFAULT_FROM_EMAIL: "ciso-assistant@alsigo.net"
CISO_ASSISTANT_SUPERUSER_EMAIL: ""
CISO_ASSISTANT_URL: http://127.0.0.1:5173
steps:
- uses: actions/checkout@v3
- name: Set up python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: "pip"
- name: Install Poetry
run: |
pipx install poetry
poetry config virtualenvs.in-project true
# Restore the exact venv created in 'setup' job to skip installation
- name: Restore Virtualenv Cache
uses: actions/cache@v4
id: cache-venv
with:
path: ${{ env.BACKEND_DIR }}/.venv
key: venv-${{ runner.os }}-${{ hashFiles('backend/poetry.lock') }}
- name: Install dependencies
working-directory: ${{ env.BACKEND_DIR }}
run: poetry install
- name: Download Database
uses: actions/download-artifact@v4
with:
name: prebuilt-db
path: ${{ env.BACKEND_DIR }}/db/
- name: Prepare Test Database
working-directory: ${{ env.BACKEND_DIR }}
run: |
# Copy pre-built DB to the name defined in settings.py TEST config
cp db/ciso-assistant.sqlite3 db/test_ciso-assistant.sqlite3
- name: Run Test File
working-directory: ${{ env.BACKEND_DIR }}
env:
TEST_FILE: ${{ matrix.test-file }}
JOB_INDEX: ${{ strategy.job-index }}
run: |
# Use --reuse-db to prevent pytest from destroying/recreating the DB
poetry run pytest "$TEST_FILE" --reuse-db --html="pytest-report-${JOB_INDEX}.html" --self-contained-html
- name: Prepare Artifact Name
if: ${{ !cancelled() }}
env:
RAW_BRANCH: ${{ env.BRANCH_NAME }}
run: |
set -euo pipefail
SAFE_BRANCH=$(echo "$RAW_BRANCH" | sed -E 's/[^a-zA-Z0-9_-]/_/g')
echo "BRANCH_SANITIZED=$SAFE_BRANCH" >> "$GITHUB_ENV"
echo "NOW=$(date +'%Y-%m-%dT%H-%M-%S')" >> "$GITHUB_ENV"
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: ${{ env.BRANCH_SANITIZED }}-${{ env.NOW }}-report-${{ strategy.job-index }}
path: ${{ env.BACKEND_DIR }}/pytest-report-${{ strategy.job-index }}.html
retention-days: 5