-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathtasks.py
107 lines (85 loc) · 2.85 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import re
import shutil
import zipfile
from pathlib import Path
import tomli
from invoke import task
ROOT = Path(__file__).parent
DIST = ROOT / "dist"
def get_version() -> str:
manifest = ROOT / "Cargo.toml"
return tomli.loads(manifest.read_bytes().decode("utf-8"))["package"]["version"]
@task
def clean(ctx):
if DIST.exists():
shutil.rmtree(DIST, ignore_errors=True)
DIST.mkdir()
@task
def legal(ctx):
version = get_version()
txt_name = f"shawl-v{version}-legal.txt"
txt_path = DIST / txt_name
try:
ctx.run(f'cargo lichking bundle --file "{txt_path}"', hide=True)
except Exception:
pass
raw = txt_path.read_text("utf8")
normalized = re.sub(r"C:\\Users\\[^\\]+", "~", raw)
txt_path.write_text(normalized, "utf8")
zip_path = DIST / f"shawl-v{version}-legal.zip"
with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zip:
zip.write(txt_path, txt_name)
@task
def docs(ctx):
docs = Path(__file__).parent / "docs"
cli = docs / "cli.md"
commands = [
"--help",
"add --help",
"run --help",
]
lines = [
"This is the raw help text for the command line interface.",
]
for command in commands:
output = ctx.run(f"cargo run -- {command}")
lines.append("")
lines.append(f"## `{command}`")
lines.append("```")
for line in output.stdout.splitlines():
lines.append(line.rstrip())
lines.append("```")
if not docs.exists():
docs.mkdir()
cli.unlink()
with cli.open("a") as f:
for line in lines:
f.write(line + "\n")
@task
def prerelease(ctx):
# Make sure that the lock file has the new version
ctx.run("cargo build")
clean(ctx)
legal(ctx)
docs(ctx)
@task
def release(ctx):
version = get_version()
ctx.run(f'git commit -m "Release v{version}"')
ctx.run(f'git tag v{version} -m "Release"')
ctx.run("git push")
ctx.run("git push --tags")
@task
def release_winget(ctx, target="/git/_forks/winget-pkgs"):
target = Path(target)
version = get_version()
with ctx.cd(target):
ctx.run("git checkout master")
ctx.run("git pull upstream master")
ctx.run(f"git checkout -b mtkennerly.shawl-{version}")
ctx.run(f"wingetcreate update mtkennerly.shawl --version {version} --urls https://github.com/mtkennerly/shawl/releases/download/v{version}/shawl-v{version}-win64.zip https://github.com/mtkennerly/shawl/releases/download/v{version}/shawl-v{version}-win32.zip")
ctx.run(f"code --wait manifests/m/mtkennerly/shawl/{version}/mtkennerly.shawl.locale.en-US.yaml")
ctx.run(f"winget validate --manifest manifests/m/mtkennerly/shawl/{version}")
ctx.run("git add .")
ctx.run(f'git commit -m "mtkennerly.shawl version {version}"')
ctx.run("git push origin HEAD")