diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ee4a2cd7..7ae67c73 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,101 +1,97 @@ name: Server Tests + on: - push: - branches: - - main - pull_request: {} + push: + branches: + - main + pull_request: {} + jobs: - tests: - runs-on: ubuntu-latest - services: - redis-cache: - image: redis:alpine - ports: - - 13000:6379 - redis-queue: - image: redis:alpine - ports: - - 11000:6379 - redis-socketio: - image: redis:alpine - ports: - - 12000:6379 - mariadb: - image: mariadb:10.6 - env: - MYSQL_ROOT_PASSWORD: "root" - COLLATION_SERVER: "utf8mb4_unicode_ci" - ports: - - 3306:3306 - options: --health-cmd="mariadb-admin ping" --health-interval=5s --health-timeout=2s --health-retries=3 + tests: + runs-on: ubuntu-latest + services: + redis-cache: + image: redis:alpine + ports: + - 13000:6379 + redis-queue: + image: redis:alpine + ports: + - 11000:6379 + redis-socketio: + image: redis:alpine + ports: + - 12000:6379 + mariadb: + image: mariadb:10.6 + ports: + - 3306:3306 + env: + MARIADB_ROOT_PASSWORD: root + MARIADB_CHARACTER_SET: utf8mb4 + MARIADB_COLLATION_SERVER: utf8mb4_unicode_ci + options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3 + steps: + - name: Checkout code + uses: actions/checkout@v2 - steps: - - name: Clone - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.11' - - name: Setup Python - uses: actions/setup-python@v4 - with: - python-version: "3.11" + - name: Set up Node + uses: actions/setup-node@v2 + with: + node-version: 18 + check-latest: true - - name: Check for valid Python & Merge Conflicts - run: | - python -m compileall -q -f "${GITHUB_WORKSPACE}" - if grep -lr --exclude-dir=node_modules "^<<<<<<< " "${GITHUB_WORKSPACE}" - then echo "Found merge conflicts" - exit 1 - fi + - name: Cache Bench + uses: actions/cache@v2 + with: + path: ~/bench-cache + key: ${{ runner.os }} - - name: Setup Node - uses: actions/setup-node@v3 - with: - node-version: 18 - check-latest: true + - name: Install Bench + run: | + pip3 install frappe-bench + which bench - - name: Add to Hosts - run: | - echo "127.0.0.1 lms.test" | sudo tee -a /etc/hosts + - name: Initialize Bench + run: | + if [ -d ~/bench-cache/bench.tgz ] + then + (cd && tar xzf ~/bench-cache/bench.tgz) + else + bench init ~/frappe-bench --skip-redis-config-generation --skip-assets --python "$(which python)" + mkdir -p ~/bench-cache + (cd && tar czf ~/bench-cache/bench.tgz frappe-bench) + fi - - name: Cache pip - uses: actions/cache@v3 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/*requirements.txt', '**/pyproject.toml', '**/setup.py') }} - restore-keys: | - ${{ runner.os }}-pip- - ${{ runner.os }}- + - name: Add LMS App + working-directory: /home/runner/frappe-bench + run: bench get-app lms $GITHUB_WORKSPACE - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT + - name: Create Bench Site + working-directory: /home/runner/frappe-bench + run: bench new-site --mariadb-root-password root --admin-password admin frappe.local - - uses: actions/cache@v3 - id: yarn-cache - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- + - name: Install LMS App + working-directory: /home/runner/frappe-bench + run: bench --site frappe.local install-app lms - - name: Install Dependencies - run: | - bash ${GITHUB_WORKSPACE}/.github/helper/install_dependencies.sh - bash ${GITHUB_WORKSPACE}/.github/helper/install.sh - env: - BEFORE: ${{ env.GITHUB_EVENT_PATH.before }} - AFTER: ${{ env.GITHUB_EVENT_PATH.after }} - TYPE: server - DB: ${{ matrix.db }} + - name: Setup Requirements + working-directory: /home/runner/frappe-bench + run: bench setup requirements --dev - - name: Run Tests - run: cd ~/frappe-bench/ && bench --site lms.test run-parallel-tests --app lms --total-builds 4 --build-number ${{ matrix.container }} - env: - SITE: lms.test - CI_BUILD_ID: ${{ github.run_id }} - BUILD_NUMBER: ${{ matrix.container }} - TOTAL_BUILDS: 2 + - name: Allow Tests + working-directory: /home/runner/frappe-bench + run: bench --site frappe.local set-config allow_tests true - - name: Show bench output - if: ${{ always() }} - run: cat ~/frappe-bench/bench_start.log || true + - name: Build + working-directory: /home/runner/frappe-bench + run: bench --site frappe.local build + - name: Run Tests + working-directory: /home/runner/frappe-bench + run: bench --site frappe.local run-tests --app lms