Repository navigation
Expand file tree
/
Copy pathexport.py
More file actions
executable file
·122 lines (109 loc) · 3.21 KB
/
Copy pathexport.py
File metadata and controls
executable file
·122 lines (109 loc) · 3.21 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python3
import os
from argparse import ArgumentParser
from pathlib import Path
from downstream.updater import Updater
from downstream.util import run
EXIT_EMPTY = 10
class Args:
downstream: Path
subrepo: str
push: str | None
branch: str
ssh: bool
message: str
onto: str | None
update_toolchains: bool
edit_lakefile: list[list[str]] | None
update_manifests: bool
fail_if_empty: bool
def main() -> None:
parser = ArgumentParser()
parser.add_argument("downstream", type=Path)
parser.add_argument("subrepo", type=str)
parser.add_argument(
"-p",
"--push",
type=str,
metavar="OWNER/REPO",
help="push the changes to this GitHub repo, given by its full name",
)
parser.add_argument(
"-b",
"--branch",
type=str,
default="downstream-export",
help="branch to push to (requires --push)",
)
parser.add_argument(
"-s",
"--ssh",
action="store_true",
help="push using SSH instead of HTTPS (requires --push)",
)
parser.add_argument(
"-m",
"--message",
type=str,
default="chore: nightly adaptations",
help="commit message for the changes",
)
parser.add_argument(
"-o",
"--onto",
type=str,
metavar="SHA",
help="create the export commit on top of this commit instead of the base commit (must be available locally)",
)
parser.add_argument(
"-t",
"--update-toolchains",
action="store_true",
help="set lean-toolchain files to the downstream toolchain used at time of export",
)
parser.add_argument(
"-e",
"--edit-lakefile",
nargs=2,
action="append",
metavar=("PATTERN", "REPLACEMENT"),
help="""
replace a regex in all lakefiles (can be given multiple times).
'<REPO sha>' in the replacement is replaced by REPO's last known sha,
'<REPO FIELD>' by FIELD (source_url, source_rev, target_url, target_rev)
from REPO's entry in repos.toml
""",
)
parser.add_argument(
"-u",
"--update-manifests",
action="store_true",
help="run `lake update` for every manifest",
)
parser.add_argument(
"-E",
"--fail-if-empty",
action="store_true",
help="exit with a nonzero exit code if there were no adaptations to commit",
)
args = parser.parse_args(namespace=Args())
os.chdir(args.downstream)
updater = Updater()
subrepo = updater.subrepos_by_name[args.subrepo]
run("git", "switch", "--detach", "HEAD")
committed = updater.export(
subrepo,
args.message,
onto=args.onto,
update_toolchains=args.update_toolchains,
lakefile_edits=[(p, r) for p, r in args.edit_lakefile or []],
update_manifests=args.update_manifests,
)
if args.push:
prefix = "git@github.com:" if args.ssh else "https://github.com/"
url = f"{prefix}{args.push}.git"
run("git", "push", url, f"HEAD:{args.branch}")
if args.fail_if_empty and committed.empty:
raise SystemExit(EXIT_EMPTY)
if __name__ == "__main__":
main()