1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
#############################
## GitHub Actions CI Tests ##
#############################
#
# This is a reusable workflow to make CI tests more modular.
# See: https://docs.github.com/en/actions/using-workflows/reusing-workflows
#
# Called by ci-tests.yml
# This one does the python tests
#
name: Modular SQLFluff python test workflow
on:
workflow_call:
inputs:
python-version:
required: true
type: string
marks:
required: false
type: string
default: "not integration"
coverage:
required: false
type: boolean
default: false
secrets:
gh_token:
required: true
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.python-version }}-${{ inputs.marks }}-${{ inputs.coverage }}
cancel-in-progress: true
jobs:
modular-python-test:
runs-on: ubuntu-latest
name: py${{ inputs.python-version }}
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
cache: 'pip'
cache-dependency-path: |
setup.cfg
requirements_dev.txt
- name: Install dependencies
run: pip install tox
- name: Parse Python Version
id: py_version
run: |
PYVERSION=$(echo "${{ inputs.python-version }}" | sed -e 's/\.//g')
echo "PYVERSION=$PYVERSION" >> $GITHUB_OUTPUT
# Run test process (with or without coverage).
# Arguments after the "--" are passed through to pytest:
# --cov=... The library to include in coverage reporting.
# -n 2 Runs with two parallel processes.
# test The path to detect tests within.
# -m ... The pytest marks to filter tests.
# --durations=16 Displays the 16 slowest runs to help with performance debugging.
- name: Run the tests (with coverage)
# NOTE: We have a separate job for coverage reporting because
# it impacts performance and slows the test suite significantly.
if: ${{ inputs.coverage }}
run: tox -e py${{ steps.py_version.outputs.PYVERSION }} -- --cov=sqlfluff -n 2 test -m "${{ inputs.marks }}" --durations=16 --verbosity=0
- name: Run the tests (without coverage)
if: ${{ !inputs.coverage }}
run: tox -e py${{ steps.py_version.outputs.PYVERSION }} -- -n 2 test -m "${{ inputs.marks }}" --durations=16 --verbosity=0
- name: Rename coverage files with suffix
# NOTE: We do this because we're using the same tox environment for multiple
# test jobs and we need to make sure that their coverage files don't collide.s
id: cov_suffix
if: ${{ inputs.coverage }}
run: |
COVSUFFIX=$(echo "${{ inputs.marks }}" | sed -e 's/ /-/g')
echo "COVSUFFIX=$COVSUFFIX" >> $GITHUB_OUTPUT
for file in .coverage.*; do mv "$file" "$file.$COVSUFFIX"; done;
- name: Upload coverage data (github)
uses: actions/upload-artifact@v4
if: ${{ inputs.coverage }}
with:
name: coverage-data-py${{ inputs.python-version }}-${{ inputs.marks }}
path: ".coverage.*"
if-no-files-found: ignore
include-hidden-files: true
|