In some cases, you might want to copy files from one repository to another. For example, you might need to copy driver examples to a dedicated code examples GitHub repo.
The DevDocs team maintains a tool for automatically copying files between repositories (source code). This tool is configured through workflows defined in YAML files.
Note
Adding a New Destination Repository
To add a workflow that points to a new destination repository, contact the DevDocs team.
How It Works
The copier app works from a source repository and copies files to a destination repository.
You merge a PR to
mainin a source repository (for example, the Docs monorepo).A webhook notifies copier app of the merge.
Copier app verifies the filepaths from the PR.
If any filepaths match a defined workflow, files are copied to one or more destination repositories.
Otherwise, the copier app does nothing.
Important
Copier App Does Not Delete Files
The copier app does not automatically delete files in the destination repository. If a file is deleted in the source repository, the copier app adds the file to a
deprecated_examples.jsonthat lives in the source repo. To learn more, see Deleted Files.
You can optionally define how the copy is managed. Based on the workflow configuration, one of the following behaviors occurs:
The copier creates a PR in the destination repository (default). You can set your own process for handling that PR, which might involve manual testing or review.
The copier commits directly to the destination repository without a PR. You might prefer this option if you want a fully automated workflow with no review at the destination repo.
To learn, more see the Define the Commit Strategy section.
Deleted Files
The copier app does not automatically delete files in the destination repository.
If your PR deletes a file in the source repository, the copier app adds that filepath to a
deprecated_examples.json that lives in the source repository. But the file itself remains
in the destination repository.
Your team can set a process to manually remove the file from the destination repository, which might include updating any docs links that refer to that file before deleting it. This is to prevent breaking changes in the destination repository, including any links to the file.
Tip
A maintainer of the destination repository should periodically review the
deprecated_examples.json file and delete any files that are no longer needed.
Workflow Configuration
Workflows are defined in a .copier/config.yaml file in the root of
each source repository. You can define multiple workflows in a single file.
workflows: - name: "my-workflow" destination: # where to copy the files to repo: "mongodb/destination-repo" branch: "main" transformations: # defines the source files to copy and where/how to copy them - move: from: "source/path" to: "destination/path"
Available Workflow Properties
Required Fields
name: Unique, human-readable name that identifies the collection of rules in this workflow.destination: Location to copy the files to.transformations: Filepaths to apply this workflow to, and the type of action to take for those filepaths. Valid transformation types:move,copy,glob, andregex. The valid properties depend on the transformation type. To learn more, see the Transform Files section.
Optional Fields
commit_strategy: Method to commit changes. Valid strategies:PRordirect commit. For more information, refer to the Define the Commit Strategy section.exclude: Files or file patterns to exclude from the workflow. For more information, refer to the Exclude Files section.
Note
Patterns and paths are matched against the full repository path, not the relative path of the configuration file.
Global Defaults
You can define global defaults in the .copier/config.yaml file.
These defaults apply to all workflows unless overridden in an individual workflow.
Note
Don't change the global defaults. Contact the DevDocs team if you need them modified.
Update Copier Behavior
To change how the copier app copies or transforms files, you must
update the workflow in the source repo, then merge the updated configuration file.
The copier app detects the change and uses the new configuration on the next PR merge to main.
Define the Workflow and Destination
To define a workflow, you must specify the following information in the .copier/config.yaml file in the root of your source repository:
workflows: - name: "my-workflow" destination: repo: "mongodb/destination-repo" branch: "main"
name: A unique name for the workflow.destination: The repository and branch to copy files to:repo: Owner or name for the git repository to copy the files to.branch: Branch to copy the files to, either to open a PR against or to commit to directly. Defaults tomain.
Note
Copier App Must Be Installed in the Destination Repo
The copier must already be installed in the destination repository to work. If you need the copier app installed in a new destination, contact the DevDocs team.
Copy to Multiple Destinations
To copy to multiple destinations, you can create multiple workflows, one for each destination.
The following example workflow copies the same source files to both the mongodb/docs and mongodb/website repositories:
workflows: - name: "copy-to-docs" # Workflow name 1 destination: repo: "mongodb/docs" # Destination repository 1 transformations: - move: { from: "examples", to: "code" } - name: "copy-to-website" # Workflow name 2 destination: repo: "mongodb/website" # Destination repository 2 transformations: - move: { from: "examples", to: "static/examples" }
Note
The workflow names must be unique.
Transform Files
To define the source files to copy and where to copy them to, use the transformation block.
You can also transform files (for example, change the file path, name, or extension) as they are copied to the destination repository.
Supported transformations include basic moves and copies, as well as more complex transformations that use glob and regex patterns.
Tip
Use the Available Transform Variables to include dynamic information by using the transform property.
Transformation Types
Type | Description | Example | ||||
|---|---|---|---|---|---|---|
| Copies all files from one directory to another. | | ||||
| Copies specific files. | | ||||
| Uses glob patterns for flexible matching. Use the | | ||||
| Uses regex patterns for advanced matching. Use the | |
Available Transform Variables
For glob and regex transformations, you can use the following dynamic variables in path transformations:
Variable | Description | Example |
|---|---|---|
| Path relative to the matched pattern. |
|
| Full source file path. |
|
| Only the filename. |
|
| Directory path. |
|
| File extension. |
|
Exclude Files
Use the exclude block to prevent certain files from being copied:
workflows: - name: "my-workflow" destination: repo: "mongodb/destination-repo" branch: "main" transformations: - move: { from: "src", to: "dest" } exclude: - "**/.env" - "**/node_modules/**" - "**/*.test.js"
The following are common files to exclude:
Environment files:
**/.envDependencies:
**/node_modules/**Build artifacts:
**/dist/**,**/build/**Test files:
**/*.test.*,**/tests/**System files:
**/.DS_Store,**/Thumbs.db
Define the Commit Strategy
To define how the copier app commits changes to the destination repository, add a commit_strategy block to the workflow.
There are three strategies available:
Pull request with manual merge (default)
Pull request with auto-merge
Direct commit
If you don't include a commit_strategy section, the copier app uses the default
strategy, which is a pull request with manual merge.
Pull Request (Recommended)
Set the type to "pull_request" and set auto_merge to false to create a PR
in the destination repository for review, as shown in the following example:
commit_strategy: type: "pull_request" pr_title: "Update examples from ${source_repo}" pr_body: | Automated update from source repository. Source PR: #${pr_number} Commit: ${commit_sha} auto_merge: false # Requires manual review and merge
Use this commit strategy when:
The destination repository requires code review.
You want to run CI or CD tests before you merge the PR.
Changes need approval.
Tip
Use PR Templates
You can use PR templates to provide additional context for reviewers.
Include the use_pr_template: true property in the workflow.
The template must be defined in the destination repository.
Pull Request with Auto-Merge
Set auto_merge: true to create a PR and automatically merge it if there are no conflicts.
commit_strategy: type: "pull_request" auto_merge: true # Automatically merges if no conflicts
Use this commit strategy when:
The destination repository has automated tests that must pass.
You trust the source content completely.
Direct Commit
Use type: "direct" to commit directly to the destination branch (no PR):
commit_strategy: type: "direct" commit_message: "Update examples from ${source_repo}"
Use this commit strategy when:
The destination repository doesn't require review.
You need immediate updates.
You have full confidence in the source content.
Important
Direct commits bypass code review and CI checks.
Customize Pull Request Details
You can customize the PR title, body, and commit message to include relevant information.
Tip
Use the Available Variables to include dynamic information.
Configure Pull Request Format
Add custom PR titles and descriptions:
workflows: - name: "my-workflow" destination: repo: "mongodb/destination-repo" branch: "main" transformations: - move: { from: "src", to: "dest" } commit_strategy: type: "pull_request" pr_title: "Update examples from ${source_repo}" pr_body: | Automated update from source repository. Source PR: #${pr_number} Commit: ${commit_sha} auto_merge: false
Use PR templates from the destination repository:
workflows: - name: "my-workflow" destination: repo: "mongodb/destination-repo" branch: "main" transformations: - move: { from: "src", to: "dest" } commit_strategy: type: "pull_request" use_pr_template: true
Note
If the destination repository uses a pull request template, any custom body you configure here will be appended after the template content.
Available Variables
You can use the following dynamic variables in PR titles, bodies, and commit messages:
Variable | Description | Example |
|---|---|---|
| Source repository name. |
|
| Source branch name. |
|
| Source PR number. |
|
| Source commit SHA. |
|
| Number of files changed. |
|
Example: Complete Workflow
# .copier/config.yaml defaults: commit_strategy: type: "pull_request" auto_merge: false exclude: - "**/.env" - "**/node_modules/**" workflows: # Defaults apply unless overridden - name: "go-examples" destination: repo: "mongodb/go-examples-repo" branch: "main" transformations: - move: from: "examples/go" to: "code" commit_strategy: pr_title: "Update Go examples from ${source_repo}" pr_body: | Automated update of Go code examples. **Source**: ${source_repo} (PR # ${pr_number}) **Commit**: ${commit_sha} **Files**: ${file_count} changed commit_message: "Automated copy from ${source_repo} PR #${pr_number}" deprecation_check: enabled: true file: "deprecated_examples.json"
Troubleshooting
For help troubleshooting or adding new workflows, contact the DevDocs team.
My files weren't copied
Verify:
Was the PR merged to
main? The PR must be merged (not closed) to the correct branch to trigger the copier.Do the changed files match your transformation patterns? The filepaths must match at least one workflow pattern to be copied.
Is the copier installed in the destination repository? Verify with the DevDocs team to confirm.
Are your files being excluded due to your
excludepatterns?
Files are being copied to the wrong location
Verify:
Is the destination repository and branch correct?
Your filepaths:
Are your paths relative to repository root? Filepaths must be relative to repository root, not relative to config file location. For example, to copy files from the
examples/godirectory in the source repository, usefrom: "examples/go"instead offrom: "../examples/go".If you're using glob or regex transform types, is your pattern correct? Are your variables used correctly?
If you're using move or copy transform types, are your to paths correct?