Commit 93921194 authored by Cooper Lees's avatar Cooper Lees Committed by Facebook GitHub Bot

Allow a project to have Actions run on all branches

Summary:
- I find the ability to make a branch and play with CI on GitHub super handy
- Removing the `- master` limitation gives me this ability

Reviewed By: yi-xian

Differential Revision: D22771835

fbshipit-source-id: 8e8839cb860ab4d1dfa0dda590afaf165127f60d
parent 1e3603df
...@@ -723,6 +723,15 @@ class TestCmd(ProjectCmdBase): ...@@ -723,6 +723,15 @@ class TestCmd(ProjectCmdBase):
@cmd("generate-github-actions", "generate a GitHub actions configuration") @cmd("generate-github-actions", "generate a GitHub actions configuration")
class GenerateGitHubActionsCmd(ProjectCmdBase): 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): def run_project_cmd(self, args, loader, manifest):
platforms = [ platforms = [
HostType("linux", "ubuntu", "18"), HostType("linux", "ubuntu", "18"),
...@@ -733,15 +742,17 @@ class GenerateGitHubActionsCmd(ProjectCmdBase): ...@@ -733,15 +742,17 @@ class GenerateGitHubActionsCmd(ProjectCmdBase):
for p in platforms: for p in platforms:
self.write_job_for_platform(p, args) self.write_job_for_platform(p, args)
def write_job_for_platform(self, platform, args): # TODO: Break up complex function
def write_job_for_platform(self, platform, args): # noqa: C901
build_opts = setup_build_options(args, platform) build_opts = setup_build_options(args, platform)
ctx_gen = build_opts.get_context_generator() ctx_gen = build_opts.get_context_generator()
loader = ManifestLoader(build_opts, ctx_gen) loader = ManifestLoader(build_opts, ctx_gen)
manifest = loader.load_manifest(args.project) manifest = loader.load_manifest(args.project)
manifest_ctx = loader.ctx_gen.get_context(manifest.name) 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
# Some projects don't do anything "useful" as a leaf project, only # 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 # as a dep for a leaf project. Check for those here; we don't want
# to waste the effort scheduling them on CI. # to waste the effort scheduling them on CI.
# We do this by looking at the builder type in the manifest file # We do this by looking at the builder type in the manifest file
# rather than creating a builder and checking its type because we # rather than creating a builder and checking its type because we
...@@ -785,13 +796,7 @@ class GenerateGitHubActionsCmd(ProjectCmdBase): ...@@ -785,13 +796,7 @@ class GenerateGitHubActionsCmd(ProjectCmdBase):
f""" f"""
name: {job_name} name: {job_name}
on: on:{run_on}
push:
branches:
- master
pull_request:
branches:
- master
jobs: jobs:
""" """
...@@ -891,6 +896,11 @@ jobs: ...@@ -891,6 +896,11 @@ jobs:
parser.add_argument( parser.add_argument(
"--output-dir", help="The directory that will contain the yml files" "--output-dir", help="The directory that will contain the yml files"
) )
parser.add_argument(
"--run-on-all-branches",
action="store_true",
help="Allow CI to fire on all branches - Handy for testing",
)
parser.add_argument( parser.add_argument(
"--ubuntu-version", default="18.04", help="Version of Ubuntu to use" "--ubuntu-version", default="18.04", help="Version of Ubuntu to use"
) )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment