From 8bcb07cc15a751e799fe52b45fb258290b822e28 Mon Sep 17 00:00:00 2001 From: Andrew Bates Date: Fri, 31 May 2024 13:13:17 -0400 Subject: [PATCH] ci: Updated pipeline --- .github/workflows/ci.yml | 124 +++++++++++++++--------------- changes/.gitignore | 1 + development/towncrier_template.j2 | 28 +++++++ pyproject.toml | 53 +++++++++++++ 4 files changed, 145 insertions(+), 61 deletions(-) create mode 100644 changes/.gitignore create mode 100644 development/towncrier_template.j2 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e1978f12..c7f479a2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: - name: "Check out repository code" uses: "actions/checkout@v4" - name: "Setup environment" - uses: "networktocode/gh-action-setup-poetry-environment@v4" + uses: "networktocode/gh-action-setup-poetry-environment@v6" - name: "Linting: black" run: "poetry run invoke black" bandit: @@ -35,10 +35,10 @@ jobs: - name: "Check out repository code" uses: "actions/checkout@v4" - name: "Setup environment" - uses: "networktocode/gh-action-setup-poetry-environment@v4" + uses: "networktocode/gh-action-setup-poetry-environment@v6" - name: "Linting: bandit" run: "poetry run invoke bandit" - pydocstyle: + ruff: runs-on: "ubuntu-22.04" env: INVOKE_NAUTOBOT_DESIGN_BUILDER_LOCAL: "True" @@ -46,9 +46,20 @@ jobs: - name: "Check out repository code" uses: "actions/checkout@v4" - name: "Setup environment" - uses: "networktocode/gh-action-setup-poetry-environment@v4" - - name: "Linting: pydocstyle" - run: "poetry run invoke pydocstyle" + uses: "networktocode/gh-action-setup-poetry-environment@v6" + - name: "Linting: ruff" + run: "poetry run invoke ruff" + check-docs-build: + runs-on: "ubuntu-22.04" + env: + INVOKE_NAUTOBOT_DESIGN_BUILDER_LOCAL: "True" + steps: + - name: "Check out repository code" + uses: "actions/checkout@v4" + - name: "Setup environment" + uses: "networktocode/gh-action-setup-poetry-environment@v6" + - name: "Check Docs Build" + run: "poetry run invoke build-and-check-docs" flake8: runs-on: "ubuntu-22.04" env: @@ -57,7 +68,7 @@ jobs: - name: "Check out repository code" uses: "actions/checkout@v4" - name: "Setup environment" - uses: "networktocode/gh-action-setup-poetry-environment@v4" + uses: "networktocode/gh-action-setup-poetry-environment@v6" - name: "Linting: flake8" run: "poetry run invoke flake8" poetry: @@ -68,7 +79,7 @@ jobs: - name: "Check out repository code" uses: "actions/checkout@v4" - name: "Setup environment" - uses: "networktocode/gh-action-setup-poetry-environment@v4" + uses: "networktocode/gh-action-setup-poetry-environment@v6" - name: "Checking: poetry lock file" run: "poetry run invoke lock --check" yamllint: @@ -79,13 +90,13 @@ jobs: - name: "Check out repository code" uses: "actions/checkout@v4" - name: "Setup environment" - uses: "networktocode/gh-action-setup-poetry-environment@v4" + uses: "networktocode/gh-action-setup-poetry-environment@v6" - name: "Linting: yamllint" run: "poetry run invoke yamllint" - pylint: + check-in-docker: needs: - "bandit" - - "pydocstyle" + - "ruff" - "flake8" - "poetry" - "yamllint" @@ -103,7 +114,7 @@ jobs: - name: "Check out repository code" uses: "actions/checkout@v4" - name: "Setup environment" - uses: "networktocode/gh-action-setup-poetry-environment@v4" + uses: "networktocode/gh-action-setup-poetry-environment@v6" - name: "Set up Docker Buildx" id: "buildx" uses: "docker/setup-buildx-action@v3" @@ -114,7 +125,7 @@ jobs: context: "./" push: false load: true - tags: "${{ env.PLUGIN_NAME }}/nautobot:${{ matrix.nautobot-version }}-py${{ matrix.python-version }}" + tags: "${{ env.APP_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 }}" @@ -125,53 +136,13 @@ jobs: 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" - strategy: - fail-fast: true - matrix: - python-version: ["3.11"] - nautobot-version: ["2.2"] - env: - INVOKE_NAUTOBOT_DESIGN_BUILDER_PYTHON_VER: "${{ matrix.python-version }}" - INVOKE_NAUTOBOT_DESIGN_BUILDER_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: "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: "Checking: App Config" + run: "poetry run invoke validate-app-config" - name: "Checking: migrations" run: "poetry run invoke check-migrations" unittest: needs: - - "pylint" - - "check-migrations" + - "check-in-docker" strategy: fail-fast: true matrix: @@ -179,6 +150,9 @@ jobs: db-backend: ["postgresql"] nautobot-version: ["stable"] include: + - python-version: "3.11" + db-backend: "postgresql" + nautobot-version: "2.2" - python-version: "3.11" db-backend: "mysql" nautobot-version: "stable" @@ -190,7 +164,7 @@ jobs: - name: "Check out repository code" uses: "actions/checkout@v4" - name: "Setup environment" - uses: "networktocode/gh-action-setup-poetry-environment@v4" + uses: "networktocode/gh-action-setup-poetry-environment@v6" - name: "Set up Docker Buildx" id: "buildx" uses: "docker/setup-buildx-action@v3" @@ -201,7 +175,7 @@ jobs: context: "./" push: false load: true - tags: "${{ env.PLUGIN_NAME }}/nautobot:${{ matrix.nautobot-version }}-py${{ matrix.python-version }}" + tags: "${{ env.APP_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 }}" @@ -215,17 +189,35 @@ jobs: if: "matrix.db-backend == 'mysql'" - name: "Run Tests" run: "poetry run invoke unittest" + changelog: + if: | + contains(fromJson('["develop","ltm-1.6"]'), github.base_ref) && + (github.head_ref != 'main') + runs-on: "ubuntu-22.04" + steps: + - name: "Check out repository code" + uses: "actions/checkout@v4" + with: + fetch-depth: "0" + - name: "Setup environment" + uses: "networktocode/gh-action-setup-poetry-environment@v6" + - name: "Check for changelog entry" + run: | + git fetch --no-tags origin +refs/heads/${{ github.base_ref }}:refs/remotes/origin/${{ github.base_ref }} + poetry run towncrier check --compare-with origin/${{ github.base_ref }} publish_gh: needs: - "unittest" name: "Publish to GitHub" runs-on: "ubuntu-22.04" if: "startsWith(github.ref, 'refs/tags/v')" + env: + INVOKE_NAUTOBOT_DESIGN_BUILDER_LOCAL: "True" steps: - name: "Check out repository code" uses: "actions/checkout@v4" - name: "Set up Python" - uses: "actions/setup-python@v4" + uses: "actions/setup-python@v5" with: python-version: "3.11" - name: "Install Python Packages" @@ -234,12 +226,16 @@ jobs: run: "echo RELEASE_VERSION=${GITHUB_REF:10} >> $GITHUB_ENV" - name: "Run Poetry Version" run: "poetry version $RELEASE_VERSION" + - name: "Install Dependencies (needed for mkdocs)" + run: "poetry install --no-root" + - name: "Build Documentation" + run: "poetry run invoke build-and-check-docs" - name: "Run Poetry Build" run: "poetry build" - name: "Upload binaries to release" uses: "svenstaro/upload-release-action@v2" with: - repo_token: "${{ secrets.GH_NAUTOBOT_BOT_TOKEN }}" + repo_token: "${{ secrets.NTC_GITHUB_TOKEN }}" # use GH_NAUTOBOT_BOT_TOKEN for Nautobot Org repos. file: "dist/*" tag: "${{ github.ref }}" overwrite: true @@ -250,11 +246,13 @@ jobs: name: "Push Package to PyPI" runs-on: "ubuntu-22.04" if: "startsWith(github.ref, 'refs/tags/v')" + env: + INVOKE_{{ cookiecutter.app_name.upper() }}_LOCAL: "True" steps: - name: "Check out repository code" uses: "actions/checkout@v4" - name: "Set up Python" - uses: "actions/setup-python@v4" + uses: "actions/setup-python@v5" with: python-version: "3.11" - name: "Install Python Packages" @@ -263,6 +261,10 @@ jobs: run: "echo RELEASE_VERSION=${GITHUB_REF:10} >> $GITHUB_ENV" - name: "Run Poetry Version" run: "poetry version $RELEASE_VERSION" + - name: "Install Dependencies (needed for mkdocs)" + run: "poetry install --no-root" + - name: "Build Documentation" + run: "poetry run invoke build-and-check-docs" - name: "Run Poetry Build" run: "poetry build" - name: "Push to PyPI" diff --git a/changes/.gitignore b/changes/.gitignore new file mode 100644 index 00000000..f935021a --- /dev/null +++ b/changes/.gitignore @@ -0,0 +1 @@ +!.gitignore diff --git a/development/towncrier_template.j2 b/development/towncrier_template.j2 new file mode 100644 index 00000000..ea91ee1d --- /dev/null +++ b/development/towncrier_template.j2 @@ -0,0 +1,28 @@ +{% if render_title %} +## [v{{ versiondata.version }} ({{ versiondata.date }})](https://github.com/nautobot/nautobot-app-design-builder/releases/tag/v{{ versiondata.version}}) + +{% endif %} +{% for section, _ in sections.items() %} +{% if sections[section] %} +{% for category, val in definitions.items() if category in sections[section] %} +{% if sections[section][category]|length != 0 %} +### {{ definitions[category]['name'] }} + +{% if definitions[category]['showcontent'] %} +{% for text, values in sections[section][category].items() %} +{% for item in text.split('\n') %} +- {{ values|join(', ') }} - {{ item.strip() }} +{% endfor %} +{% endfor %} + +{% else %} +- {{ sections[section][category]['']|join(', ') }} + +{% endif %} +{% endif %} +{% endfor %} +{% else %} +No significant changes. + +{% endif %} +{% endfor %} diff --git a/pyproject.toml b/pyproject.toml index 2dbf2b6a..b35c975e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -181,3 +181,56 @@ convention = "google" [build-system] requires = ["poetry_core>=1.0.0"] build-backend = "poetry.core.masonry.api" + +[tool.towncrier] +package = "nautobot_design_builder" +directory = "changes" +filename = "docs/admin/release_notes/version_X.Y.md" +template = "development/towncrier_template.j2" +start_string = "" +issue_format = "[#{issue}](https://github.com/nautobot/nautobot-app-design-builder/issues/{issue})" + +[[tool.towncrier.type]] +directory = "security" +name = "Security" +showcontent = true + +[[tool.towncrier.type]] +directory = "added" +name = "Added" +showcontent = true + +[[tool.towncrier.type]] +directory = "changed" +name = "Changed" +showcontent = true + +[[tool.towncrier.type]] +directory = "deprecated" +name = "Deprecated" +showcontent = true + +[[tool.towncrier.type]] +directory = "removed" +name = "Removed" +showcontent = true + +[[tool.towncrier.type]] +directory = "fixed" +name = "Fixed" +showcontent = true + +[[tool.towncrier.type]] +directory = "dependencies" +name = "Dependencies" +showcontent = true + +[[tool.towncrier.type]] +directory = "documentation" +name = "Documentation" +showcontent = true + +[[tool.towncrier.type]] +directory = "housekeeping" +name = "Housekeeping" +showcontent = true