Skip to content

Commit

Permalink
Change how documentation deployments work
Browse files Browse the repository at this point in the history
  • Loading branch information
Argmaster committed Nov 11, 2024
1 parent 866764c commit 310afb4
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 3 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/deploy_dev_docs.yaml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
fetch-depth: 0
fetch-tags: true

- name: Set up Python ${{ matrix.python-version }}
uses: actions/[email protected]
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 [email protected]
- name: Deploy documentation
run: poetry run python -m scripts.deploy_docs --is-dev
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: Deploy Latest Documentation
name: Deploy Documentation

on:
push:
Expand All @@ -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:
Expand All @@ -26,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 @@ -48,4 +49,4 @@ jobs:
git config user.email [email protected]
- name: Deploy documentation
run: poetry run poe run deploy-latest-docs
run: poetry run python -m scripts.deploy_docs
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"dpmm",
"drawsvg",
"dtype",
"dulwich",
"ebnf",
"endwith",
"EOEX",
Expand All @@ -33,6 +34,7 @@
"indygo",
"inlinehilite",
"IPPOS",
"is_devrelease",
"kicad",
"levelname",
"linenums",
Expand Down
62 changes: 62 additions & 0 deletions scripts/deploy_docs.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 310afb4

Please sign in to comment.