From 4b174a29e3fdc68c5c195c786a4009d1615945b9 Mon Sep 17 00:00:00 2001 From: Jan Snasel Date: Tue, 17 Oct 2023 06:39:27 +0000 Subject: [PATCH 1/3] feat: Check migrations and poetry lock file in CI --- .github/workflows/ci.yml | 22 ++++++++++++++++++++++ tasks.py | 8 ++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b34c4f1f..e54c800c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,6 +71,28 @@ jobs: uses: "networktocode/gh-action-setup-poetry-environment@v4" - name: "Linting: yamllint" run: "poetry run invoke yamllint" + migrations: + runs-on: "ubuntu-22.04" + env: + INVOKE_NAUTOBOT_FIREWALL_MODELS_LOCAL: "True" + steps: + - name: "Check out repository code" + uses: "actions/checkout@v4" + - name: "Setup environment" + uses: "networktocode/gh-action-setup-poetry-environment@v4" + - name: "Linting: yamllint" + run: "poetry run invoke check-migrations" + poetry: + runs-on: "ubuntu-22.04" + env: + INVOKE_NAUTOBOT_FIREWALL_MODELS_LOCAL: "True" + steps: + - name: "Check out repository code" + uses: "actions/checkout@v4" + - name: "Setup environment" + uses: "networktocode/gh-action-setup-poetry-environment@v4" + - name: "Linting: yamllint" + run: "poetry run invoke lock --check" pylint: needs: - "bandit" diff --git a/tasks.py b/tasks.py index ddb53cc8..20764311 100644 --- a/tasks.py +++ b/tasks.py @@ -173,9 +173,9 @@ def generate_packages(context): @task -def lock(context): +def lock(context, check=False): """Generate poetry.lock inside the Nautobot container.""" - run_command(context, "poetry lock --no-update") + run_command(context, f"poetry {'check' if check else 'lock --no-update'}") # ------------------------------------------------------------------------------ @@ -678,6 +678,10 @@ def tests(context, failfast=False, keepdb=False, lint_only=False): pydocstyle(context) print("Running yamllint...") yamllint(context) + print("Running poetry check...") + lock(context, check=True) + print("Running migrations check...") + check_migrations(context) print("Running pylint...") pylint(context) print("Running mkdocs...") From 1534c55ea5bea975db8683cb81ced38dff489c0b Mon Sep 17 00:00:00 2001 From: Jan Snasel Date: Tue, 17 Oct 2023 06:53:42 +0000 Subject: [PATCH 2/3] fix: CI --- .github/workflows/ci.yml | 57 +++++++++++++++++++++++++++++++--------- tasks.py | 9 ++++++- 2 files changed, 53 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e54c800c..aa325dce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,7 +60,7 @@ jobs: uses: "networktocode/gh-action-setup-poetry-environment@v4" - name: "Linting: flake8" run: "poetry run invoke flake8" - yamllint: + poetry: runs-on: "ubuntu-22.04" env: INVOKE_NAUTOBOT_FIREWALL_MODELS_LOCAL: "True" @@ -69,9 +69,9 @@ jobs: uses: "actions/checkout@v4" - name: "Setup environment" uses: "networktocode/gh-action-setup-poetry-environment@v4" - - name: "Linting: yamllint" - run: "poetry run invoke yamllint" - migrations: + - name: "Checking: poetry lock file" + run: "poetry run invoke lock --check" + yamllint: runs-on: "ubuntu-22.04" env: INVOKE_NAUTOBOT_FIREWALL_MODELS_LOCAL: "True" @@ -81,23 +81,56 @@ jobs: - name: "Setup environment" uses: "networktocode/gh-action-setup-poetry-environment@v4" - name: "Linting: yamllint" - run: "poetry run invoke check-migrations" - poetry: + run: "poetry run invoke yamllint" + pylint: + needs: + - "bandit" + - "pydocstyle" + - "flake8" + - "poetry" + - "yamllint" + - "black" runs-on: "ubuntu-22.04" + strategy: + fail-fast: true + matrix: + python-version: ["3.11"] + nautobot-version: ["2.0.0"] env: - INVOKE_NAUTOBOT_FIREWALL_MODELS_LOCAL: "True" + INVOKE_NAUTOBOT_FIREWALL_MODELS_PYTHON_VER: "${{ matrix.python-version }}" + INVOKE_NAUTOBOT_FIREWALL_MODELS_NAUTOBOT_VER: "${{ matrix.nautobot-version }}" steps: - name: "Check out repository code" uses: "actions/checkout@v4" - name: "Setup environment" uses: "networktocode/gh-action-setup-poetry-environment@v4" - - name: "Linting: yamllint" - run: "poetry run invoke lock --check" - pylint: + - name: "Set up Docker Buildx" + id: "buildx" + uses: "docker/setup-buildx-action@v3" + - name: "Build" + uses: "docker/build-push-action@v5" + with: + builder: "${{ steps.buildx.outputs.name }}" + context: "./" + push: false + load: true + tags: "${{ env.PLUGIN_NAME }}/nautobot:${{ matrix.nautobot-version }}-py${{ matrix.python-version }}" + file: "./development/Dockerfile" + cache-from: "type=gha,scope=${{ matrix.nautobot-version }}-py${{ matrix.python-version }}" + cache-to: "type=gha,scope=${{ matrix.nautobot-version }}-py${{ matrix.python-version }}" + build-args: | + NAUTOBOT_VER=${{ matrix.nautobot-version }} + PYTHON_VER=${{ matrix.python-version }} + - name: "Copy credentials" + run: "cp development/creds.example.env development/creds.env" + - name: "Linting: pylint" + run: "poetry run invoke pylint" + check-migrations: needs: - "bandit" - "pydocstyle" - "flake8" + - "poetry" - "yamllint" - "black" runs-on: "ubuntu-22.04" @@ -133,8 +166,8 @@ jobs: PYTHON_VER=${{ matrix.python-version }} - name: "Copy credentials" run: "cp development/creds.example.env development/creds.env" - - name: "Linting: pylint" - run: "poetry run invoke pylint" + - name: "Checking: migrations" + run: "poetry run invoke check-migrations" unittest: needs: - "pylint" diff --git a/tasks.py b/tasks.py index 20764311..17cda20c 100644 --- a/tasks.py +++ b/tasks.py @@ -172,7 +172,14 @@ def generate_packages(context): run_command(context, command) -@task +@task( + help={ + "check": ( + "If enabled, check for outdated dependencies in the poetry.lock file, " + "instead of generating a new one. (default: disabled)" + ) + } +) def lock(context, check=False): """Generate poetry.lock inside the Nautobot container.""" run_command(context, f"poetry {'check' if check else 'lock --no-update'}") From a428375261c015601dc7de3868ca191b95a3d594 Mon Sep 17 00:00:00 2001 From: Jan Snasel Date: Tue, 17 Oct 2023 07:07:00 +0000 Subject: [PATCH 3/3] fix: CI deps --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aa325dce..b539e935 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -171,6 +171,7 @@ jobs: unittest: needs: - "pylint" + - "check-migrations" strategy: fail-fast: true matrix: