Skip to content

Commit b72cbf7

Browse files
committed
Update fern workflows
1 parent ec49507 commit b72cbf7

5 files changed

Lines changed: 128 additions & 36 deletions

File tree

.github/triage/jax_toolbox_triage/args.py

Lines changed: 116 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import argparse
2+
import ast
23
import datetime
34
import getpass
45
import os
56
import pathlib
7+
import re
8+
import sys
69
import tempfile
710
import typing
811
import warnings
@@ -16,6 +19,90 @@
1619
optional_software = ["flax", "maxtext", "transformer-engine"]
1720

1821

22+
_INFO_LOG_ARGUMENTS_RE = re.compile(
23+
r"^\[INFO\]\s+\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}\s+Arguments:\s*$"
24+
)
25+
_INFO_LOG_ARGUMENT_RE = re.compile(
26+
r"^\[INFO\]\s+\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}\s+"
27+
r"(?P<name>[A-Za-z_][A-Za-z0-9_]*):\s*(?P<value>.*)$"
28+
)
29+
30+
31+
def logged_arg_value(s: str) -> typing.Any:
32+
try:
33+
return ast.literal_eval(s)
34+
except (SyntaxError, ValueError):
35+
return s
36+
37+
38+
def load_args_from_info_log(info_log: pathlib.Path) -> typing.Dict[str, str]:
39+
ret: typing.Dict[str, str] = {}
40+
in_arguments = False
41+
with info_log.open("r", encoding="utf-8") as f:
42+
for line in f:
43+
if not in_arguments:
44+
if _INFO_LOG_ARGUMENTS_RE.match(line):
45+
in_arguments = True
46+
continue
47+
match = _INFO_LOG_ARGUMENT_RE.match(line)
48+
if not match:
49+
if ret:
50+
break
51+
continue
52+
ret[match.group("name")] = match.group("value")
53+
if not ret:
54+
raise Exception(f"Could not read arguments from {info_log}")
55+
return ret
56+
57+
58+
def parser_actions_by_dest(parser: argparse.ArgumentParser) -> typing.Dict[str, argparse.Action]:
59+
return {
60+
action.dest: action
61+
for action in parser._actions
62+
if action.dest != argparse.SUPPRESS
63+
}
64+
65+
66+
def provided_arg_dests(
67+
parser: argparse.ArgumentParser, args: typing.Sequence[str]
68+
) -> typing.Set[str]:
69+
option_actions = {
70+
option: action for action in parser._actions for option in action.option_strings
71+
}
72+
ret: typing.Set[str] = set()
73+
i = 0
74+
while i < len(args):
75+
arg = args[i]
76+
if arg == "--":
77+
if i + 1 < len(args):
78+
ret.add("test_command")
79+
break
80+
option = arg.split("=", 1)[0]
81+
action = option_actions.get(option)
82+
if action is None:
83+
ret.add("test_command")
84+
break
85+
ret.add(action.dest)
86+
if "=" in arg or action.nargs == 0:
87+
i += 1
88+
elif action.nargs is None:
89+
i += 2
90+
elif isinstance(action.nargs, int):
91+
i += 1 + action.nargs
92+
else:
93+
i += 1
94+
return ret
95+
96+
97+
def coerce_logged_arg(
98+
action: argparse.Action, value: str
99+
) -> typing.Any:
100+
value = logged_arg_value(value)
101+
if isinstance(value, str) and action.type is not None:
102+
return action.type(value)
103+
return value
104+
105+
19106
def parse_cherry_picks(s: str) -> typing.Dict[str, typing.List[str]]:
20107
ret: typing.Dict[str, typing.List[str]] = {}
21108
for part in s.split(","):
@@ -128,9 +215,16 @@ def parse_args(args=None) -> argparse.Namespace:
128215
container. Careful use of this option, along with --start-date, --end-date and
129216
--threshold-days, allows the container-level search to be skipped.""",
130217
)
218+
parser.add_argument(
219+
"--no-skip-precondition-checks",
220+
dest="skip_precondition_checks",
221+
action="store_false",
222+
default=False,
223+
help="Re-enable precondition checks when restarting from a run that skipped them.",
224+
)
131225
parser.add_argument(
132226
"test_command",
133-
nargs="+",
227+
nargs="*",
134228
help="""
135229
Command to execute inside the container. This should be as targeted as
136230
possible.""",
@@ -273,6 +367,13 @@ def parse_args(args=None) -> argparse.Namespace:
273367
action="store_true",
274368
help="Exclude transformer-engine from the list of optional software to triage.",
275369
)
370+
version_search_args.add_argument(
371+
"--no-exclude-transformer-engine",
372+
dest="exclude_transformer_engine",
373+
action="store_false",
374+
default=False,
375+
help="Include transformer-engine when restarting from a run that excluded it.",
376+
)
276377
version_search_args.add_argument(
277378
"--transformer-engine-ccache-env",
278379
action="append",
@@ -316,7 +417,9 @@ def parse_args(args=None) -> argparse.Namespace:
316417
default="main",
317418
help="The name of the main branch (e.g. main) to derive cherry-picks from",
318419
)
319-
args = parser.parse_args(args=args)
420+
raw_args = sys.argv[1:] if args is None else list(args)
421+
provided_args = provided_arg_dests(parser, raw_args)
422+
args = parser.parse_args(args=raw_args)
320423
if args.restart:
321424
if args.output_prefix is None:
322425
raise Exception("--restart requires --output-prefix")
@@ -326,11 +429,21 @@ def parse_args(args=None) -> argparse.Namespace:
326429
raise Exception(
327430
f"--output-prefix must contain summary.json: {summary_file}"
328431
)
432+
info_log = args.output_prefix / "info.log"
433+
if not info_log.exists():
434+
raise Exception(f"--output-prefix must contain info.log: {info_log}")
435+
actions_by_dest = parser_actions_by_dest(parser)
436+
for arg, value in load_args_from_info_log(info_log).items():
437+
if arg in provided_args or arg not in actions_by_dest:
438+
continue
439+
setattr(args, arg, coerce_logged_arg(actions_by_dest[arg], value))
329440
else:
330441
if args.output_prefix is None:
331442
args.output_prefix = pathlib.Path(
332443
datetime.datetime.now().strftime("triage-%Y-%m-%d-%H-%M-%S")
333444
)
445+
if not args.test_command:
446+
raise Exception("test_command must be passed or restored from info.log")
334447

335448
assert args.container_runtime in {
336449
"docker",
@@ -426,3 +539,4 @@ def parse_args(args=None) -> argparse.Namespace:
426539
args.optional_software.remove("transformer-engine")
427540

428541
return args
542+

.github/workflows/fern-docs-ci.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
# Validates Fern docs configuration and checks for broken internal links on PRs.
22
# Runs without a FERN_TOKEN — suitable for untrusted forks.
3-
name: Fern Docs CI
3+
name: Fern Docs Validate
44

55
on:
6-
push:
7-
branches:
8-
- "pull-request/[0-9]+"
96
pull_request:
7+
types: [synchronize]
108
paths:
119
- 'docs/**'
1210
- 'fern/**'
1311
- 'package.json'
12+
- '.github/workflows/*fern*.yml'
1413

1514
jobs:
1615
validate:
1716
name: Validate docs
1817
runs-on: ubuntu-latest
1918
steps:
20-
- uses: actions/checkout@v4
19+
- uses: actions/checkout@v7
2120

22-
- uses: actions/setup-node@v4
23-
with:
24-
node-version: '20'
21+
- uses: actions/setup-node@v6
2522

2623
- name: Install dependencies
2724
run: npm install

.github/workflows/fern-docs-preview.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ on:
66
push:
77
branches:
88
- "pull-request/[0-9]+"
9-
pull_request:
109
paths:
1110
- 'docs/**'
1211
- 'fern/**'
1312
- 'package.json'
13+
- '.github/workflows/*fern*.yml'
1414

1515
jobs:
1616
preview:
@@ -19,11 +19,9 @@ jobs:
1919
permissions:
2020
pull-requests: write
2121
steps:
22-
- uses: actions/checkout@v4
22+
- uses: actions/checkout@v7
2323

24-
- uses: actions/setup-node@v4
25-
with:
26-
node-version: '20'
24+
- uses: actions/setup-node@v6
2725

2826
- name: Install dependencies
2927
run: npm install
@@ -47,9 +45,9 @@ jobs:
4745
uses: actions/github-script@v7
4846
with:
4947
script: |
50-
github.rest.issues.createComment({
48+
await github.rest.issues.createComment({
5149
issue_number: context.issue.number,
5250
owner: context.repo.owner,
5351
repo: context.repo.repo,
54-
body: '📖 **Docs preview:** ${{ steps.preview.outputs.url }}'
52+
body: '📖 [**Docs preview**](${{ steps.preview.outputs.url }})'
5553
})

.github/workflows/publish-fern-docs.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ jobs:
1717
name: Publish docs
1818
runs-on: ubuntu-latest
1919
steps:
20-
- uses: actions/checkout@v4
20+
- uses: actions/checkout@v7
2121

22-
- uses: actions/setup-node@v4
23-
with:
24-
node-version: '20'
22+
- uses: actions/setup-node@v6
2523

2624
- name: Install dependencies
2725
run: npm install

.gitignore

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)