From 5ea593a50c1c9d17dfaa184414d1daa91c03d513 Mon Sep 17 00:00:00 2001 From: Maxwell G Date: Tue, 5 Sep 2023 12:51:04 -0500 Subject: [PATCH] [stable-2.15] Backport workflow automation (#342) Co-authored-by: Sviatoslav Sydorenko Co-authored-by: Don Naro --- .github/dependabot.yml | 11 ++ .github/workflows/ci.yaml | 5 + .github/workflows/reusable-nox.yml | 30 ++++ .isort.cfg | 2 + .pip-tools.toml | 5 + .../community/documentation_contributions.rst | 1 + noxfile.py | 77 +++++++++ tests/constraints-base.in | 4 + tests/constraints.in | 6 +- tests/formatters.in | 2 + tests/formatters.txt | 22 +++ tests/requirements-relaxed.in | 14 ++ tests/requirements-relaxed.txt | 163 ++++++++++++++++++ tests/requirements.in | 13 +- tests/static.in | 1 + tests/static.txt | 8 + tests/typing.in | 3 + tests/typing.txt | 67 +++++++ 18 files changed, 422 insertions(+), 12 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/reusable-nox.yml create mode 100644 .isort.cfg create mode 100644 .pip-tools.toml create mode 100644 noxfile.py create mode 100644 tests/constraints-base.in create mode 100644 tests/formatters.in create mode 100644 tests/formatters.txt create mode 100644 tests/requirements-relaxed.in create mode 100644 tests/requirements-relaxed.txt create mode 100644 tests/static.in create mode 100644 tests/static.txt create mode 100644 tests/typing.in create mode 100644 tests/typing.txt diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000000..2f4ff900d8 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +--- +# Copyright (c) Ansible Project +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 868cf78cf6..a3a8e6834d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -4,7 +4,9 @@ on: push: branches-ignore: - 'patchback/**' + - 'pip-compile/**' pull_request: + workflow_dispatch: jobs: docs_sanity_docs_build: @@ -54,3 +56,6 @@ jobs: - name: Run rstcheck Sanity run: | python tests/sanity.py rstcheck + + nox: + uses: ./.github/workflows/reusable-nox.yml diff --git a/.github/workflows/reusable-nox.yml b/.github/workflows/reusable-nox.yml new file mode 100644 index 0000000000..72baa63196 --- /dev/null +++ b/.github/workflows/reusable-nox.yml @@ -0,0 +1,30 @@ +--- +name: nox + +"on": + workflow_call: + +jobs: + nox: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - session: static + python-versions: "3.11" + - session: formatters_check + python-versions: "3.11" + - session: typing + python-versions: "3.11" + name: "Run nox ${{ matrix.session }} session" + steps: + - name: Check out repo + uses: actions/checkout@v3 + - name: Setup nox + uses: wntrblm/nox@2023.04.22 + with: + python-versions: "${{ matrix.python-versions }}" + - name: "Run nox -e ${{ matrix.session }}" + run: | + nox -e "${{ matrix.session }}" diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 0000000000..c76db01ff4 --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,2 @@ +[isort] +profile = black diff --git a/.pip-tools.toml b/.pip-tools.toml new file mode 100644 index 0000000000..c1f6c7ad65 --- /dev/null +++ b/.pip-tools.toml @@ -0,0 +1,5 @@ +[tool.pip-tools] +resolver = "backtracking" +allow-unsafe = true +strip-extras = true +quiet = true diff --git a/docs/docsite/rst/community/documentation_contributions.rst b/docs/docsite/rst/community/documentation_contributions.rst index f49d86977d..e94d3f5219 100644 --- a/docs/docsite/rst/community/documentation_contributions.rst +++ b/docs/docsite/rst/community/documentation_contributions.rst @@ -111,6 +111,7 @@ Drop the ``--user`` option in the following commands if you use a virtual enviro pip install --user -r tests/requirements.in -c tests/requirements.txt # Installs tested dependency versions. pip install --user -r tests/requirements.in # Installs the unpinned dependency versions. + pip install --user -r tests/requirements-relaxed.in # Installs the unpinned dependency versions including untested antsibull-docs. .. note:: diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 0000000000..486b23b18c --- /dev/null +++ b/noxfile.py @@ -0,0 +1,77 @@ +import os +from pathlib import Path + +import nox + +LINT_FILES = ("hacking/pr_labeler/label.py", "noxfile.py") +PINNED = os.environ.get("PINNED", "true").lower() in {"1", "true"} +nox.options.sessions = ("lint",) + + +def install(session: nox.Session, *args, req: str, **kwargs): + if PINNED: + kwargs.setdefault("env", {})["PIP_CONSTRAINT"] = f"tests/{req}.txt" + session.install("-r", f"tests/{req}.in", *args, **kwargs) + + +@nox.session +def static(session: nox.Session): + """ + Run static checkers + """ + install(session, req="static") + session.run("ruff", *session.posargs, *LINT_FILES) + + +@nox.session +def formatters(session: nox.Session): + """ + Reformat code + """ + install(session, req="formatters") + session.run("isort", *session.posargs, *LINT_FILES) + session.run("black", *session.posargs, *LINT_FILES) + + +@nox.session +def formatters_check(session: nox.Session): + """ + Check code formatting without making changes + """ + install(session, req="formatters") + session.run("isort", "--check", *session.posargs, *LINT_FILES) + session.run("black", "--check", *session.posargs, *LINT_FILES) + + +@nox.session +def typing(session: nox.Session): + install(session, req="typing") + session.run("mypy", *session.posargs, *LINT_FILES) + + +@nox.session +def lint(session: nox.Session): + session.notify("typing") + session.notify("static") + session.notify("formatters") + + +requirements_files = list( + {path.name.replace(".in", "") for path in Path("tests").glob("*in")} + - {"constraints", "constraints-base"} +) + + +@nox.session(name="pip-compile", python=["3.10"]) +@nox.parametrize(["req"], requirements_files, requirements_files) +def pip_compile(session: nox.Session, req: str): + # .pip-tools.toml was introduced in v7 + session.install("pip-tools >= 7") + # fmt: off + session.run( + "pip-compile", + "--upgrade", + "--output-file", f"tests/{req}.txt", + f"tests/{req}.in", + ) + # fmt: on diff --git a/tests/constraints-base.in b/tests/constraints-base.in new file mode 100644 index 0000000000..7a92b3815d --- /dev/null +++ b/tests/constraints-base.in @@ -0,0 +1,4 @@ +# Known limitations for indirect/transitive dependencies. + +rstcheck < 6 # rstcheck 6.x has problem with rstcheck.core triggered by include files w/ sphinx directives https://github.com/rstcheck/rstcheck-core/issues/3 +sphinx < 7.2.0 # https://github.com/readthedocs/sphinx-notfound-page/issues/219 diff --git a/tests/constraints.in b/tests/constraints.in index e776c29219..2d5485180b 100644 --- a/tests/constraints.in +++ b/tests/constraints.in @@ -1,5 +1,5 @@ -# Known limitations for indirect/transitive dependencies. -resolvelib < 1.1.0 +# This constraints file contains pins for the stable, tested versions of sphinx +# and antsibull-docs that production builds rely upon. + sphinx == 5.3.0 -rstcheck < 6 # rstcheck 6.x has problem with rstcheck.core triggered by include files w/ sphinx directives https://github.com/rstcheck/rstcheck-core/issues/3 antsibull-docs == 2.3.1 # currently approved version diff --git a/tests/formatters.in b/tests/formatters.in new file mode 100644 index 0000000000..7559a405a0 --- /dev/null +++ b/tests/formatters.in @@ -0,0 +1,2 @@ +black +isort diff --git a/tests/formatters.txt b/tests/formatters.txt new file mode 100644 index 0000000000..979b15c745 --- /dev/null +++ b/tests/formatters.txt @@ -0,0 +1,22 @@ +# +# This file is autogenerated by pip-compile with Python 3.10 +# by the following command: +# +# pip-compile --allow-unsafe --output-file=tests/formatters.txt --strip-extras tests/formatters.in +# +black==23.7.0 + # via -r tests/formatters.in +click==8.1.7 + # via black +isort==5.12.0 + # via -r tests/formatters.in +mypy-extensions==1.0.0 + # via black +packaging==23.1 + # via black +pathspec==0.11.2 + # via black +platformdirs==3.10.0 + # via black +tomli==2.0.1 + # via black diff --git a/tests/requirements-relaxed.in b/tests/requirements-relaxed.in new file mode 100644 index 0000000000..efc542c66c --- /dev/null +++ b/tests/requirements-relaxed.in @@ -0,0 +1,14 @@ +# This requirements file contains no pins on antsibull-docs and other +# essential tools +# It's used for testing purposes and devel branch builds on docs.ansible.com. + +-c constraints-base.in + +jinja2 >= 3.0.0 # used by hacking/build_library/build_ansible/command_plugins/generate_man.py and dump_keywords.py +pyyaml >= 5.1 # used by ansible-core +resolvelib >= 0.5.3, < 1.1.0 # used by ansible-core +sphinx +sphinx-notfound-page +sphinx-ansible-theme +rstcheck +antsibull-docs ~= 2.0 diff --git a/tests/requirements-relaxed.txt b/tests/requirements-relaxed.txt new file mode 100644 index 0000000000..5c321b8259 --- /dev/null +++ b/tests/requirements-relaxed.txt @@ -0,0 +1,163 @@ +# +# This file is autogenerated by pip-compile with Python 3.10 +# by the following command: +# +# pip-compile --allow-unsafe --output-file=tests/requirements-relaxed.txt --strip-extras tests/requirements-relaxed.in +# +aiofiles==23.2.1 + # via antsibull-core +aiohttp==3.8.5 + # via + # antsibull-core + # antsibull-docs +aiosignal==1.3.1 + # via aiohttp +alabaster==0.7.13 + # via sphinx +ansible-pygments==0.1.1 + # via + # antsibull-docs + # sphinx-ansible-theme +antsibull-core==2.0.0 + # via antsibull-docs +antsibull-docs==2.3.1 + # via -r tests/requirements-relaxed.in +antsibull-docs-parser==1.0.0 + # via antsibull-docs +async-timeout==4.0.3 + # via aiohttp +asyncio-pool==0.6.0 + # via antsibull-docs +attrs==23.1.0 + # via aiohttp +babel==2.12.1 + # via sphinx +build==0.10.0 + # via antsibull-core +certifi==2023.7.22 + # via requests +charset-normalizer==3.2.0 + # via + # aiohttp + # requests +docutils==0.18.1 + # via + # antsibull-docs + # rstcheck + # sphinx + # sphinx-rtd-theme +frozenlist==1.4.0 + # via + # aiohttp + # aiosignal +idna==3.4 + # via + # requests + # yarl +imagesize==1.4.1 + # via sphinx +jinja2==3.1.2 + # via + # -r tests/requirements-relaxed.in + # antsibull-docs + # sphinx +markupsafe==2.1.3 + # via jinja2 +multidict==6.0.4 + # via + # aiohttp + # yarl +packaging==23.1 + # via + # antsibull-core + # antsibull-docs + # build + # sphinx +perky==0.9.2 + # via antsibull-core +pydantic==1.10.12 + # via + # antsibull-core + # antsibull-docs +pygments==2.16.1 + # via + # ansible-pygments + # sphinx +pyproject-hooks==1.0.0 + # via build +pyyaml==6.0.1 + # via + # -r tests/requirements-relaxed.in + # antsibull-core + # antsibull-docs +requests==2.31.0 + # via sphinx +resolvelib==1.0.1 + # via -r tests/requirements-relaxed.in +rstcheck==5.0.0 + # via + # -c tests/constraints-base.in + # -r tests/requirements-relaxed.in + # antsibull-docs +semantic-version==2.10.0 + # via + # antsibull-core + # antsibull-docs +sh==1.14.3 + # via antsibull-core +six==1.16.0 + # via twiggy +snowballstemmer==2.2.0 + # via sphinx +sphinx==7.1.2 + # via + # -c tests/constraints-base.in + # -r tests/requirements-relaxed.in + # antsibull-docs + # sphinx-ansible-theme + # sphinx-notfound-page + # sphinx-rtd-theme + # sphinxcontrib-applehelp + # sphinxcontrib-devhelp + # sphinxcontrib-htmlhelp + # sphinxcontrib-jquery + # sphinxcontrib-qthelp + # sphinxcontrib-serializinghtml +sphinx-ansible-theme==0.10.2 + # via -r tests/requirements-relaxed.in +sphinx-notfound-page==0.8.3 + # via -r tests/requirements-relaxed.in +sphinx-rtd-theme==1.3.0 + # via sphinx-ansible-theme +sphinxcontrib-applehelp==1.0.7 + # via sphinx +sphinxcontrib-devhelp==1.0.5 + # via sphinx +sphinxcontrib-htmlhelp==2.0.4 + # via sphinx +sphinxcontrib-jquery==4.1 + # via sphinx-rtd-theme +sphinxcontrib-jsmath==1.0.1 + # via sphinx +sphinxcontrib-qthelp==1.0.6 + # via sphinx +sphinxcontrib-serializinghtml==1.1.9 + # via sphinx +tomli==2.0.1 + # via + # build + # pyproject-hooks +twiggy==0.5.1 + # via + # antsibull-core + # antsibull-docs +types-docutils==0.18.3 + # via rstcheck +typing-extensions==4.7.1 + # via + # pydantic + # rstcheck +urllib3==2.0.4 + # via requests +yarl==1.9.2 + # via aiohttp diff --git a/tests/requirements.in b/tests/requirements.in index 7a409bbc5a..6ff0f42f86 100644 --- a/tests/requirements.in +++ b/tests/requirements.in @@ -1,10 +1,5 @@ --c constraints.in # <-- contains known limitations +# This requirements file is used for stable ansible docs builds +# It depends on specific, tested antsibull-docs and sphinx versions -jinja2 >= 3.0.0 # used by hacking/build_library/build_ansible/command_plugins/generate_man.py and dump_keywords.py -pyyaml >= 5.1 # used by ansible-core -resolvelib # used by ansible-core -sphinx -sphinx-notfound-page -sphinx-ansible-theme -rstcheck -antsibull-docs +-c constraints.in # <-- contains known limitations +-r requirements-relaxed.in # <-- contains base set of dependencies diff --git a/tests/static.in b/tests/static.in new file mode 100644 index 0000000000..af3ee57638 --- /dev/null +++ b/tests/static.in @@ -0,0 +1 @@ +ruff diff --git a/tests/static.txt b/tests/static.txt new file mode 100644 index 0000000000..f5256c2d1f --- /dev/null +++ b/tests/static.txt @@ -0,0 +1,8 @@ +# +# This file is autogenerated by pip-compile with Python 3.10 +# by the following command: +# +# pip-compile --allow-unsafe --output-file=tests/static.txt --strip-extras tests/static.in +# +ruff==0.0.286 + # via -r tests/static.in diff --git a/tests/typing.in b/tests/typing.in new file mode 100644 index 0000000000..63112a0d90 --- /dev/null +++ b/tests/typing.in @@ -0,0 +1,3 @@ +-r ../hacking/pr_labeler/requirements.txt +mypy +nox diff --git a/tests/typing.txt b/tests/typing.txt new file mode 100644 index 0000000000..f3f9e40960 --- /dev/null +++ b/tests/typing.txt @@ -0,0 +1,67 @@ +# +# This file is autogenerated by pip-compile with Python 3.10 +# by the following command: +# +# pip-compile --allow-unsafe --output-file=tests/typing.txt --strip-extras tests/typing.in +# +argcomplete==3.1.1 + # via nox +certifi==2023.7.22 + # via requests +cffi==1.15.1 + # via + # cryptography + # pynacl +charset-normalizer==3.2.0 + # via requests +click==8.1.7 + # via typer +codeowners==0.6.0 + # via -r tests/../hacking/pr_labeler/requirements.txt +colorlog==6.7.0 + # via nox +cryptography==41.0.3 + # via pyjwt +deprecated==1.2.14 + # via pygithub +distlib==0.3.7 + # via virtualenv +filelock==3.12.2 + # via virtualenv +idna==3.4 + # via requests +mypy==1.5.1 + # via -r tests/typing.in +mypy-extensions==1.0.0 + # via mypy +nox==2023.4.22 + # via -r tests/typing.in +packaging==23.1 + # via nox +platformdirs==3.10.0 + # via virtualenv +pycparser==2.21 + # via cffi +pygithub==1.59.1 + # via -r tests/../hacking/pr_labeler/requirements.txt +pyjwt==2.8.0 + # via pygithub +pynacl==1.5.0 + # via pygithub +requests==2.31.0 + # via pygithub +tomli==2.0.1 + # via mypy +typer==0.9.0 + # via -r tests/../hacking/pr_labeler/requirements.txt +typing-extensions==4.7.1 + # via + # codeowners + # mypy + # typer +urllib3==2.0.4 + # via requests +virtualenv==20.24.3 + # via nox +wrapt==1.15.0 + # via deprecated