|
| 1 | +import os |
| 2 | + |
| 3 | +import nox |
| 4 | + |
| 5 | +PROJECT_DIR = os.path.dirname(__file__) |
| 6 | +THEHIVE4PY_DIR = os.path.join(PROJECT_DIR, "thehive4py/") |
| 7 | +TESTS_DIR = os.path.join(PROJECT_DIR, "tests/") |
| 8 | + |
| 9 | +nox.options.default_venv_backend = "none" |
| 10 | +nox.options.tags = ["audit", "lint"] |
| 11 | + |
| 12 | + |
| 13 | +@nox.session(tags=["ci", "lint"]) |
| 14 | +def style(session: nox.Session): |
| 15 | + """Run style checks with flake8.""" |
| 16 | + session.run("flake8", THEHIVE4PY_DIR, TESTS_DIR) |
| 17 | + |
| 18 | + |
| 19 | +@nox.session(tags=["ci", "lint"]) |
| 20 | +def format(session: nox.Session): |
| 21 | + """Run format checks with black.""" |
| 22 | + session.run("black", "--check", THEHIVE4PY_DIR, TESTS_DIR) |
| 23 | + |
| 24 | + |
| 25 | +@nox.session(tags=["ci", "lint"]) |
| 26 | +def type(session: nox.Session): |
| 27 | + """Run type checks with mypy.""" |
| 28 | + session.run("mypy", "--install-types", "--non-interactive", THEHIVE4PY_DIR) |
| 29 | + |
| 30 | + |
| 31 | +@nox.session(tags=["ci", "audit"]) |
| 32 | +def cve(session: nox.Session): |
| 33 | + """Run cve checks with pip-audit.""" |
| 34 | + session.run("pip-audit", ".") |
| 35 | + |
| 36 | + |
| 37 | +@nox.session(tags=["ci", "audit"]) |
| 38 | +def security(session: nox.Session): |
| 39 | + """Run security checks with bandit.""" |
| 40 | + session.run("bandit", "-r", THEHIVE4PY_DIR) |
| 41 | + |
| 42 | + |
| 43 | +@nox.session(tags=["ci", "test"]) |
| 44 | +def test(session: nox.Session): |
| 45 | + """Run integration tests with pytest.""" |
| 46 | + |
| 47 | + if not session.posargs: |
| 48 | + session.run("pytest", "-v", "--cov") |
| 49 | + else: |
| 50 | + session.run("pytest", *session.posargs) |
| 51 | + |
| 52 | + |
| 53 | +@nox.session(tags=["cd", "build"]) |
| 54 | +def build(session: nox.Session): |
| 55 | + """Build thehive4py with the build module.""" |
| 56 | + session.run("rm", "-rf", "build/", "dist/") |
| 57 | + session.run("python", "-m", "build", "--sdist", "--wheel") |
| 58 | + |
| 59 | + |
| 60 | +@nox.session(tags=["cd", "upload"]) |
| 61 | +def upload(session: nox.Session): |
| 62 | + """Upload thehive4py to PyPI using twine.""" |
| 63 | + # TODO: change check to upload |
| 64 | + session.run("twine", "check", "dist/*") |
| 65 | + |
| 66 | + |
| 67 | +@nox.session(tags=["cd", "docs"], name="build-docs") |
| 68 | +def build_docs(session: nox.Session): |
| 69 | + """Build docs locally.""" |
| 70 | + session.run("mkdocs", "build", "--clean", "--strict") |
| 71 | + |
| 72 | + |
| 73 | +@nox.session(tags=["cd", "docs"], name="deploy-docs") |
| 74 | +def deploy_docs(session: nox.Session): |
| 75 | + """Deploy docs to gh-pages.""" |
| 76 | + session.run("mkdocs", "build", "--clean", "--strict") |
| 77 | + |
| 78 | + |
| 79 | +@nox.session(tags=["utils", "docs"], name="serve-docs") |
| 80 | +def serve_docs(session: nox.Session): |
| 81 | + """Serve docs locally.""" |
| 82 | + session.run("mkdocs", "serve", "--clean", "--strict") |
| 83 | + |
| 84 | + |
| 85 | +@nox.session(tags=["utils", "docs"], name="linkify-release-notes") |
| 86 | +def linkify_release_notes(session: nox.Session): |
| 87 | + """Linkify plain github release notes for the docs.""" |
| 88 | + session.run("./scripts/linkify_release_notes.py") |
| 89 | + |
| 90 | + |
| 91 | +@nox.session(tags=["cd", "docs"], name="check-release-notes") |
| 92 | +def check_release_notes(session: nox.Session): |
| 93 | + """Check release notes for deployment.""" |
| 94 | + session.run("./scripts/linkify_release_notes.py", "--check") |
| 95 | + session.run( |
| 96 | + "bash", |
| 97 | + "-c", |
| 98 | + r""" |
| 99 | + VERSION=$(grep -Po '(?<=version = ")[^"]*' pyproject.toml) |
| 100 | + if ! grep -qF "## $VERSION " "docs/release-notes.md"; then |
| 101 | + echo "No release notes found for version '$VERSION'" |
| 102 | + exit 1 |
| 103 | + else |
| 104 | + echo "Release notes found for version '$VERSION'" |
| 105 | + fi |
| 106 | + """, |
| 107 | + ) |
0 commit comments