Skip to content

Commit

Permalink
ci: API tests optimization. Enable merge queue checks and run only ch…
Browse files Browse the repository at this point in the history
…anged tests (#3216)
  • Loading branch information
novakzaballa authored Dec 22, 2023
1 parent 924149c commit 93ea01c
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 5 deletions.
28 changes: 25 additions & 3 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 @@ -67,11 +69,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*
key: testmon-data-python${{ matrix.python-version }}-${{ github.event.pull_request.base.sha }}
restore-keys: testmon-data-python${{ matrix.python-version }}-

- name: Run Tests
env:
DOTENV_OVERRIDE_FILE: .env-ci
DOTENV_OVERRIDE_FILE: "${{ github.event_name == 'merge_group' && '.env-ci' || '.env-ci-testmon' }}"
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ checkstyle.txt
.env*
!.env-local
!.env-ci
!.env-ci-testmon
.direnv
.envrc
.tool-versions
Expand Down
3 changes: 3 additions & 0 deletions api/.env-ci-testmon
Original file line number Diff line number Diff line change
@@ -0,0 +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 --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*
15 changes: 15 additions & 0 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 @@ -145,6 +145,7 @@ requests-mock = "^1.11.0"
django-extensions = "^3.2.3"
pdbpp = "^0.10.3"
django-capture-on-commit-callbacks = "^1.11.0"
pytest-testmon = "^2.0.13"
mypy-boto3-dynamodb = "^1.33.0"

[build-system]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ def test_create_environment_with_required_metadata_returns_201(
assert response.status_code == status.HTTP_201_CREATED
assert (
response.json()["metadata"][0]["model_field"]
== required_a_environment_metadata_field.field.id
== required_a_environment_metadata_field.id
)
assert response.json()["metadata"][0]["field_value"] == str(field_value)

Expand Down

3 comments on commit 93ea01c

@vercel
Copy link

@vercel vercel bot commented on 93ea01c Dec 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./docs

docs.bullet-train.io
docs.flagsmith.com
docs-flagsmith.vercel.app
docs-git-main-flagsmith.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 93ea01c Dec 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 93ea01c Dec 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.