PluralKit/ci/run_ci.py

83 lines
1.9 KiB
Python
Raw Normal View History

2024-09-05 18:47:16 +09:00
#!/usr/bin/env python3
2024-09-05 19:17:25 +09:00
2024-09-06 13:06:17 +09:00
import os, sys, json, subprocess
2024-09-06 12:53:24 +09:00
dispatch_data = os.environ.get("DISPATCH_DATA")
def must_get_env(name):
val = os.environ.get(name)
if val == "":
raise "meow"
return val
def docker_build(data):
# file="", tags=[], root="/"
pass
def create_jobs():
modify_regexes = {
2024-09-06 13:08:50 +09:00
r'^ci/': "all",
2024-09-06 12:53:24 +09:00
2024-09-06 13:08:50 +09:00
r'^docs/': "bin_docs",
r'^dashboard/': "bin_dashboard",
2024-09-06 12:53:24 +09:00
2024-09-06 13:08:50 +09:00
r'\.rs$': "format_rs",
r'\.cs$': "format_cs",
2024-09-06 12:53:24 +09:00
2024-09-06 13:08:50 +09:00
r'^Cargo.lock': "all_rs",
2024-09-06 12:53:24 +09:00
2024-09-06 13:08:50 +09:00
r'^services/api': "bin_api",
2024-09-06 12:53:24 +09:00
# dispatch doesn't use libpk
2024-09-06 13:08:50 +09:00
r'^services/dispatch': "bin_dispatch",
r'^services/scheduled_tasks': "bin_scheduled_tasks",
2024-09-06 12:53:24 +09:00
# one image for all dotnet
2024-09-06 13:08:50 +09:00
r'^PluralKit\.': "bin_dotnet",
r'^Myriad': "bin_dotnet",
2024-09-06 12:53:24 +09:00
}
aliases = {
"all": ["bin_dotnet", "bin_api", "bin_dispatch", "bin_scheduled_tasks", "bin_dashboard"],
"all_rs": ["bin_api", "bin_dispatch"],
}
now = must_get_env("CUR_SHA")
before = must_get_env("OLD_SHA")
changed_files = subprocess.check_output(["git", "diff", "--name-only", before, now])
jobs = set([])
for key in modify_regexes.keys():
2024-09-06 12:54:34 +09:00
if true:
2024-09-06 12:53:24 +09:00
jobs = jobs | modify_regexes[key]
for key in changes:
if aliases.get(key) is not None:
jobs = jobs | aliases[key]
jobs = jobs - [key]
pass
2024-09-06 13:05:07 +09:00
def main():
2024-09-06 12:53:24 +09:00
print("hello from python!")
2024-09-06 13:08:50 +09:00
subprocess.run(["docker", "run", "--rm", "-i", "hello-world"], check=True)
2024-09-06 12:53:24 +09:00
2024-09-06 13:05:07 +09:00
return 0
2024-09-06 13:00:50 +09:00
if dispatch_data == "":
return create_jobs()
2024-09-06 12:53:24 +09:00
data = json.loads(dispatch_data)
match data.get("action"):
case "docker_build":
return docker_build(data.get("data"))
case "rustfmt":
2024-09-06 13:03:18 +09:00
pass
2024-09-06 12:53:24 +09:00
case "dotnet_format":
2024-09-06 13:03:18 +09:00
pass
2024-09-06 12:53:24 +09:00
case _:
print (f"data unknown: {dispatch_data}")
2024-09-06 13:05:07 +09:00
return 1
if __name__ == "__main__":
2024-09-06 13:06:17 +09:00
sys.exit(main())