diff --git a/.copier/README.md b/.copier/README.md new file mode 100644 index 0000000..4af65aa --- /dev/null +++ b/.copier/README.md @@ -0,0 +1,169 @@ +# Code Copier Workflows + +This directory contains workflow configurations for automatically copying code examples to destination repositories. + +The copier app is owned by the Dev Docs team. + +## Adding a New Workflow + +To add a new workflow, create a new DOCSP Jira ticket with the component set to `DevDocs`. + +## How It Works + +1. **You merge a PR** to ``main`` in this repository +2. **Copier is notified** of the merge via webhook +3. **Copier checks the filepaths** from the PR. If any filepaths match a defined workflow: + - **Files are copied** to the one or more destination repositories + - The copier does nothing + +You can optionally define *how* the copy is managed. Based on the workflow configuration: +- The copier creates a PR in the destination repository (**default**). You can set your own process for handling that PR, which may involve manual testing or review. +- The copier commits directly to the destination repository **without a PR**. You may prefer this option if you want a fully automated workflow with no review at the destination repo. + +Source Code: [Code Example Tooling Repository](https://github.com/mongodb/code-example-tooling) + +## Basic Workflow Structure + +```yaml +workflows: + - name: "my-workflow" + destination: + repo: "mongodb/destination-repo" + branch: "main" + transformations: + - move: + from: "source/path" + to: "destination/path" +``` + +Note: Patterns and paths are matched against the full repository path + +## Common Transformation Types + +### Move Directory + +Copy all files from one directory to another: + +```yaml +transformations: + - move: + from: "examples/go" + to: "code/go" +``` + +### Copy Single File + +Copy a specific file: + +```yaml +transformations: + - copy: + from: "README.md" + to: "docs/README.md" +``` + +### Match with Wildcards + +Use glob patterns for flexible matching: + +```yaml +transformations: + - glob: + pattern: "examples/**/*.go" + transform: "code/${relative_path}" +``` + +## Customizing PR Details + +Add custom PR titles and descriptions: + +```yaml +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 +``` + +## Available Variables + +Use these variables in PR titles, bodies, and commit messages: + +- `${source_repo}` - Source repository name +- `${source_branch}` - Source branch name +- `${pr_number}` - Source PR number +- `${commit_sha}` - Source commit SHA +- `${file_count}` - Number of files changed + +Use these in path transformations: + +- `${relative_path}` - Path relative to the matched pattern +- `${path}` - Full source file path +- `${filename}` - Just the filename +- `${dir}` - Directory path +- `${ext}` - File extension + +## Excluding Files + +Prevent certain files from being copied: + +```yaml +workflows: + - name: "my-workflow" + destination: + repo: "mongodb/destination-repo" + branch: "main" + transformations: + - move: { from: "src", to: "dest" } + exclude: + - "**/.env" + - "**/node_modules/**" + - "**/*.test.js" +``` + +## Example: Complete Workflow + +```yaml +# .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 + deprecation_check: + enabled: true + file: "deprecated_examples.json" +``` \ No newline at end of file diff --git a/.copier/config.yaml b/.copier/config.yaml new file mode 100644 index 0000000..d9f108f --- /dev/null +++ b/.copier/config.yaml @@ -0,0 +1,107 @@ +# Docs Copier Workflow Configuration +# Referenced from main config file in https://github.com/mongodb/code-example-tooling/blob/main/.copier/workflows/main.yaml + +# ============================================================================ +# LOCAL DEFAULTS +# ============================================================================ +# These defaults apply to all workflows in this file +# They override main config defaults but can be overridden by individual workflows + + +defaults: + commit_strategy: + type: "pull_request" + auto_merge: false + use_pr_template: true + commit_message: "Automated update from ${source_repo} PR #${pr_number} (${file_count} files)" + deprecation_check: + enabled: true + file: "deprecated_examples.json" + exclude: + - "**/.env" + - "**/node_modules/**" + - "**/.DS_Store" + - "\\.gitignore$" + - "README.md$" + +# ============================================================================ +# WORKFLOW CONFIGURATION +# ============================================================================ +# To add a workflow, create a DOCSP Jira ticket with the component set to `DevDocs`. +# See also [README.md](https://github.com/mongodb/docs-sample-apps/blob/main/.copier/README.md) + +workflows: + + # -------------------------------------------------------------------------- + # MFlix Java Application + # -------------------------------------------------------------------------- + - name: "mflix-java" + destination: + repo: "mongodb/sample-app-java-mflix" + branch: "main" + transformations: + - move: { from: "mflix/client", to: "client" } + - move: { from: "mflix/server/java-spring", to: "server" } + - copy: { from: "mflix/README-JAVA-SPRING.md", to: "README.md" } + - copy: { from: "mflix/.gitignore-java", to: ".gitignore" } + commit_strategy: + pr_title: "Update MFlix application from docs-sample-apps" + pr_body: | + Automated update of MFlix Java application + + **Source:** ${source_repo} (${source_branch}) + **PR:** #${pr_number} | **Commit:** ${commit_sha} + **Changes:** ${file_count} files + exclude: + - "mflix/client/**/.gitignore" + - "mflix/server/java-spring/**/.gitignore" + + + # -------------------------------------------------------------------------- + # MFlix Node.js Application + # -------------------------------------------------------------------------- + - name: "mflix-nodejs" + destination: + repo: "mongodb/sample-app-nodejs-mflix" + branch: "main" + transformations: + - move: { from: "mflix/client", to: "client" } + - move: { from: "mflix/server/js-express", to: "server" } + - copy: { from: "mflix/README-JAVASCRIPT-EXPRESS.md", to: "README.md" } + - copy: { from: "mflix/.gitignore-js", to: ".gitignore" } + commit_strategy: + pr_title: "Update MFlix application from docs-sample-apps" + pr_body: | + Automated update of MFlix Node.js application + + **Source:** ${source_repo} (${source_branch}) + **PR:** #${pr_number} | **Commit:** ${commit_sha} + **Changes:** ${file_count} files + exclude: + - "mflix/client/**/.gitignore" + - "mflix/server/js-express/**/.gitignore" + + + # -------------------------------------------------------------------------- + # MFlix Python Application + # -------------------------------------------------------------------------- + - name: "mflix-python" + destination: + repo: "mongodb/sample-app-python-mflix" + branch: "main" + transformations: + - move: { from: "mflix/client", to: "client" } + - move: { from: "mflix/server/python-fastapi", to: "server" } + - copy: { from: "mflix/README-PYTHON-FASTAPI.md", to: "README.md" } + - copy: { from: "mflix/.gitignore-python", to: ".gitignore" } + commit_strategy: + pr_title: "Update MFlix application from docs-sample-apps" + pr_body: | + Automated update of MFlix Python application + + **Source:** ${source_repo} (${source_branch}) + **PR:** #${pr_number} | **Commit:** ${commit_sha} + **Changes:** ${file_count} files + exclude: + - "mflix/client/**/.gitignore" + - "mflix/server/python-fastapi/**/.gitignore" diff --git a/copier-config.yaml b/copier-config.yaml deleted file mode 100644 index 7c3fcf7..0000000 --- a/copier-config.yaml +++ /dev/null @@ -1,328 +0,0 @@ -# MFlix Configuration with Batch PR Config -# Source: mongodb/docs-sample-apps -# This config uses batch_pr_config to create ONE PR per target repo with accurate file counts - -source_repo: "mongodb/docs-sample-apps" -source_branch: "main" - -# Enable batching - all rules targeting the same repo will be combined into one PR -batch_by_repo: true - -# Configure PR metadata for batched PRs with accurate file counts -batch_pr_config: - pr_title: "Update MFlix application from docs-sample-apps" - pr_body: | - Automated update of MFlix application files - - **Source Information:** - - Repository: ${source_repo} - - Branch: ${source_branch} - - PR: #${pr_number} - - Commit: ${commit_sha} - - **Changes:** - - Total files: ${file_count} - - Target branch: ${target_branch} - - This PR includes client files, server files, README, and .gitignore updates. - All files have been automatically synchronized from the source repository. - use_pr_template: true # Fetch and merge PR template from target repos - commit_message: "Update MFlix from ${source_repo} PR #${pr_number} (${file_count} files)" - -copy_rules: - # ============================================================================ - # Java Target: mongodb/sample-app-java-mflix - # ============================================================================ - - # Rule 1: Copy client directory to Java target - - name: "mflix-client-to-java" - source_pattern: - type: "prefix" - pattern: "mflix/client/" - exclude_patterns: - - "\\.gitignore$" # Exclude .gitignore files - - "README.md$" # Exclude README files - - "\\.env$" # Exclude environment files - targets: - - repo: "mongodb/sample-app-java-mflix" - branch: "main" - path_transform: "client/${relative_path}" - commit_strategy: - type: "pull_request" - pr_title: "Update MFlix client from docs-sample-apps" - pr_body: | - Automated update of MFlix Next.js client - - Source: ${source_repo} - PR: #${pr_number} - Commit: ${commit_sha} - auto_merge: false - deprecation_check: - enabled: true - file: "deprecated_examples.json" - - # Rule 2: Copy Java server files (removing the java-spring subdirectory) - - name: "java-server" - source_pattern: - type: "regex" - pattern: "^mflix/server/java-spring/(?P.+)$" - exclude_patterns: - - "\\.gitignore$" # Exclude .gitignore files - - "README.md$" # Exclude README files - - "\\.env$" # Exclude environment files - targets: - - repo: "mongodb/sample-app-java-mflix" - branch: "main" - path_transform: "server/${file}" - commit_strategy: - type: "pull_request" - pr_title: "Update MFlix Java server from docs-sample-apps" - pr_body: | - Automated update of MFlix Java/Spring Boot server - - Source: ${source_repo} - PR: #${pr_number} - Commit: ${commit_sha} - auto_merge: false - deprecation_check: - enabled: true - - # Rule 3: Copy Java README (renaming to just README.md) - - name: "mflix-java-readme" - source_pattern: - type: "glob" - pattern: "mflix/README-JAVA-SPRING.md" - targets: - - repo: "mongodb/sample-app-java-mflix" - branch: "main" - path_transform: "README.md" - commit_strategy: - type: "pull_request" - pr_title: "Update README from docs-sample-apps" - pr_body: | - Automated update of README - - Source: ${source_repo} - PR: #${pr_number} - auto_merge: false - deprecation_check: - enabled: true - - # Rule 4: Copy Java .gitignore (renaming to just .gitignore) - - name: "mflix-java-gitignore" - source_pattern: - type: "glob" - pattern: "mflix/.gitignore-java" - targets: - - repo: "mongodb/sample-app-java-mflix" - branch: "main" - path_transform: ".gitignore" - commit_strategy: - type: "pull_request" - pr_title: "Update .gitignore from docs-sample-apps" - pr_body: | - Automated update of .gitignore - - Source: ${source_repo} - PR: #${pr_number} - auto_merge: false - deprecation_check: - enabled: true - - # ============================================================================ - # JavaScript Target: mongodb/sample-app-nodejs-mflix - # ============================================================================ - - # Rule 5: Copy client directory to JavaScript target - - name: "mflix-client-to-js" - source_pattern: - type: "prefix" - pattern: "mflix/client/" - exclude_patterns: - - "\\.gitignore$" # Exclude .gitignore files - - "README.md$" # Exclude README files - - "\\.env$" # Exclude environment files - targets: - - repo: "mongodb/sample-app-nodejs-mflix" - branch: "main" - path_transform: "client/${relative_path}" - commit_strategy: - type: "pull_request" - pr_title: "Update MFlix client from docs-sample-apps" - pr_body: | - Automated update of MFlix Next.js client - - Source: ${source_repo} - PR: #${pr_number} - Commit: ${commit_sha} - auto_merge: false - deprecation_check: - enabled: true - file: "deprecated_examples.json" - - # Rule 6: Copy Express server files (removing the express subdirectory) - - name: "mflix-express-server" - source_pattern: - type: "regex" - pattern: "^mflix/server/js-express/(?P.+)$" - exclude_patterns: - - "\\.gitignore$" # Exclude .gitignore files - - "README.md$" # Exclude README files - - "\\.env$" # Exclude environment files - targets: - - repo: "mongodb/sample-app-nodejs-mflix" - branch: "main" - path_transform: "server/${file}" - commit_strategy: - type: "pull_request" - pr_title: "Update MFlix Express server from docs-sample-apps" - pr_body: | - Automated update of MFlix Express.js server - - Source: ${source_repo} - PR: #${pr_number} - Commit: ${commit_sha} - auto_merge: false - deprecation_check: - enabled: true - - # Rule 7: Copy JavaScript README (renaming to just README.md) - - name: "mflix-js-readme" - source_pattern: - type: "glob" - pattern: "mflix/README-JAVASCRIPT-EXPRESS.md" - targets: - - repo: "mongodb/sample-app-nodejs-mflix" - branch: "main" - path_transform: "README.md" - commit_strategy: - type: "pull_request" - pr_title: "Update README from docs-sample-apps" - pr_body: | - Automated update of README - - Source: ${source_repo} - PR: #${pr_number} - auto_merge: false - deprecation_check: - enabled: true - - # Rule 8: Copy JavaScript .gitignore (renaming to just .gitignore) - - name: "mflix-js-gitignore" - source_pattern: - type: "glob" - pattern: "mflix/.gitignore-js" - targets: - - repo: "mongodb/sample-app-nodejs-mflix" - branch: "main" - path_transform: ".gitignore" - commit_strategy: - type: "pull_request" - pr_title: "Update .gitignore from docs-sample-apps" - pr_body: | - Automated update of .gitignore - - Source: ${source_repo} - PR: #${pr_number} - auto_merge: false - deprecation_check: - enabled: true - - # ============================================================================ - # Python Target: mongodb/sample-app-python-mflix - # ============================================================================ - - # Rule 9: Copy client directory to Python target - - name: "mflix-client-to-python" - source_pattern: - type: "prefix" - pattern: "mflix/client/" - exclude_patterns: - - "\\.gitignore$" # Exclude .gitignore files - - "README.md$" # Exclude README files - - "\\.env$" # Exclude environment files - targets: - - repo: "mongodb/sample-app-python-mflix" - branch: "main" - path_transform: "client/${relative_path}" - commit_strategy: - type: "pull_request" - pr_title: "Update MFlix client from docs-sample-apps" - pr_body: | - Automated update of MFlix Next.js client - - Source: ${source_repo} - PR: #${pr_number} - Commit: ${commit_sha} - auto_merge: false - deprecation_check: - enabled: true - file: "deprecated_examples.json" - - # Rule 10: Copy Python server files (removing the python subdirectory) - - name: "mflix-python-server" - source_pattern: - type: "regex" - pattern: "^mflix/server/python-fastapi/(?P.+)$" - exclude_patterns: - - "\\.gitignore$" # Exclude .gitignore files - - "README.md$" # Exclude README files - - "\\.env$" # Exclude environment files - targets: - - repo: "mongodb/sample-app-python-mflix" - branch: "main" - path_transform: "server/${file}" - commit_strategy: - type: "pull_request" - pr_title: "Update MFlix Python server from docs-sample-apps" - pr_body: | - Automated update of MFlix Python/FastAPI server - - Source: ${source_repo} - PR: #${pr_number} - Commit: ${commit_sha} - auto_merge: false - deprecation_check: - enabled: true - - # Rule 11: Copy Python README (renaming to just README.md) - - name: "mflix-python-readme" - source_pattern: - type: "glob" - pattern: "mflix/README-PYTHON-FASTAPI.md" - targets: - - repo: "mongodb/sample-app-python-mflix" - branch: "main" - path_transform: "README.md" - commit_strategy: - type: "pull_request" - pr_title: "Update README from docs-sample-apps" - pr_body: | - Automated update of README - - Source: ${source_repo} - PR: #${pr_number} - auto_merge: false - deprecation_check: - enabled: true - - # Rule 12: Copy Python .gitignore (renaming to just .gitignore) - - name: "mflix-python-gitignore" - source_pattern: - type: "glob" - pattern: "mflix/.gitignore-python" - targets: - - repo: "mongodb/sample-app-python-mflix" - branch: "main" - path_transform: ".gitignore" - commit_strategy: - type: "pull_request" - pr_title: "Update .gitignore from docs-sample-apps" - pr_body: | - Automated update of .gitignore - - Source: ${source_repo} - PR: #${pr_number} - auto_merge: false - deprecation_check: - enabled: true