Skip to content

Commit

Permalink
Update documentation deployment flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Argmaster committed Nov 11, 2024
1 parent b9d1988 commit 23399f7
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -27,6 +26,7 @@ jobs:
uses: actions/[email protected]
with:
fetch-depth: 0
fetch-tags: true

- name: Set up Python ${{ matrix.python-version }}
uses: actions/[email protected]
Expand All @@ -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 [email protected]
- 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
18 changes: 11 additions & 7 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
license = "MIT"
readme = "README.md"
Expand Down Expand Up @@ -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]
Expand Down
65 changes: 65 additions & 0 deletions scripts/deploy_docs.py
Original file line number Diff line number Diff line change
@@ -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()
6 changes: 6 additions & 0 deletions test/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from __future__ import annotations

from pathlib import Path

THIS_FILE = Path(__file__)
THIS_DIRECTORY = THIS_FILE.parent

0 comments on commit 23399f7

Please sign in to comment.