Skip to content

Commit 677f47d

Browse files
r-barnesmeta-codesync[bot]
authored andcommitted
Add tmate SSH debugging to generated GitHub Actions workflows
Summary: Add a workflow_dispatch input (tmate_enabled) to all generated workflows. When a workflow is manually dispatched with tmate_enabled=true and a step fails, a tmate SSH session is started for interactive debugging. Normal CI runs (push/PR) are completely unaffected. Reviewed By: bigfootjon Differential Revision: D96800077 fbshipit-source-id: 8e805446a9b58c35a6fe5c9df1ad6caf6a3ae07c
1 parent 7eb401f commit 677f47d

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

build/fbcode_builder/getdeps.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,15 @@ def run_project_cmd(self, args, loader, manifest):
10091009
class GenerateGitHubActionsCmd(ProjectCmdBase):
10101010
RUN_ON_ALL = """ [push, pull_request]"""
10111011

1012+
WORKFLOW_DISPATCH_TMATE = """
1013+
workflow_dispatch:
1014+
inputs:
1015+
tmate_enabled:
1016+
description: 'Start a tmate SSH session on failure'
1017+
required: false
1018+
default: false
1019+
type: boolean"""
1020+
10121021
def run_project_cmd(self, args, loader, manifest):
10131022
platforms = [
10141023
HostType("linux", "ubuntu", "24"),
@@ -1023,24 +1032,35 @@ def run_project_cmd(self, args, loader, manifest):
10231032

10241033
def get_run_on(self, args):
10251034
if args.run_on_all_branches:
1026-
return self.RUN_ON_ALL
1035+
return (
1036+
"""
1037+
push:
1038+
pull_request:"""
1039+
+ self.WORKFLOW_DISPATCH_TMATE
1040+
)
10271041
if args.cron:
10281042
if args.cron == "never":
10291043
return " {}"
10301044
elif args.cron == "workflow_dispatch":
1031-
return "\n workflow_dispatch"
1045+
return self.WORKFLOW_DISPATCH_TMATE
10321046
else:
1033-
return f"""
1047+
return (
1048+
f"""
10341049
schedule:
10351050
- cron: '{args.cron}'"""
1051+
+ self.WORKFLOW_DISPATCH_TMATE
1052+
)
10361053

1037-
return f"""
1054+
return (
1055+
f"""
10381056
push:
10391057
branches:
10401058
- {args.main_branch}
10411059
pull_request:
10421060
branches:
10431061
- {args.main_branch}"""
1062+
+ self.WORKFLOW_DISPATCH_TMATE
1063+
)
10441064

10451065
# TODO: Break up complex function
10461066
def write_job_for_platform(self, platform, args): # noqa: C901
@@ -1386,6 +1406,12 @@ def write_job_for_platform(self, platform, args): # noqa: C901
13861406
out.write(" if: always()\n")
13871407
out.write(" run: df -h\n")
13881408

1409+
out.write(" - name: Setup tmate session\n")
1410+
out.write(
1411+
" if: failure() && github.event_name == 'workflow_dispatch' && inputs.tmate_enabled\n"
1412+
)
1413+
out.write(" uses: mxschmitt/action-tmate@v3\n")
1414+
13891415
def setup_project_cmd_parser(self, parser):
13901416
parser.add_argument(
13911417
"--disallow-system-packages",

0 commit comments

Comments
 (0)