From a1c00f89dae2437286b298af737d56e14bd6caba Mon Sep 17 00:00:00 2001 From: "Zeyi (Rice) Fan" Date: Thu, 2 Sep 2021 12:42:33 -0700 Subject: [PATCH] add support to custom main branch name Summary: This diff adds support to customize main branch name when generating GitHub Actions. Differential Revision: D30679305 fbshipit-source-id: 0fc7eb1c97c27e2b42e60cc1ab69a48ab93b93fa --- build/fbcode_builder/getdeps.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/build/fbcode_builder/getdeps.py b/build/fbcode_builder/getdeps.py index 1b539735f..66c008fe5 100755 --- a/build/fbcode_builder/getdeps.py +++ b/build/fbcode_builder/getdeps.py @@ -772,13 +772,6 @@ class TestCmd(ProjectCmdBase): @cmd("generate-github-actions", "generate a GitHub actions configuration") class GenerateGitHubActionsCmd(ProjectCmdBase): RUN_ON_ALL = """ [push, pull_request]""" - RUN_ON_DEFAULT = """ - push: - branches: - - master - pull_request: - branches: - - master""" def run_project_cmd(self, args, loader, manifest): platforms = [ @@ -790,6 +783,17 @@ class GenerateGitHubActionsCmd(ProjectCmdBase): for p in platforms: self.write_job_for_platform(p, args) + def get_run_on(self, args): + if args.run_on_all_branches: + return self.RUN_ON_ALL + return f""" + push: + branches: + - {args.main_branch} + pull_request: + branches: + - {args.main_branch}""" + # TODO: Break up complex function def write_job_for_platform(self, platform, args): # noqa: C901 build_opts = setup_build_options(args, platform) @@ -797,7 +801,7 @@ class GenerateGitHubActionsCmd(ProjectCmdBase): loader = ManifestLoader(build_opts, ctx_gen) manifest = loader.load_manifest(args.project) manifest_ctx = loader.ctx_gen.get_context(manifest.name) - run_on = self.RUN_ON_ALL if args.run_on_all_branches else self.RUN_ON_DEFAULT + run_on = self.get_run_on(args) # Some projects don't do anything "useful" as a leaf project, only # as a dep for a leaf project. Check for those here; we don't want @@ -945,6 +949,11 @@ jobs: parser.add_argument( "--ubuntu-version", default="18.04", help="Version of Ubuntu to use" ) + parser.add_argument( + "--main-branch", + default="master", + help="Main branch to trigger GitHub Action on", + ) def get_arg_var_name(args):