#!/usr/bin/env python3 # Copyright 2023 Greptime Team # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Admit `/ci` comments and dispatch a pinned draft-PR CI workflow.""" import json, os, re, sys, urllib.request COMMAND = re.compile(r'^/ci(?:\s+(.+))?$') OPTIONS = { '': ('rust.yml,integration.yml,checks.yml,docs.yml', 'none', 'standard CI'), 'help': (None, 'none', ''), 'rust': ('rust.yml', 'none', 'Rust CI'), 'integration': ('integration.yml', 'none', 'Integration CI (without fuzz)'), 'checks': ('checks.yml', 'none', 'Checks'), 'docs': ('docs.yml', 'none', 'Docs CI'), 'fuzz standalone': ('integration.yml', 'standalone', 'standalone fuzz'), 'fuzz distributed': ('integration.yml', 'distributed', 'distributed fuzz'), 'fuzz chaos': ('integration.yml', 'chaos', 'chaos fuzz'), 'fuzz all': ('integration.yml', 'all', 'all fuzz'), } HELP = '''Available draft-PR CI commands:\n\n- `/ci` or `/ci rust` — Rust CI\n- `/ci integration` — integration CI without fuzz\n- `/ci checks` or `/ci docs`\n- `/ci fuzz standalone|distributed|chaos`\n- `/ci fuzz all` — all fuzz suites (admin only)\n\nCommands require repository admin permission and a same-repository open draft PR. CI is pinned to the current head SHA; comment again after a push.''' def api(path): req=urllib.request.Request(os.environ['GITHUB_API_URL']+path, headers={'Authorization':'Bearer '+os.environ['GITHUB_TOKEN'],'Accept':'application/vnd.github+json'}) with urllib.request.urlopen(req) as r: return json.load(r) def out(**kw): with open(os.environ["GITHUB_OUTPUT"], "a") as file: for key, value in kw.items(): value = str(value) if "\n" in value: file.write(f"{key}<