Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Track html artifacts #37

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ repos:
language_version: python3
args:
- --max-line-length=88
- --ignore=E203,W503,BLK100
- --ignore=E203,W503,BLK100,TYP001
exclude: |
(?x)(
__init__.py
Expand Down
5 changes: 1 addition & 4 deletions laminci/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
__version__ = "0.13.1" # denote a pre-release for 0.1.0 with 0.1a1

from . import db, nox
from ._artifacts import upload_docs_artifact
from ._artifacts import upload_docs_artifact, upload_html_artifact
from ._docs import (
move_built_docs_to_docs_slash_project_slug,
move_built_docs_to_slash_project_slug,
)
from ._env import get_package_name, get_schema_handle

# backward compat
upload_docs_dir = upload_docs_artifact
39 changes: 26 additions & 13 deletions laminci/_artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import warnings
from pathlib import Path
from subprocess import run
from typing import Literal
from zipfile import ZipFile

from lamin_utils import logger
Expand All @@ -19,23 +20,32 @@ def zip_docs_dir(zip_filename: str) -> None:
zf.write(f, f.relative_to("./docs")) # add at root level


def zip_docs():
def zip_html_dir(zip_filename: str) -> None:
with ZipFile(zip_filename, "w") as zf:
for f in Path("./_build/html").glob("**/*"):
zf.write(f, f.relative_to("./_build/html")) # add at root level


def zip_files(type: Literal["docs", "html"]):
package_name = get_package_name()
zip_filename = f"{package_name}_docs.zip"
zip_docs_dir(zip_filename)
zip_filename = f"{package_name}_{type}.zip"
if type == "docs":
zip_docs_dir(zip_filename)
elif type == "html":
zip_html_dir(zip_filename)
return package_name, zip_filename


def upload_docs_artifact_aws() -> None:
package_name, zip_filename = zip_docs()
def upload_artifact_aws(type: Literal["docs", "html"]) -> None:
_, zip_filename = zip_files(type)
run(
f"aws s3 cp {zip_filename} s3://lamin-site-assets/docs/{zip_filename}",
f"aws s3 cp {zip_filename} s3://lamin-site-assets/{type}/{zip_filename}",
shell=True,
)


def upload_docs_artifact_lamindb() -> None:
package_name, zip_filename = zip_docs()
def upload_docs_artifact_lamindb(type: Literal["docs", "html"]) -> None:
package_name, zip_filename = zip_files(type)

import lamindb as ln

Expand All @@ -52,13 +62,16 @@ def upload_docs_artifact_lamindb() -> None:
ln.add(file)


def upload_html_artifact() -> None:
upload_artifact_aws(type="html")


def upload_docs_artifact(aws: bool = False) -> None:
if os.getenv("GITHUB_EVENT_NAME") not in {"push", "repository_dispatch"}:
logger.info("Only upload docs artifact for push event.")
logger.info("Only uploading docs artifact for push & repository_dispatch.")
return None

if aws:
upload_docs_artifact_aws()
upload_artifact_aws(type="docs")
else:
try:
# this is super ugly but necessary right now
Expand All @@ -69,8 +82,8 @@ def upload_docs_artifact(aws: bool = False) -> None:

import lamindb as ln # noqa

upload_docs_artifact_lamindb()
upload_docs_artifact_lamindb(type="docs")

except ImportError:
warnings.warn("Fall back to AWS")
upload_docs_artifact_aws()
upload_artifact_aws(type="docs")
6 changes: 3 additions & 3 deletions tests/test_artifacts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from laminci._artifacts import upload_docs_artifact_aws
from laminci._artifacts import upload_artifact_aws


def test_upload_docs_artifact_aws():
upload_docs_artifact_aws()
def test_upload_artifact_aws():
upload_artifact_aws(type="docs")
Loading