|
| 1 | +import nox |
| 2 | +import shutil |
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +# Default tag for docker images |
| 6 | +TAG = "latest" |
| 7 | + |
| 8 | + |
| 9 | +@nox.session |
| 10 | +def image(session: nox.Session) -> None: |
| 11 | + """Build docker image""" |
| 12 | + session.run("docker", "build", "-t", f"gitstats:{TAG}", ".", external=True) |
| 13 | + |
| 14 | + |
| 15 | +@nox.session |
| 16 | +def publish_image(session: nox.Session) -> None: |
| 17 | + """Publish docker image to ghcr""" |
| 18 | + image(session) # Build the image first |
| 19 | + session.run( |
| 20 | + "docker", |
| 21 | + "tag", |
| 22 | + f"gitstats:{TAG}", |
| 23 | + f"ghcr.io/shenxianpeng/gitstats:{TAG}", |
| 24 | + external=True, |
| 25 | + ) |
| 26 | + session.run("docker", "push", f"ghcr.io/shenxianpeng/gitstats:{TAG}", external=True) |
| 27 | + |
| 28 | + |
| 29 | +@nox.session(name="install-deps") |
| 30 | +def install_deps(session: nox.Session) -> None: |
| 31 | + """Install gnuplot""" |
| 32 | + session.run("sudo", "apt", "update", "-y", external=True) |
| 33 | + session.run("sudo", "apt", "install", "gnuplot", "-y", external=True) |
| 34 | + |
| 35 | + |
| 36 | +@nox.session |
| 37 | +def build(session: nox.Session) -> None: |
| 38 | + """Generate gitstats report and json file""" |
| 39 | + report_dir = Path("test-report") |
| 40 | + if report_dir.exists(): |
| 41 | + shutil.rmtree(report_dir) |
| 42 | + session.install("--upgrade", "pip") |
| 43 | + session.install("-e", ".") |
| 44 | + session.run("gitstats", ".", str(report_dir), "-f", "json", external=True) |
| 45 | + |
| 46 | + |
| 47 | +@nox.session |
| 48 | +def preview(session: nox.Session) -> None: |
| 49 | + """Preview gitstats report in local""" |
| 50 | + build(session) # Generate report first |
| 51 | + session.run( |
| 52 | + "python3", "-m", "http.server", "8000", "-d", "test-report", external=True |
| 53 | + ) |
0 commit comments