Skip to content

add jobs for testing strategy branches #3

add jobs for testing strategy branches

add jobs for testing strategy branches #3

# Since we're using both the "require pull request" and "require merge queue"
# requirements for develop and master branches, there's no reason to run tests
# on every push. Instead, we're using the recommended "merge_group" formulation
# that runs status checks and reports them whenever a PR is added to the merge
# queue.
name: Backend tests and linting
on: [pull_request, merge_group]
jobs:
pytest_required_check:
runs-on: ubuntu-latest
# Here, we capture whether any files have changed to indicate we need to run
# python tests
outputs:
any_changed: ${{ steps.changed_files.outputs.any_changed }}
steps:
- uses: actions/checkout@v4
- name: Get changed files
id: changed_files
uses: tj-actions/changed-files@v39
with:
files: |
*.py
mathesar/**
db/**
flake8_required_check:
runs-on: ubuntu-latest
# Here, we capture whether any files have changed to indicate we need to run
# python linter
outputs:
any_changed: ${{ steps.changed_files.outputs.any_changed }}
steps:
- uses: actions/checkout@v4
- name: Get changed files
id: changed_files
uses: tj-actions/changed-files@v39
with:
files: '**.py'
sql_tests_required_check:
runs-on: ubuntu-latest
# Here, we capture whether any files have changed to indicate we need to run
# SQL tests
outputs:
any_changed: ${{ steps.changed_files.outputs.any_changed }}
steps:
- uses: actions/checkout@v4
- name: Get changed files
id: changed_files
uses: tj-actions/changed-files@v39
with:
files: '**.sql'
python_tests:
name: Run Python tests
runs-on: ubuntu-latest
needs: pytest_required_check
if: needs.pytest_required_check.outputs.any_changed == 'true'
strategy:
matrix:
pg-version: [13, 14, 15]
steps:
- uses: actions/checkout@v4
- name: Copy env file
run: cp .env.example .env
# The code is checked out under uid 1001 - reset this to 1000 for the
# container to run tests successfully
- name: Fix permissions
run: sudo chown -R 1000:1000 .
- name: Build the stack
run: docker compose -f docker-compose.yml -f docker-compose.dev.yml up --build -d test-service
env:
PG_VERSION: ${{ matrix.pg-version }}
- name: Run tests with pytest
run: docker exec mathesar_service_test ./run_pytest.sh
sql_tests:
name: Run SQL tests
runs-on: ubuntu-latest
if: needs.sql_tests_required_check.outputs.any_changed == 'true'
strategy:
matrix:
pg-version: [13, 14, 15]
steps:
- uses: actions/checkout@v4
- name: Copy env file
run: cp .env.example .env
- name: Fix permissions
run: sudo chown -R 1000:1000 .
- name: Build the test DB
run: docker compose -f docker-compose.yml -f docker-compose.dev.yml up --build -d dev-db
env:
PG_VERSION: ${{ matrix.pg-version }}
- name: Run tests with pg_prove
run: docker exec mathesar_dev_db /bin/bash /sql/run_tests.sh
python_lint:
name: Run Python linter
runs-on: ubuntu-latest
needs: flake8_required_check
if: needs.flake8_required_check.outputs.any_changed == 'true'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- name: Run flake8
uses: julianwachholz/flake8-action@main
with:
checkName: "flake8"
path: "."
plugins: flake8-no-types
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tests:
runs-on: ubuntu-latest
needs: [python_tests, sql_tests]
steps:
- name: Report success
run: echo "Backend tests succeeded or skipped!"
lint:
runs-on: ubuntu-latest
needs: python_lint
steps:
- name: Report success
run: echo "Python linter succeeded or skipped!"