name: Repository Sync with L6-N9 on: workflow_dispatch: inputs: sync_direction: description: 'Sync direction' required: true default: 'push' type: choice options: - push - pull - bidirectional push: branches: - main - master schedule: # Run auto-sync every 6 hours - cron: '0 */6 * * *' permissions: contents: write concurrency: group: repo-sync-${{ github.ref }} cancel-in-progress: false jobs: sync-repositories: runs-on: ubuntu-latest env: # Target repository for sync TARGET_REPO: ${{ secrets.L6_N9_REPO || 'A6-9V/L6-N9' }} SYNC_BRANCH: ${{ secrets.L6_N9_SYNC_BRANCH || 'main' }} steps: - name: Checkout source repository uses: actions/checkout@v4 with: fetch-depth: 0 token: ${{ secrets.REPO_SYNC_TOKEN || secrets.GITHUB_TOKEN }} - name: Check sync configuration id: check_config env: SYNC_TOKEN: ${{ secrets.REPO_SYNC_TOKEN }} REST_API_KEY: ${{ secrets.REST_API_KEY }} run: | if [[ -z "${SYNC_TOKEN:-}" ]]; then echo "SYNC_ENABLED=false" >> "$GITHUB_ENV" echo "⚠️ Skipping repository sync: REPO_SYNC_TOKEN not configured." exit 0 fi echo "SYNC_ENABLED=true" >> "$GITHUB_ENV" if [[ -z "${REST_API_KEY:-}" ]]; then echo "⚠️ Warning: REST_API_KEY not configured. API authentication will be skipped." else echo "✅ REST API key configured for secure sync." fi - name: Setup Git if: env.SYNC_ENABLED == 'true' run: | git config --global user.name "github-actions[bot]" git config --global user.email "github-actions[bot]@users.noreply.github.com" - name: Clone target repository (L6-N9) if: env.SYNC_ENABLED == 'true' env: SYNC_TOKEN: ${{ secrets.REPO_SYNC_TOKEN }} run: | git clone https://${SYNC_TOKEN}@github.com/${TARGET_REPO}.git target-repo cd target-repo git checkout ${SYNC_BRANCH} || git checkout -b ${SYNC_BRANCH} - name: Sync changes to L6-N9 if: env.SYNC_ENABLED == 'true' run: | # Determine sync direction SYNC_DIRECTION="${{ github.event.inputs.sync_direction || 'push' }}" echo "🔄 Syncing with direction: ${SYNC_DIRECTION}" if [[ "${SYNC_DIRECTION}" == "push" || "${SYNC_DIRECTION}" == "bidirectional" ]]; then echo "📤 Pushing changes to L6-N9..." # Copy selected directories to target mkdir -p target-repo/mt5 cp -r mt5/MQL5 target-repo/mt5/ || true mkdir -p target-repo/scripts cp -r scripts/* target-repo/scripts/ || true mkdir -p target-repo/config cp -r config/* target-repo/config/ || true mkdir -p target-repo/docs cp -r docs/* target-repo/docs/ || true # Copy configuration files cp README.md target-repo/ || true cp requirements.txt target-repo/ || true cp .env.example target-repo/ || true fi if [[ "${SYNC_DIRECTION}" == "pull" || "${SYNC_DIRECTION}" == "bidirectional" ]]; then echo "📥 Pulling changes from L6-N9..." # Pull specific updates from L6-N9 if configured # This can be customized based on what should be synced back fi - name: Notify REST API endpoint if: env.SYNC_ENABLED == 'true' env: REST_API_KEY: ${{ secrets.REST_API_KEY }} REST_API_URL: ${{ secrets.REST_API_URL }} run: | if [[ -n "${REST_API_URL:-}" && -n "${REST_API_KEY:-}" ]]; then echo "📡 Notifying REST API endpoint..." PAYLOAD=$(cat <> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY echo "- **Source**: A6-9V/MQL5-Google-Onedrive" >> $GITHUB_STEP_SUMMARY echo "- **Target**: ${TARGET_REPO}" >> $GITHUB_STEP_SUMMARY echo "- **Branch**: ${SYNC_BRANCH}" >> $GITHUB_STEP_SUMMARY echo "- **Commit**: ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY echo "- **Time**: $(date -u --iso-8601=seconds)" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY echo "✅ Sync completed successfully!" >> $GITHUB_STEP_SUMMARY