diff --git a/.github/actions/run-linters/action.yml b/.github/actions/run-linters/action.yml index cad62175..f1656143 100644 --- a/.github/actions/run-linters/action.yml +++ b/.github/actions/run-linters/action.yml @@ -1,3 +1,4 @@ +# TODO: not used --- name: "Run Linters" description: "Run Linters for Nautobot App" diff --git a/.github/actions/unittests/action.yml b/.github/actions/unittests/action.yml index 33d41fb5..03e7a375 100644 --- a/.github/actions/unittests/action.yml +++ b/.github/actions/unittests/action.yml @@ -1,3 +1,4 @@ +# TODO: NOT USED --- name: "Unit Tests" description: "Run Unit Tests for Nautobot App" diff --git a/.github/workflows/check-migrations.yml b/.github/workflows/check-migrations.yml new file mode 100644 index 00000000..088892c6 --- /dev/null +++ b/.github/workflows/check-migrations.yml @@ -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 diff --git a/.github/workflows/run-linters.yml b/.github/workflows/run-linters.yml index c3594f26..82aebd21 100644 --- a/.github/workflows/run-linters.yml +++ b/.github/workflows/run-linters.yml @@ -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 diff --git a/.github/workflows/single-test-parallel.yml b/.github/workflows/single-test-parallel.yml index cb6f1db8..c246d1b7 100644 --- a/.github/workflows/single-test-parallel.yml +++ b/.github/workflows/single-test-parallel.yml @@ -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: diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index ae92c03b..aa5260ed 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -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 diff --git a/ci.md b/ci.md index c2fb75c3..2e2062cc 100644 --- a/ci.md +++ b/ci.md @@ -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. diff --git a/tasks.py b/tasks.py index 573374b1..98a69d36 100644 --- a/tasks.py +++ b/tasks.py @@ -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): @@ -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)