11# GitHub Docs Code Example Copier
22
3- A GitHub app that automatically copies code examples and files from a source repository to one or more target
4- repositories when pull requests are merged. Features advanced pattern matching, path transformations, audit logging,
5- and comprehensive monitoring.
3+ A GitHub app that automatically copies code examples and files from source repositories to target repositories when pull requests are merged. Features centralized configuration with distributed workflow management, $ref support for reusable components, advanced pattern matching, and comprehensive monitoring.
64
75## Features
86
97### Core Functionality
8+ - ** Main Config System** - Centralized configuration with distributed workflow management
9+ - ** Source Context Inference** - Workflows automatically inherit source repo/branch
10+ - ** $ref Support** - Reusable components for transformations, strategies, and excludes
11+ - ** Resilient Loading** - Continues processing when individual configs fail (logs warnings)
1012- ** Automated File Copying** - Copies files from source to target repos on PR merge
1113- ** Advanced Pattern Matching** - Prefix, glob, and regex patterns with variable extraction
1214- ** Path Transformations** - Template-based path transformations with variable substitution
13- - ** Multiple Targets** - Copy files to multiple repositories and branches
1415- ** Flexible Commit Strategies** - Direct commits or pull requests with auto-merge
1516- ** Deprecation Tracking** - Automatic tracking of deleted files
1617
1718### Enhanced Features
18- - ** YAML Configuration** - Modern workflow-based YAML configuration
19+ - ** Workflow References** - Local, remote (repo), or inline workflow configs
20+ - ** Default Precedence** - Workflow > Workflow config > Main config > System defaults
1921- ** Message Templating** - Template-ized commit messages and PR titles
2022- ** PR Template Integration** - Fetch and merge PR templates from target repos
21- - ** File Exclusion** - Exclude patterns to filter out unwanted files ( ` .gitignore ` , ` node_modules ` , etc.)
23+ - ** File Exclusion** - Exclude patterns to filter out unwanted files
2224- ** Audit Logging** - MongoDB-based event tracking for all operations
2325- ** Health & Metrics** - ` /health ` and ` /metrics ` endpoints for monitoring
2426- ** Development Tools** - Dry-run mode, CLI validation, enhanced logging
@@ -55,74 +57,80 @@ go build -o config-validator ./cmd/config-validator
55571 . ** Copy environment example file**
5658
5759``` bash
58- # For local development
59- cp configs/.env.local.example configs/.env
60-
61- # Or for YAML-based configuration
62- cp configs/env.yaml.example env.yaml
60+ cp env.yaml.example env.yaml
6361```
6462
65632 . ** Set required environment variables**
6664
67- ``` bash
65+ ``` yaml
6866# GitHub Configuration
69- REPO_OWNER=your-org
70- REPO_NAME=your-repo
71- SRC_BRANCH=main
72- GITHUB_APP_ID=123456
73- GITHUB_INSTALLATION_ID=789012
67+ GITHUB_APP_ID : " 123456"
68+ INSTALLATION_ID : " 789012" # Optional fallback
7469
75- # Google Cloud
76- GCP_PROJECT_ID=your-project
77- PEM_KEY_NAME=projects/123/secrets/< name> /versions/latest
78- WEBHOOK_SECRET_NAME=projects/123/secrets/webhook-secret
70+ # Config Repository (where main config lives)
71+ CONFIG_REPO_OWNER : " your-org"
72+ CONFIG_REPO_NAME : " config-repo"
73+ CONFIG_REPO_BRANCH : " main"
74+
75+ # Main Config
76+ MAIN_CONFIG_FILE : " .copier/workflows/main.yaml"
77+ USE_MAIN_CONFIG : " true"
78+
79+ # Secret Manager References
80+ GITHUB_APP_PRIVATE_KEY_SECRET_NAME : " projects/.../secrets/PEM/versions/latest"
81+ WEBHOOK_SECRET_NAME : " projects/.../secrets/webhook-secret/versions/latest"
7982
8083# Application Settings
81- PORT=8080
82- CONFIG_FILE=copier-config.yaml
83- DEPRECATION_FILE=deprecated_examples.json
84+ WEBSERVER_PATH : " /events"
85+ DEPRECATION_FILE : " deprecated_examples.json"
86+ COMMITTER_NAME : " GitHub Copier App"
87+ COMMITTER_EMAIL :
" [email protected] " 88+
89+ # Feature Flags
90+ AUDIT_ENABLED : " false"
91+ METRICS_ENABLED : " true"
92+ ` ` `
8493
85- # Optional: MongoDB Audit Logging
86- AUDIT_ENABLED=true
87- MONGO_URI=mongodb+srv://user:
[email protected] 88- AUDIT_DATABASE=code_copier
89- AUDIT_COLLECTION=audit_events
94+ 3. **Create main configuration file**
9095
91- # Optional: Development Features
92- DRY_RUN=false
93- METRICS_ENABLED=true
96+ Create ` .copier/workflows/main.yaml` in your config repository:
97+
98+ ` ` ` yaml
99+ # Main config with global defaults and workflow references
100+ defaults:
101+ commit_strategy:
102+ type: "pull_request"
103+ auto_merge: false
104+ exclude:
105+ - "**/.env"
106+ - "**/node_modules/**"
107+
108+ workflow_configs:
109+ # Reference workflows in source repo
110+ - source: "repo"
111+ repo: "your-org/source-repo"
112+ branch: "main"
113+ path: ".copier/workflows/config.yaml"
114+ enabled: true
94115` ` `
95116
96- 3 . ** Create configuration file **
117+ 4 . **Create workflow config in source repository **
97118
98- Create ` copier- config.yaml ` in your source repository:
119+ Create `. copier/workflows/ config.yaml` in your source repository :
99120
100121` ` ` yaml
101122workflows:
102- - name : " Copy code examples"
103- source :
104- repo : " your-org/source-repo"
105- branch : " main"
123+ - name: "copy-examples"
124+ # source.repo and source.branch inherited from workflow config reference
106125 destination:
107126 repo: "your-org/target-repo"
108127 branch: "main"
109128 transformations:
110- - move :
111- from : " examples"
112- to : " docs/examples"
113- exclude :
114- - " **/.gitignore"
115- - " **/node_modules/**"
116- - " **/.env"
129+ - move: { from: "examples", to: "docs/examples" }
117130 commit_strategy:
118131 type: "pull_request"
119132 pr_title: "Update code examples"
120- pr_body : " Automated update of code examples"
121133 use_pr_template: true
122- auto_merge : false
123- deprecation_check :
124- enabled : true
125- file : " deprecated_examples.json"
126134` ` `
127135
128136# ## Running the Application
@@ -143,6 +151,16 @@ workflows:
143151
144152# # Configuration
145153
154+ See [MAIN-CONFIG-README.md](configs/copier-config-examples/MAIN-CONFIG-README.md) for complete configuration documentation.
155+
156+ # ## Main Config Structure
157+
158+ The application uses a three-tier configuration system :
159+
160+ 1. **Main Config** - Centralized defaults and workflow references
161+ 2. **Workflow Configs** - Collections of workflows (local, remote, or inline)
162+ 3. **Individual Workflows** - Specific source → destination mappings
163+
146164# ## Transformation Types
147165
148166# ### Move Transformation
@@ -233,51 +251,64 @@ commit_strategy:
233251
234252# ## Advanced Features
235253
254+ # ### $ref Support for Reusable Components
255+
256+ Extract common configurations into separate files :
257+
258+ ` ` ` yaml
259+ # Workflow config
260+ workflows:
261+ - name: "mflix-java"
262+ destination:
263+ repo: "mongodb/sample-app-java-mflix"
264+ branch: "main"
265+ transformations:
266+ $ref: "../transformations/mflix-java.yaml"
267+ commit_strategy:
268+ $ref: "../strategies/mflix-pr-strategy.yaml"
269+ exclude:
270+ $ref: "../common/mflix-excludes.yaml"
271+ ` ` `
272+
273+ # ### Source Context Inference
274+
275+ Workflows automatically inherit source repo/branch from workflow config reference :
276+
277+ ` ` ` yaml
278+ # No need to specify source.repo and source.branch!
279+ workflows:
280+ - name: "my-workflow"
281+ # source.repo and source.branch inherited automatically
282+ destination:
283+ repo: "mongodb/dest-repo"
284+ branch: "main"
285+ transformations:
286+ - move: { from: "src", to: "dest" }
287+ ` ` `
288+
236289# ### PR Template Integration
237290
238291Automatically fetch and merge PR templates from target repositories :
239292
240293` ` ` yaml
241294commit_strategy:
242295 type: "pull_request"
243- pr_body: |
244- 🤖 Automated update
245- Files: ${file_count}
296+ pr_body: "🤖 Automated update"
246297 use_pr_template: true # Fetches .github/pull_request_template.md
247298` ` `
248299
249- **Result:** PR description shows the target repo's template first (with checklists and guidelines), followed by your configured content.
250-
251300# ### File Exclusion
252301
253- Exclude unwanted files from being copied at the workflow level :
302+ Exclude unwanted files at the workflow or workflow config level :
254303
255304` ` ` yaml
256- workflows:
257- - name: "Copy examples"
258- source:
259- repo: "owner/source-repo"
260- branch: "main"
261- destination:
262- repo: "owner/target-repo"
263- branch: "main"
264- transformations:
265- - move:
266- from: "examples"
267- to: "code"
268- exclude:
269- - "**/.gitignore" # Exclude .gitignore files
270- - "**/node_modules/**" # Exclude dependencies
271- - "**/.env" # Exclude environment files
272- - "**/dist/**" # Exclude build artifacts
273- - "**/*.test.js" # Exclude test files
305+ exclude:
306+ - "**/.gitignore"
307+ - "**/node_modules/**"
308+ - "**/.env"
309+ - "**/dist/**"
274310` ` `
275311
276- **Use cases:**
277- - Filter out configuration files
278- - Exclude build artifacts and dependencies
279- - Skip test files or documentation
280-
281312# ## Message Templates
282313
283314Use variables in commit messages and PR titles :
@@ -504,19 +535,20 @@ container := NewServiceContainer(config)
504535
505536## Deployment
506537
507- See [ DEPLOYMENT.md] ( ./docs/DEPLOYMENT.md ) for complete deployment guide for step-by-step checklist .
538+ See [ DEPLOYMENT.md] ( ./docs/DEPLOYMENT.md ) for complete deployment guide.
508539
509- ### Google Cloud App Engine
540+ ### Google Cloud Run
510541
511542``` bash
512- gcloud app deploy
543+ cd examples-copier
544+ ./scripts/deploy-cloudrun.sh
513545```
514546
515547### Docker
516548
517549``` bash
518550docker build -t examples-copier .
519- docker run -p 8080:8080 --env-file . env examples-copier
551+ docker run -p 8080:8080 --env-file env.yaml examples-copier
520552```
521553
522554## Security
@@ -530,7 +562,8 @@ docker run -p 8080:8080 --env-file .env examples-copier
530562
531563### Getting Started
532564
533- - ** [ Configuration Guide] ( docs/CONFIGURATION-GUIDE.md ) ** - Complete configuration reference
565+ - ** [ Main Config README] ( configs/copier-config-examples/MAIN-CONFIG-README.md ) ** - Complete main config documentation
566+ - ** [ Quick Start Guide] ( configs/copier-config-examples/QUICK-START-MAIN-CONFIG.md ) ** - Get started in 5 minutes
534567- ** [ Pattern Matching Guide] ( docs/PATTERN-MATCHING-GUIDE.md ) ** - Pattern matching with examples
535568- ** [ Local Testing] ( docs/LOCAL-TESTING.md ) ** - Test locally before deploying
536569- ** [ Deployment Guide] ( docs/DEPLOYMENT.md ) ** - Deploy to production
@@ -540,7 +573,6 @@ docker run -p 8080:8080 --env-file .env examples-copier
540573- ** [ Architecture] ( docs/ARCHITECTURE.md ) ** - System design and components
541574- ** [ Troubleshooting] ( docs/TROUBLESHOOTING.md ) ** - Common issues and solutions
542575- ** [ FAQ] ( docs/FAQ.md ) ** - Frequently asked questions
543- - ** [ Debug Logging] ( docs/DEBUG-LOGGING.md ) ** - Debug logging configuration
544576- ** [ Deprecation Tracking] ( docs/DEPRECATION-TRACKING-EXPLAINED.md ) ** - How deprecation tracking works
545577
546578### Features
@@ -550,6 +582,4 @@ docker run -p 8080:8080 --env-file .env examples-copier
550582
551583### Tools
552584
553- - ** [ config-validator] ( cmd/config-validator/README.md ) ** - Validate and test configurations
554- - ** [ test-webhook] ( cmd/test-webhook/README.md ) ** - Test webhook processing
555- - ** [ Scripts] ( scripts/README.md ) ** - Helper scripts
585+ - ** [ Scripts] ( scripts/README.md ) ** - Helper scripts for deployment and testing
0 commit comments