diff --git a/packaging/nightly-release-tests.py b/packaging/nightly-release-tests.py index d8c86d36a2..9738b641bd 100755 --- a/packaging/nightly-release-tests.py +++ b/packaging/nightly-release-tests.py @@ -110,7 +110,7 @@ def assert_caller_secrets(source, job_name, names): for value, children in (*root.values(), *job.values()): outside_map = "\n".join([value or "", *children]) # Scan all remaining text: quoted braces can appear before a secret reference. - if re.search(r"(?im)^\s*environment:|\bsecrets\b", outside_map): + if re.search(r"(?im)(?:^\s*environment:)|(?:\bsecrets\b)", outside_map): raise ValueError("secret bindings belong only in the signer map") @@ -600,10 +600,13 @@ def app_workflows(): return {path.name: path.read_text() for path in sorted((ROOT / ".github/workflows").glob("*.y*ml"))} -WORKFLOW_KEY = re.compile(r'''("(?:[^"\\]|\\.)*"|'(?:[^']|'')*'|[^\s'"#{}\[\],:&*!|>%@`?-][^:#,{}]*?|-[^\s:#][^:#,{}]*?)\s*:(?:\s+(.*))?$''') +WORKFLOW_KEY = re.compile( + r'''((?:"(?:[^"\\]|\\.)*"|'(?:[^']|'')*')[ \t]*|[^\s'"#{}\[\],:&*!|>%@`?-][^:#,{}]*|-[^\s:#][^:#,{}]*):(?:[ \t]+(.*))?$''' +) def _workflow_key(text): + text = text.rstrip() if text.startswith('"'): return None if "\\" in text else text[1:-1] if text.startswith("'"): @@ -620,7 +623,10 @@ def _workflow_value(text): if text.startswith("'"): quoted = re.match(r"'((?:[^']|'')*)'\s*(?:#.*)?$", text) return None if quoted is None else quoted.group(1).replace("''", "'") - return re.split(r"\s+#", text, maxsplit=1)[0].strip() + for idx, ch in enumerate(text): + if ch == "#" and idx > 0 and text[idx - 1].isspace(): + return text[:idx].rstrip() + return text def _strip_comment(text):