From 23399f7890afaeb27b41cdbb6e2144655e51fdd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Wi=C5=9Bniewski?= Date: Mon, 11 Nov 2024 13:09:52 +0100 Subject: [PATCH] Update documentation deployment flow --- ...ld_n_deploy_docs.yaml => deploy_docs.yaml} | 22 ++++--- poetry.lock | 18 +++-- pyproject.toml | 4 +- scripts/deploy_docs.py | 65 +++++++++++++++++++ test/__init__.py | 6 ++ 5 files changed, 96 insertions(+), 19 deletions(-) rename .github/workflows/{build_n_deploy_docs.yaml => deploy_docs.yaml} (63%) create mode 100644 scripts/deploy_docs.py diff --git a/.github/workflows/build_n_deploy_docs.yaml b/.github/workflows/deploy_docs.yaml similarity index 63% rename from .github/workflows/build_n_deploy_docs.yaml rename to .github/workflows/deploy_docs.yaml index d09c60b6..de2f6c2e 100644 --- a/.github/workflows/build_n_deploy_docs.yaml +++ b/.github/workflows/deploy_docs.yaml @@ -1,19 +1,18 @@ --- -name: Build & Deploy Docs +name: Deploy Documentation on: push: tags: - "v*" - workflow_dispatch: concurrency: - group: ${{ github.action_path }}-${{ github.ref }}-build-n-deploy-docs + group: ${{ github.action_path }}-${{ github.ref }}-release-docs cancel-in-progress: false jobs: - run-build-n-deploy-docs: + docs: strategy: fail-fast: false matrix: @@ -27,6 +26,7 @@ jobs: uses: actions/checkout@v3.6.0 with: fetch-depth: 0 + fetch-tags: true - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4.7.0 @@ -35,16 +35,18 @@ jobs: architecture: "x64" - name: Install Poetry - run: pip install poetry==1.6.1 + run: pip install poetry==1.8.4 + + - name: Install base dependencies + run: poetry install --no-cache - - name: Install dependencies - run: poetry install --with=docs --no-cache --sync + - name: Prepare environment for docs deploy + run: poetry run poe prepare-deploy-docs - name: Configure Git run: | git config user.name github-actions git config user.email argmaster.world@gmail.com - - name: Run build & deploy documentation - run: | - poetry run mike deploy --push --update-aliases $(poetry version | awk '{ print $2 }') latest -F mkdocs.yaml + - name: Deploy documentation + run: poetry run python -m scripts.deploy_docs diff --git a/poetry.lock b/poetry.lock index d3853e24..12b93e5c 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1386,24 +1386,28 @@ files = [ [[package]] name = "mike" -version = "1.1.2" +version = "2.1.3" description = "Manage multiple versions of your MkDocs-powered documentation" optional = false python-versions = "*" files = [ - {file = "mike-1.1.2-py3-none-any.whl", hash = "sha256:4c307c28769834d78df10f834f57f810f04ca27d248f80a75f49c6fa2d1527ca"}, - {file = "mike-1.1.2.tar.gz", hash = "sha256:56c3f1794c2d0b5fdccfa9b9487beb013ca813de2e3ad0744724e9d34d40b77b"}, + {file = "mike-2.1.3-py3-none-any.whl", hash = "sha256:d90c64077e84f06272437b464735130d380703a76a5738b152932884c60c062a"}, + {file = "mike-2.1.3.tar.gz", hash = "sha256:abd79b8ea483fb0275b7972825d3082e5ae67a41820f8d8a0dc7a3f49944e810"}, ] [package.dependencies] -jinja2 = "*" +importlib-metadata = "*" +importlib-resources = "*" +jinja2 = ">=2.7" mkdocs = ">=1.0" +pyparsing = ">=3.0" pyyaml = ">=5.1" +pyyaml-env-tag = "*" verspec = "*" [package.extras] -dev = ["coverage", "flake8 (>=3.0)", "shtab"] -test = ["coverage", "flake8 (>=3.0)", "shtab"] +dev = ["coverage", "flake8 (>=3.0)", "flake8-quotes", "shtab"] +test = ["coverage", "flake8 (>=3.0)", "flake8-quotes", "shtab"] [[package]] name = "mkdocs" @@ -3466,4 +3470,4 @@ svg = ["drawsvg"] [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "d451541de65243e49b45548fa1f82237aab47c3678cfa30e9c1e8e34f9e9d946" +content-hash = "b5ca899c5906ae3eb9803586124090f868303817df8341ae05a54dd80b1d8949" diff --git a/pyproject.toml b/pyproject.toml index 09d2863a..c9592e93 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "pygerber" version = "2.4.2" -description = "Parsing, formatting and rendering toolkit for Gerber X3 file format" +description = "Parsing and rendering toolkit for Gerber X3 file format" authors = ["Krzysztof Wisniewski "] license = "MIT" readme = "README.md" @@ -104,7 +104,7 @@ mkdocs-macros-plugin = "^1.0.2" mkdocs-gen-files = "^0.5.0" pygments = "^2.15.1" pymdown-extensions = "^10.3" -mike = "^1.1.2" +mike = "^2" black = "^24.4.0" [tool.poetry.extras] diff --git a/scripts/deploy_docs.py b/scripts/deploy_docs.py new file mode 100644 index 00000000..db043c77 --- /dev/null +++ b/scripts/deploy_docs.py @@ -0,0 +1,65 @@ +from __future__ import annotations + +import sys + +import click +import dulwich +import dulwich.porcelain +import dulwich.repo +from mike.driver import main as mike_main +from packaging.version import Version +from test import THIS_DIRECTORY + +import pygerber + + +@click.command() +@click.option("--is-dev", is_flag=True, default=False) +@click.option("--check-only", is_flag=True, default=False) +def main(*, is_dev: bool, check_only: bool) -> None: + version = Version(pygerber.__version__) + + is_unstable = version.is_devrelease or version.is_prerelease + aliases = [] + + repo = dulwich.repo.Repo((THIS_DIRECTORY / ".." / ".git").as_posix()) + versions = [Version(t.decode("utf-8")) for t in dulwich.porcelain.tag_list(repo)] + + if not is_dev: + aliases.append(pygerber.__version__) + + latest_unstable = find_latest_unstable(versions) + + if version > latest_unstable: + aliases.append("latest") + + latest_stable = find_latest_stable(versions) + + if not is_unstable and version > latest_stable: + aliases.append("stable") + + else: + aliases.append("dev") + + print("Aliases:", aliases) # noqa: T201 + if check_only: + return + + sys_argv_original = sys.argv.copy() + + sys.argv = ["mike", "deploy", "--push", "--update-aliases", *aliases] + mike_main() + + sys.argv = sys_argv_original + + +def find_latest_stable(versions: list[Version]) -> Version: + return max(filter(lambda v: not (v.is_devrelease or v.is_prerelease), versions)) + + +def find_latest_unstable(versions: list[Version]) -> Version: + return max(filter(lambda v: (v.is_devrelease or v.is_prerelease), versions)) + + +if __name__ == "__main__": + main() diff --git a/test/__init__.py b/test/__init__.py index e69de29b..211405ce 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -0,0 +1,6 @@ +from __future__ import annotations + +from pathlib import Path + +THIS_FILE = Path(__file__) +THIS_DIRECTORY = THIS_FILE.parent