-
Notifications
You must be signed in to change notification settings - Fork 2
adding a readme to sync-vip-prod #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
micahwave
wants to merge
1
commit into
main
Choose a base branch
from
feature/add-sync-docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| # Sync to VIP Production Composite Action | ||
|
|
||
| This GitHub Actions composite action synchronizes code from a source repository to a WordPress VIP production repository. | ||
|
|
||
| ## Overview | ||
|
|
||
| The `sync-vip-prod` composite action is designed to automate the deployment process for WordPress VIP sites by: | ||
|
|
||
| 1. Checking out the source repository | ||
| 2. Checking out the destination VIP repository | ||
| 3. Syncing files while preserving protected directories | ||
| 4. Committing and pushing changes to the destination repository | ||
| 5. Sending Slack notifications on failure | ||
|
|
||
| ## Usage | ||
|
|
||
| ```yaml | ||
| - name: Sync to VIP Production | ||
| uses: ./composites/sync-vip-prod | ||
| with: | ||
| destination_repo: 'wpcomvip/your-site' | ||
| destination_branch: 'production' | ||
| destination_directory: 'wp-content/themes/your-theme' | ||
| protected_directories: 'wp-content/plugins/brand-specific-plugin' | ||
| GIT_EMAIL: 'your-bot@example.com' | ||
| SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
| SSH_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | ||
| ``` | ||
|
|
||
| ## Inputs | ||
|
|
||
| | Input | Description | Required | Default | | ||
| |-------|-------------|----------|---------| | ||
| | `destination_repo` | Destination repository slug, including organization (e.g., `wpcomvip/pmc`) | Yes | - | | ||
| | `destination_branch` | Branch name in the destination repository | Yes | - | | ||
| | `destination_directory` | Directory path relative to repository root where files will be synced | Yes | - | | ||
| | `protected_directories` | Directories to preserve during sync (typically brand-specific plugins) | No | `''` | | ||
| | `GIT_EMAIL` | Email address for the Git user making commits | Yes | - | | ||
| | `SLACK_WEBHOOK_URL` | Webhook URL for failure notifications | No | `''` | | ||
| | `SSH_KEY` | SSH private key with access to both source and destination repositories | Yes | - | | ||
|
|
||
| ## Workflow Steps | ||
|
|
||
| ### 1. Repository Checkout | ||
| - **Source Repository**: Checks out the current repository with minimal history (`fetch-depth: 1`) | ||
| - **Destination Repository**: Checks out the specified VIP repository and branch using the provided SSH key | ||
| - **Utility Scripts**: Checks out `penske-media-corp/pmc-jenkins-scripts` for helper functions | ||
|
|
||
| ### 2. File Synchronization Process | ||
|
|
||
| The action uses several utility functions from the Jenkins scripts: | ||
|
|
||
| - **`exclude_plugins`**: Temporarily moves protected directories out of the way | ||
| - **`rsync_repo_files`**: Synchronizes files from source to destination using rsync | ||
| - **`restore_plugins`**: Restores the protected directories after sync | ||
| - **`setup_git_committer`**: Configures Git committer information based on the source repository | ||
|
|
||
| ### 3. Git Operations | ||
|
|
||
| The action performs the following Git operations: | ||
| - Configures Git user as `pmcvipgo-sync` with the provided email | ||
| - Stages all changes (`git add --all`) | ||
| - Checks if there are changes to commit | ||
| - Creates a commit with metadata about the source repository and revision | ||
| - Pushes changes to the destination branch | ||
|
|
||
| ### 4. Error Handling and Notifications | ||
|
|
||
| If the sync fails and a Slack webhook URL is provided: | ||
| - Retrieves job details from the GitHub API | ||
| - Sends a formatted Slack notification with source, destination, and failure details | ||
|
|
||
| ## Commit Message Format | ||
|
|
||
| Commits created by this action follow this format: | ||
| ``` | ||
| Sync from {source-repo}:{branch-name} for revision {commit-hash} by {author} | ||
| ``` | ||
|
|
||
| ## Slack Notification | ||
|
|
||
| When a sync fails, the action sends a Slack notification with: | ||
| - Alert header indicating production sync failure | ||
| - Source repository and branch information | ||
| - Destination repository and branch information | ||
| - Link to the failed GitHub Actions job | ||
|
|
||
| ## Protected Directories | ||
|
|
||
| The `protected_directories` input allows you to specify directories that should be preserved in the destination repository during the sync. This is useful for: | ||
|
|
||
| - Brand-specific plugins that aren't in the shared source repository | ||
| - Configuration files specific to the VIP environment | ||
| - Any custom modifications that shouldn't be overwritten | ||
|
|
||
| Multiple directories can be specified (the exact format depends on the utility functions implementation). | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Directories are pipe-delimited: https://github.com/penske-media-corp/pmc-vip-go-plugins/commit/67f43e4e2249e4fa94bfb89e837507b46e320c20 |
||
|
|
||
| ## Requirements | ||
|
|
||
| - The SSH key must have read access to the source repository | ||
| - The SSH key must have write access to the destination VIP repository | ||
| - The destination repository must exist and have the specified branch | ||
| - The `penske-media-corp/pmc-jenkins-scripts` repository must be accessible | ||
|
|
||
| ## Security Considerations | ||
|
|
||
| - SSH keys should be stored as GitHub repository secrets | ||
| - Slack webhook URLs should be stored as secrets | ||
| - The action runs with the permissions of the provided SSH key | ||
| - All file operations are performed in isolated workspace directories | ||
|
|
||
| ## Debugging | ||
|
|
||
| Enable debug mode by setting `ACTIONS_STEP_DEBUG=true` in your workflow. This will: | ||
| - List contents of all workspace directories | ||
| - Show detailed information about the checkout process | ||
| - Display Git operations and status information | ||
|
|
||
| ## Example Workflow | ||
|
|
||
| ```yaml | ||
| name: Deploy to VIP Production | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
|
|
||
| jobs: | ||
| deploy: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Deploy to Production | ||
| uses: ./composites/sync-vip-prod | ||
| with: | ||
| destination_repo: 'wpcomvip/your-brand' | ||
| destination_branch: 'production' | ||
| destination_directory: 'wp-content/themes/brand-theme' | ||
| protected_directories: 'wp-content/plugins/brand-analytics wp-content/mu-plugins/brand-config' | ||
| GIT_EMAIL: 'deploy-bot@yourbrand.com' | ||
| SLACK_WEBHOOK_URL: ${{ secrets.PROD_DEPLOY_SLACK_WEBHOOK }} | ||
| SSH_KEY: ${{ secrets.VIP_DEPLOY_SSH_KEY }} | ||
| ``` | ||
|
|
||
| ## Related Files | ||
|
|
||
| - [`action.yml`](./action.yml) - The composite action definition | ||
| - [`slack-payload.json`](./slack-payload.json) - Slack notification template | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These aren't the intended use cases. When it was in use, it was only for BGR and Gold Derby as they had plugins added directly to their VIP repos. We rectified that for GD during the replatform, while Static Media resolved the BGR situation.