diff --git a/.github/workflows/deploy_dev_docs.yaml b/.github/workflows/deploy_dev_docs.yaml new file mode 100644 index 00000000..d91d2158 --- /dev/null +++ b/.github/workflows/deploy_dev_docs.yaml @@ -0,0 +1,52 @@ +--- +name: Deploy Development Documentation + +on: + push: + branches: + - main + workflow_dispatch: + +concurrency: + group: ${{ github.action_path }}-${{ github.ref }}-dev-docs + cancel-in-progress: false + +jobs: + docs: + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + python-version: ["3.8"] + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout code + 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 + with: + python-version: ${{ matrix.python-version }} + architecture: "x64" + + - name: Install Poetry + run: pip install poetry==1.8.4 + + - name: Install base dependencies + run: poetry install --no-cache + + - 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: Deploy documentation + run: poetry run python -m scripts.deploy_docs --is-dev diff --git a/.github/workflows/deploy_latest_docs.yaml b/.github/workflows/deploy_release_docs.yaml similarity index 85% rename from .github/workflows/deploy_latest_docs.yaml rename to .github/workflows/deploy_release_docs.yaml index deb3e669..de2f6c2e 100644 --- a/.github/workflows/deploy_latest_docs.yaml +++ b/.github/workflows/deploy_release_docs.yaml @@ -1,5 +1,5 @@ --- -name: Deploy Latest Documentation +name: Deploy Documentation on: push: @@ -8,7 +8,7 @@ on: workflow_dispatch: concurrency: - group: ${{ github.action_path }}-${{ github.ref }}-latest-docs + group: ${{ github.action_path }}-${{ github.ref }}-release-docs cancel-in-progress: false jobs: @@ -26,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 @@ -48,4 +49,4 @@ jobs: git config user.email argmaster.world@gmail.com - name: Deploy documentation - run: poetry run poe run deploy-latest-docs + run: poetry run python -m scripts.deploy_docs diff --git a/.vscode/settings.json b/.vscode/settings.json index 5ccb827c..3b0d30ad 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -20,6 +20,7 @@ "dpmm", "drawsvg", "dtype", + "dulwich", "ebnf", "endwith", "EOEX", @@ -33,6 +34,7 @@ "indygo", "inlinehilite", "IPPOS", + "is_devrelease", "kicad", "levelname", "linenums", diff --git a/scripts/deploy_docs.py b/scripts/deploy_docs.py new file mode 100644 index 00000000..5a70127a --- /dev/null +++ b/scripts/deploy_docs.py @@ -0,0 +1,62 @@ +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) +def main(*, is_dev: 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 + + 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()