forked from opsmill/infrahub-demo-edge
-
Notifications
You must be signed in to change notification settings - Fork 3
/
tasks.py
34 lines (24 loc) · 1.15 KB
/
tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""Replacement for Makefile."""
import os
from typing import Tuple
from invoke import Context, task # type: ignore
PROJECT_NAME = "infrahub-demo-edge"
def git_info(context: Context) -> Tuple[str, str]:
"""Return the name of the current branch and hash of the current commit."""
branch_name = context.run("git rev-parse --abbrev-ref HEAD", hide=True, pty=False)
hash = context.run("git rev-parse --short HEAD", hide=True, pty=False)
return branch_name.stdout.strip(), hash.stdout.strip()
@task
def generate_archive(context: Context):
branch, commit = git_info(context=context) # noqa: F841
directory_name = os.path.basename(os.path.dirname(os.path.realpath(__file__)))
package_name = f"{PROJECT_NAME}-{commit[:8]}.tar.gz"
commands = [
f"rm -rf /tmp/{PROJECT_NAME}",
f"cp -a ../{directory_name} /tmp/{PROJECT_NAME}",
f"git --git-dir /tmp/{PROJECT_NAME}/.git remote remove origin",
f"tar -C /tmp -czf {package_name} {PROJECT_NAME}",
]
for command in commands:
result = context.run(command=command, pty=True) # noqa: F841
print(f"Package {package_name!r} generated successfully.")