7.7 KiB
Repository Sync Setup Guide
This guide explains how to set up and use the automatic repository synchronization between A6-9V/MQL5-Google-Onedrive and L6-N9 with REST API key management.
Overview
The repository sync system provides:
- Automatic synchronization between A6-9V and L6-N9 repositories
- REST API integration for secure authentication and notifications
- Bidirectional sync capabilities (push, pull, or both)
- Scheduled auto-sync every 6 hours
- Manual trigger via GitHub Actions
Prerequisites
-
GitHub Personal Access Token (PAT)
- Required for accessing the L6-N9 repository
- Needs
reposcope for full repository access
-
REST API Endpoint (Optional)
- For receiving sync notifications and status updates
- Secured with API key authentication
Setup Instructions
1. Generate GitHub Personal Access Token
- Go to GitHub Settings → Developer settings → Personal access tokens → Tokens (classic)
- Click "Generate new token (classic)"
- Give it a descriptive name (e.g., "Repo Sync Token")
- Select scopes:
- ✅
repo(Full control of private repositories)
- ✅
- Click "Generate token"
- Copy the token immediately (you won't be able to see it again)
2. Configure GitHub Secrets
Add the following secrets to your repository (Settings → Secrets and variables → Actions):
Required Secrets:
REPO_SYNC_TOKEN: Your GitHub Personal Access Token- Used for authenticating with the L6-N9 repository
Optional Secrets:
L6_N9_REPO: Target repository name (default:A6-9V/L6-N9)L6_N9_SYNC_BRANCH: Target branch name (default:main)REST_API_KEY: Your REST API authentication keyREST_API_URL: Your REST API endpoint URL (e.g.,https://api.example.com/sync)
3. Using the GitHub CLI (Optional)
You can set secrets using the GitHub CLI:
# Set the sync token
gh secret set REPO_SYNC_TOKEN --body "ghp_your_token_here"
# Set optional configuration
gh secret set L6_N9_REPO --body "A6-9V/L6-N9"
gh secret set L6_N9_SYNC_BRANCH --body "main"
# Set REST API credentials (if using)
gh secret set REST_API_KEY --body "your_api_key_here"
gh secret set REST_API_URL --body "https://api.example.com/sync"
4. Local Environment Setup
For local testing, create a .env file:
# Copy the example file
cp .env.example .env
# Edit with your values
nano .env
Add your credentials:
# Repository Sync Configuration
REPO_SYNC_TOKEN=ghp_your_token_here
L6_N9_REPO=A6-9V/L6-N9
L6_N9_SYNC_BRANCH=main
# REST API Configuration
REST_API_KEY=your_api_key_here
REST_API_URL=https://api.example.com/sync
REST_API_SYNC_ENABLED=true
Usage
Automatic Sync
The sync runs automatically:
- On push to main/master branch: Immediately syncs changes
- Scheduled: Every 6 hours (0:00, 6:00, 12:00, 18:00 UTC)
Manual Sync via GitHub Actions
- Go to your repository on GitHub
- Click Actions tab
- Select Repository Sync with L6-N9 workflow
- Click Run workflow
- Choose sync direction:
- push: Copy from A6-9V to L6-N9 (default)
- pull: Copy from L6-N9 to A6-9V
- bidirectional: Sync both ways
- Click Run workflow
Manual Sync via Command Line
# Check configuration
python3 scripts/repo_sync_manager.py --check-config
# Push changes to L6-N9 (default)
python3 scripts/repo_sync_manager.py
# Push changes explicitly
python3 scripts/repo_sync_manager.py --direction push
# Pull changes from L6-N9
python3 scripts/repo_sync_manager.py --direction pull
# Bidirectional sync
python3 scripts/repo_sync_manager.py --direction bidirectional
What Gets Synced
The following directories and files are synchronized:
Directories:
mt5/MQL5/- MT5 indicators and expert advisorsscripts/- Automation scriptsconfig/- Configuration filesdocs/- Documentation
Files:
README.md- Project documentationrequirements.txt- Python dependencies.env.example- Environment variable template
REST API Integration
API Endpoint Requirements
Your REST API endpoint should:
- Accept POST requests
- Handle JSON payloads
- Support Bearer token authentication
Request Format
{
"event": "repo_sync",
"source": "A6-9V/MQL5-Google-Onedrive",
"target": "A6-9V/L6-N9",
"direction": "push",
"timestamp": "2024-01-01T12:00:00Z",
"branch": "main",
"commit": "abc123...",
"phase": "start|complete|error",
"status": "success|failed"
}
Response Codes
200,201,202: Success401: Unauthorized (check API key)500: Server error
Troubleshooting
Sync Fails with Authentication Error
Problem: "Authentication failed" or "403 Forbidden"
Solution:
- Verify
REPO_SYNC_TOKENis set correctly - Check token has
reposcope - Ensure token hasn't expired
- Regenerate token if necessary
REST API Notification Fails
Problem: API notification returns error
Solution:
- Verify
REST_API_KEYis correct - Check
REST_API_URLis accessible - Review API endpoint logs
- Note: API failures are non-critical and won't stop the sync
No Changes Synced
Problem: Workflow completes but no changes appear in L6-N9
Solution:
- Check if there were actually changes to sync
- Verify the sync direction is correct
- Check L6-N9 repository permissions
- Review workflow logs for specific errors
Target Repository Not Found
Problem: "Repository not found" error
Solution:
- Verify
L6_N9_REPOvalue is correct (format:owner/repo) - Ensure token has access to the target repository
- Check if L6-N9 repository exists and is accessible
Security Best Practices
- Never commit tokens or API keys to the repository
- Use GitHub Secrets for all sensitive values
- Rotate tokens regularly (every 60-90 days)
- Use fine-grained permissions when possible
- Monitor sync activity through workflow logs
- Restrict API endpoints to known IP ranges if possible
CI/CD Integration
The sync workflow integrates with your CI/CD pipeline:
- Pre-sync validation: Checks configuration before syncing
- Post-sync notification: Sends status to REST API
- Failure handling: Non-critical failures don't block the workflow
- Summary report: Generates detailed summary in workflow logs
Monitoring
Check Sync Status
View recent syncs:
- Go to Actions tab
- Filter by Repository Sync with L6-N9 workflow
- Review recent runs and their status
Workflow Logs
Each sync generates a detailed log including:
- Configuration check results
- Files and directories synced
- API notification results
- Commit information
- Success/failure status
Advanced Configuration
Custom Sync Paths
Edit .github/workflows/repo-sync.yml to customize what gets synced:
# Add or remove directories
cp -r custom-dir target-repo/custom-dir/ || true
Sync Filters
Exclude specific files or directories:
# In the sync step
rsync -av --exclude='*.log' --exclude='temp/' source/ target/
Multiple Target Repositories
Create separate workflows for different targets:
- Copy
repo-sync.ymltorepo-sync-target2.yml - Update
TARGET_REPOenvironment variable - Add corresponding secrets
Support
For issues or questions:
- Review workflow logs in GitHub Actions
- Check GitHub Actions documentation
- Review REST API integration guide
- Contact repository maintainers