Skip to content

add jobs for testing strategy branches #4

add jobs for testing strategy branches

add jobs for testing strategy branches #4

# 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:
################################################################################
## FILE CHANGE CHECKERS ##
## ##
## These jobs check which files have changed so that we can call appropriate ##
## testing, auditing, and linting jobs. Jobs in this section should check for ##
## file changes that would indicate whether we need to run some particular ##
## test suite, then they should output 'true' if such file changes are found. ##
## ##
################################################################################
python_tests_required:
name: Check for file changes requiring python tests
runs-on: ubuntu-latest
outputs:
tests_should_run: ${{ 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/**
python_lint_required:
name: Check for file changes requiring python linter
runs-on: ubuntu-latest
outputs:
lint_should_run: ${{ 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:
name: Check for file changes requiring SQL tests
runs-on: ubuntu-latest
outputs:
tests_should_run: ${{ 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'
################################################################################
## TEST/LINT RUNNERS ##
## ##
## These jobs run tests and linters. Each job in this section should be ##
## dependent on one of the FILE CHANGE CHECKERS above, and should only run if ##
## appropriate files have changed. You can see this by using a `needs:` block ##
## to make the job dependent on the relevant file checker, and an `if:` block ##
## to ensure that the file checker returned 'true' before running the actual ##
## job. Job IDs in this section must be namespaced (so `python_tests` ##
## instead of just `tests`). ##
## ##
################################################################################
python_tests:
name: Run Python tests
runs-on: ubuntu-latest
needs: python_tests_required
if: needs.python_tests_required.outputs.tests_should_run == '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
needs: sql_tests_required
if: needs.sql_tests_required.outputs.tests_should_run == '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 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: python_lint_required
if: needs.python_lint_required.outputs.lint_should_run == '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 }}
vulture:
name: Find unused code
runs-on: ubuntu-latest
needs: python_lint_required
if: needs.python_lint_required.outputs.lint_should_run == 'true'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- name: Install Vulture
run: pip3 install vulture
- name: Run Vulture
run: vulture .
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!"