154 lines
4.9 KiB
Python
Executable file
154 lines
4.9 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
import os
|
|
import shutil
|
|
import contextlib
|
|
import re
|
|
import tomllib
|
|
import subprocess
|
|
import sys
|
|
import argparse
|
|
|
|
from git import Repo
|
|
|
|
@contextlib.contextmanager
|
|
def working_dir(d):
|
|
cwd = os.getcwd()
|
|
os.chdir(d)
|
|
try:
|
|
yield
|
|
finally:
|
|
os.chdir(cwd)
|
|
|
|
def write_job_output(name, value):
|
|
with open(os.environ["FORGEJO_OUTPUT"], "a") as f:
|
|
f.write(f"{name}={value}\n")
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("step")
|
|
parser.add_argument("-v", "--version")
|
|
args = parser.parse_args()
|
|
|
|
with open("release.toml", "rb") as f:
|
|
config = tomllib.load(f)
|
|
|
|
if args.step == "start":
|
|
start(config)
|
|
elif args.step == "openbsd":
|
|
with working_dir("local/openbsd"):
|
|
openbsd(config, args)
|
|
elif args.step == "netbsd":
|
|
with working_dir("local/netbsd"):
|
|
netbsd(config, args)
|
|
|
|
def start(config):
|
|
print(f"Dist release: %s" % config['distversion'])
|
|
|
|
if not os.path.exists("local"):
|
|
Repo.clone_from("https://code.kat5.dev/katie/continuwuity-bsd.git", "local")
|
|
print("Cloned local repo")
|
|
|
|
repo = Repo("local")
|
|
release_branch = repo.create_head(f"release-%s" % config['distversion'], "main")
|
|
repo.head.reference = release_branch
|
|
repo.head.reset(index=True, working_tree=True)
|
|
print(f"Created %s branch" % release_branch.name)
|
|
write_job_output("branch", release_branch.name)
|
|
|
|
with working_dir("local/freebsd"):
|
|
freebsd(config)
|
|
|
|
print("Processed freebsd/")
|
|
|
|
repo.index.add("freebsd/Makefile")
|
|
repo.index.add("freebsd/distinfo")
|
|
commit = repo.index.commit(f"freebsd: update to %s" % config['distversion'])
|
|
|
|
print(f"Committed %s" % commit.hexsha)
|
|
|
|
def freebsd(config):
|
|
with open("Makefile", "r") as f:
|
|
makefile = f.read()
|
|
|
|
makefile = re.sub("^(DISTVERSION=\\W+).+$", f"\\g<1>%s" % config['distversion'], makefile, flags=re.MULTILINE)
|
|
|
|
with open("Makefile", "w") as f:
|
|
f.write(makefile)
|
|
|
|
subp = subprocess.run(["make", "-V", "PKGVERSION"], capture_output=True, text=True)
|
|
assert subp.returncode == 0
|
|
pkgversion = subp.stdout.strip()
|
|
print(f"New package version is {pkgversion}")
|
|
write_job_output("version", pkgversion)
|
|
|
|
subp = subprocess.run(["make", "makesum"], capture_output=True, text=True)
|
|
print(subp.stdout)
|
|
print(subp.stderr)
|
|
assert subp.returncode == 0
|
|
|
|
def openbsd(config, args):
|
|
with open("Makefile", "r") as f:
|
|
makefile = f.read()
|
|
|
|
print(f"Updating OpenBSD package to {args.version} (%s)" % config['distversion'])
|
|
|
|
makefile = re.sub("^(V=\\W+).+$", f"\\g<1>%s" % args.version, makefile, flags=re.MULTILINE)
|
|
makefile = re.sub("^(DIST_V=\\W+).+$", f"\\g<1>%s" % config['distversion'], makefile, flags=re.MULTILINE)
|
|
|
|
with open("Makefile", "w") as f:
|
|
f.write(makefile)
|
|
|
|
shutil.copytree(".", os.path.join(os.environ["PORTSDIR"], "net", "continuwuity"))
|
|
|
|
with working_dir(os.path.join(os.environ["PORTSDIR"], "net", "continuwuity")):
|
|
subp = subprocess.run(["make", "makesum"], capture_output=True, text=True)
|
|
print(subp.stdout)
|
|
print(subp.stderr)
|
|
assert subp.returncode == 0
|
|
|
|
shutil.copy(os.path.join(os.environ["PORTSDIR"], "net", "continuwuity", "distinfo"), ".")
|
|
|
|
repo = Repo("..")
|
|
repo.index.add("openbsd/Makefile")
|
|
repo.index.add("openbsd/distinfo")
|
|
commit = repo.index.commit(f"openbsd: update to %s" % config['distversion'])
|
|
|
|
print(f"Committed {commit.hexsha}")
|
|
|
|
def netbsd(config, args):
|
|
with open("Makefile", "r") as f:
|
|
makefile = f.read()
|
|
|
|
print(f"Updating NetBSD package to {args.version} (%s)" % config['distversion'])
|
|
|
|
makefile = re.sub("^(V=\\W+).+$", f"\\g<1>%s" % args.version, makefile, flags=re.MULTILINE)
|
|
makefile = re.sub("^(DIST_V=\\W+).+$", f"\\g<1>%s" % config['distversion'], makefile, flags=re.MULTILINE)
|
|
|
|
with open("Makefile", "w") as f:
|
|
f.write(makefile)
|
|
|
|
shutil.copytree(".", os.path.join(os.environ["PORTSDIR"], "net", "continuwuity"))
|
|
|
|
# idk why this has to run twice, but the first time it removes the files from distinfo
|
|
# and then readds them the second time.
|
|
# it works correctly if I do everything by hand, so there's probably something obvious.
|
|
for i in range(0, 2):
|
|
with working_dir(os.path.join(os.environ["PORTSDIR"], "net", "continuwuity")):
|
|
subp = subprocess.run(["make", "makesum"], capture_output=True, text=True)
|
|
print(subp.stdout)
|
|
print(subp.stderr)
|
|
assert subp.returncode == 0
|
|
|
|
shutil.copy(os.path.join(os.environ["PORTSDIR"], "net", "continuwuity", "distinfo"), ".")
|
|
|
|
repo = Repo("..")
|
|
repo.index.add("netbsd/Makefile")
|
|
repo.index.add("netbsd/distinfo")
|
|
commit = repo.index.commit(f"netbsd: update to %s" % config['distversion'])
|
|
|
|
print(f"Committed {commit.hexsha}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|