Skip to content

Commit

Permalink
WIP: migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
snaselj committed Oct 18, 2023
1 parent ca732b2 commit 8c7ab6f
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 23 deletions.
1 change: 1 addition & 0 deletions .github/actions/run-linters/action.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# TODO: not used
---
name: "Run Linters"
description: "Run Linters for Nautobot App"
Expand Down
1 change: 1 addition & 0 deletions .github/actions/unittests/action.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# TODO: NOT USED
---
name: "Unit Tests"
description: "Run Unit Tests for Nautobot App"
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/check-migrations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
name: "Check Migrations"
# yamllint disable-line rule:truthy
on:
workflow_call:
inputs:
db-backend:
description: "Database Backend"
required: true
type: "string"
nautobot-version:
description: "Nautobot Version"
required: true
type: "string"
python-version:
description: "Python Version"
required: true
type: "string"
tag-prefix:
description: "Docker Image Tag Prefix"
required: true
type: "string"
use-cache:
description: "Whether to use GitHub Actions cache"
required: true
type: "boolean"
jobs:
check-migrations:
runs-on: "ubuntu-22.04"
steps:
- name: "Check out repository code"
uses: "actions/checkout@v4"
- name: "Configure Compose"
id: "config"
uses: "./.github/actions/config-compose"
with:
db-backend: "${{ inputs.db-backend }}"
nautobot-version: "${{ inputs.nautobot-version }}"
python-version: "${{ inputs.python-version }}"
tag-prefix: "${{ inputs.tag-prefix }}"
use-cache: "${{ inputs.use-cache }}"
- name: "Check Migrations"
env:
COMPOSE_ANSI: "0"
COMPOSE_FILE: "${{ steps.config.outputs.compose-file }}"
NAUTOBOT_VER: "${{ inputs.nautobot-version }}"
PYTHON_VER: "${{ inputs.python-version }}"
run: |
cd development
docker compose run \
--rm \
--entrypoint='' \
-- \
nautobot \
invoke check-migrations
19 changes: 14 additions & 5 deletions .github/workflows/run-linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,17 @@ jobs:
tag-prefix: "${{ inputs.tag-prefix }}"
use-cache: "${{ inputs.use-cache }}"
- name: "Run Linters"
uses: "./.github/actions/run-linters"
with:
compose-file: "${{ steps.config.outputs.compose-file }}"
nautobot-version: "${{ inputs.nautobot-version }}"
python-version: "${{ inputs.python-version }}"
shell: "bash"
env:
COMPOSE_ANSI: "0"
COMPOSE_FILE: "${{ steps.config.outputs.compose-file }}"
NAUTOBOT_VER: "${{ inputs.nautobot-version }}"
PYTHON_VER: "${{ inputs.python-version }}"
run: |
cd development
docker-compose run \
--rm \
--entrypoint='' \
-- \
nautobot \
invoke test-linters
10 changes: 9 additions & 1 deletion .github/workflows/single-test-parallel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,21 @@ on:
required: true
type: "boolean"
jobs:
linters:
run-linters:
uses: "./.github/workflows/run-linters.yml"
with:
nautobot-version: "${{ inputs.nautobot-version }}"
python-version: "${{ inputs.python-version }}"
tag-prefix: "${{ inputs.tag-prefix }}"
use-cache: "${{ inputs.use-cache }}"
check-migrations:
uses: "./.github/workflows/check-migrations.yml"
with:
db-backend: "${{ inputs.db-backend }}"
nautobot-version: "${{ inputs.nautobot-version }}"
python-version: "${{ inputs.python-version }}"
tag-prefix: "${{ inputs.tag-prefix }}"
use-cache: "${{ inputs.use-cache }}"
unittest:
uses: "./.github/workflows/unittest.yml"
with:
Expand Down
19 changes: 14 additions & 5 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,17 @@ jobs:
tag-prefix: "${{ inputs.tag-prefix }}"
use-cache: "${{ inputs.use-cache }}"
- name: "Unit Tests"
uses: "./.github/actions/unittests"
with:
compose-file: "${{ steps.config.outputs.compose-file }}"
nautobot-version: "${{ inputs.nautobot-version }}"
python-version: "${{ inputs.python-version }}"
shell: "bash"
env:
COMPOSE_ANSI: "0"
COMPOSE_FILE: "${{ steps.config.outputs.compose-file }}"
NAUTOBOT_VER: "${{ inputs.nautobot-version }}"
PYTHON_VER: "${{ inputs.python-version }}"
run: |
cd development
docker compose run \
--rm \
--entrypoint='' \
-- \
nautobot \
invoke unittest --failfast --keepdb
2 changes: 1 addition & 1 deletion ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ Jobs will run in parallel and re-use cached Docker layers and [database dumps](#

When testing the single Nautobot and Python version the cache is much less utilized.

- Currently, the limit is 10 G per repository. Each Nautobot/Python combination uses about 2.5 GB. That means, two concurrent PRs will purge others cache.
- Currently, the limit is 10 G per repository. Each Nautobot/Python combination uses almost 1 GB. That means, multiple concurrent PRs can often purge others cache.
- For full tests, caching will be disabled.

Better define `.gitignore` file to avoid unnecessary context changes.
Expand Down
32 changes: 21 additions & 11 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,15 +663,8 @@ def unittest_coverage(context):
run_command(context, command)


@task(
help={
"failfast": "fail as soon as a single test fails don't run the entire test suite. (default: False)",
"keepdb": "Save and re-use test database between test runs for faster re-testing. (default: False)",
"lint-only": "Only run linters; unit tests will be excluded. (default: False)",
"test-docs": "Build documentation to be available within Nautobot. (default: True)",
}
)
def tests(context, failfast=False, keepdb=False, lint_only=False, test_docs=True):
@task
def test_linters(context):
"""Run all tests for this plugin."""
# If we are not running locally, start the docker containers so we don't have to for each test
if not is_truthy(context.nautobot_firewall_models.local):
Expand All @@ -690,10 +683,27 @@ def tests(context, failfast=False, keepdb=False, lint_only=False, test_docs=True
yamllint(context)
print("Running poetry check...")
lock(context, check=True)
print("Running migrations check...")
check_migrations(context)
print("Running pylint...")
pylint(context)
print("All linters have passed!")


@task(
help={
"failfast": "fail as soon as a single test fails don't run the entire test suite. (default: False)",
"keepdb": "Save and re-use test database between test runs for faster re-testing. (default: False)",
"lint-only": "Only run linters; unit tests will be excluded. (default: False)",
"test-docs": "Build documentation to be available within Nautobot. (default: True)",
"test-migrations": "Run migration checks. (default: True)",
}
)
def tests(context, failfast=False, keepdb=False, lint_only=False, test_docs=True, test_migrations=True):
"""Run all tests for this plugin."""
# If we are not running locally, start the docker containers so we don't have to for each test
test_linters(context)
if test_migrations:
print("Running migrations check...")
check_migrations(context)
if test_docs:
print("Running mkdocs...")
build_and_check_docs(context)
Expand Down

0 comments on commit 8c7ab6f

Please sign in to comment.