Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Run only API tests affected by changes in PRs and Upgrade GHA runners #2867

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions .github/workflows/api-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ on:
- .github/**
branches:
- main
merge_group:
types: [checks_requested]

defaults:
run:
working-directory: api

jobs:
test:
runs-on: ubuntu-latest
runs-on: General-Purpose-8c-Runner
name: API Unit Tests

services:
Expand All @@ -33,7 +35,7 @@ jobs:
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

strategy:
max-parallel: 4
max-parallel: 2
matrix:
python-version: ['3.10', '3.11']

Expand Down Expand Up @@ -66,11 +68,31 @@ jobs:
opts: --no-input --dry-run --check
run: make django-make-migrations

- name: Restore cached testmon data
if: ${{ github.event_name == 'pull_request' }}
id: cache-testmon-restore
uses: actions/cache/restore@v3
with:
enableCrossOsArchive: true
path: |
/home/runner/work/flagsmith/flagsmith/api/.testmondata*
khvn26 marked this conversation as resolved.
Show resolved Hide resolved
key: testmon-data-python${{ matrix.python-version }}-${{ github.event.pull_request.base.sha }}
khvn26 marked this conversation as resolved.
Show resolved Hide resolved
restore-keys: testmon-data-python${{ matrix.python-version }}-

- name: Run Tests
env:
DOTENV_OVERRIDE_FILE: .env-ci
run: make test

- name: Save testmon data cache
id: cache-testmon-save
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
uses: actions/cache/save@v3
with:
path: |
/home/runner/work/flagsmith/flagsmith/api/.testmondata*
key: testmon-data-python${{ matrix.python-version }}-${{github.sha}}

- name: Upload Coverage
uses: codecov/codecov-action@v3
env:
Expand Down
2 changes: 1 addition & 1 deletion api/.env-ci
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres
ANALYTICS_DATABASE_URL=postgres://postgres:postgres@localhost:5432/analytics
PYTEST_ADDOPTS=--cov . --cov-report xml -n auto --dist worksteal
PYTEST_ADDOPTS=--cov . --cov-report xml -n auto --dist worksteal --testmon
5 changes: 4 additions & 1 deletion api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ saml/
features/workflows/logic/

# Unit test coverage
.coverage
.coverage

# pytest-testmon files
.testmondata*
33 changes: 19 additions & 14 deletions api/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ pip-tools = "~6.13.0"
pytest-cov = "~4.1.0"
datamodel-code-generator = "~0.22"
requests-mock = "^1.11.0"
pytest-testmon = "^2.0.13"

[build-system]
requires = ["poetry-core>=1.5.0"]
Expand Down