Skip to content

Workflows Overview

A workflow is the core abstraction in Copybara. It defines the complete pipeline for moving code from one repository to another.

Copybara supports two main types of workflows:

The primary workflow type for syncing code between repositories:

core.workflow(
name = "export",
origin = git.origin(...),
destination = git.destination(...),
transformations = [...],
mode = "SQUASH",
)

A secondary workflow type for reacting to events (PRs merged, issues created, etc.):

core.feedback(
name = "notify",
origin = git.github_trigger(...),
destination = git.github_api(...),
actions = [...],
)

The mode parameter in core.workflow determines how commits are created:

ModeDescriptionUse Case
SQUASHCombine all changes into one commitMost common, clean history
ITERATIVEPreserve individual commitsWhen history matters
CHANGE_REQUESTCreate PR/CL for reviewWhen approval is needed
CHANGE_REQUEST_FROM_SOTPR from source of truthBidirectional sync
# Each mode has different behavior
mode = "SQUASH", # Default, recommended
mode = "ITERATIVE", # Preserve history
mode = "CHANGE_REQUEST", # Create PRs

A complete workflow has these components:

core.workflow(
# Required
name = "my-workflow", # Unique identifier
origin = git.origin(...), # Where to read from
destination = git.destination(...), # Where to write to
authoring = authoring.pass_thru(...), # Author handling
# Optional but common
origin_files = glob(["src/**"]), # What to read
destination_files = glob(["**"]), # What to manage
transformations = [...], # How to modify
mode = "SQUASH", # Commit strategy
# Less common
reversible_check = True, # Verify transforms are reversible
check_last_rev_state = True, # Validate state on each run
ask_for_confirmation = False, # Interactive confirmation
)

Defines what files to read from the origin:

origin_files = glob(
include = ["src/**", "docs/**"],
exclude = ["**/internal/**"],
)

Defines what files Copybara is allowed to modify in the destination:

# Only modify files under src/
destination_files = glob(["src/**"])
# Exclude manually-managed files
destination_files = glob(
include = ["**"],
exclude = ["README.md", ".github/**"],
)
Terminal window
java -jar copybara.jar validate copy.bara.sky workflow_name
Terminal window
# Standard run (processes new commits)
java -jar copybara.jar migrate copy.bara.sky workflow_name
# Initial sync (process all history)
java -jar copybara.jar migrate copy.bara.sky workflow_name --init-history
# Force re-sync (ignore state)
java -jar copybara.jar migrate copy.bara.sky workflow_name --force
# Start from specific commit
java -jar copybara.jar migrate copy.bara.sky workflow_name --last-rev abc123

A single config file can contain multiple workflows:

copy.bara.sky
# Export internal code to GitHub
core.workflow(
name = "export",
origin = git.origin(url = internal_url, ref = "main"),
destination = git.github_destination(url = github_url, push = "main"),
...
)
# Import external contributions
core.workflow(
name = "import",
origin = git.github_pr_origin(url = github_url, branch = "main"),
destination = git.gerrit_destination(url = internal_url, ...),
...
)

Run specific workflows by name:

Terminal window
java -jar copybara.jar migrate copy.bara.sky export
java -jar copybara.jar migrate copy.bara.sky import