Auto-Sync to GitHub #469
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
| name: Auto-Sync to GitHub | |
| on: | |
| workflow_dispatch: # Allows manual triggering | |
| schedule: | |
| - cron: '0 */6 * * *' # Run every 6 hours | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ github.token }} | |
| - name: Set up Git | |
| run: | | |
| git config --global user.name "GitHub Actions Bot" | |
| git config --global user.email "actions@github.com" | |
| - name: Check if Replit repo URL is configured | |
| id: check-replit | |
| env: | |
| REPLIT_URL: ${{ secrets.REPLIT_REPO_URL }} | |
| run: | | |
| if [[ -z "$REPLIT_URL" ]]; then | |
| echo "REPLIT_REPO_CONFIGURED=false" >> $GITHUB_OUTPUT | |
| echo "Replit repository URL is not configured. Skipping sync." | |
| else | |
| echo "REPLIT_REPO_CONFIGURED=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Pull from Replit | |
| if: steps.check-replit.outputs.REPLIT_REPO_CONFIGURED == 'true' | |
| env: | |
| REPLIT_URL: ${{ secrets.REPLIT_REPO_URL }} | |
| run: | | |
| # Add Replit as a remote repository | |
| echo "Adding Replit remote repository..." | |
| git remote add replit "$REPLIT_URL" | |
| # Fetch from Replit | |
| echo "Fetching from Replit..." | |
| if ! git fetch replit; then | |
| echo "Failed to fetch from Replit. Check the repository URL and credentials." | |
| exit 1 | |
| fi | |
| - name: Merge changes | |
| if: steps.check-replit.outputs.REPLIT_REPO_CONFIGURED == 'true' | |
| run: | | |
| # Check if replit/main branch exists | |
| if ! git show-ref --verify --quiet refs/remotes/replit/main; then | |
| echo "Replit main branch not found. Checking for other branches..." | |
| REPLIT_BRANCH=$(git branch -r | grep replit | head -n 1 | tr -d ' ') | |
| if [ -z "$REPLIT_BRANCH" ]; then | |
| echo "No Replit branches found. Skipping merge." | |
| exit 0 | |
| else | |
| echo "Found Replit branch: $REPLIT_BRANCH" | |
| BRANCH_TO_MERGE=$REPLIT_BRANCH | |
| fi | |
| else | |
| BRANCH_TO_MERGE="replit/main" | |
| fi | |
| echo "Attempting to merge $BRANCH_TO_MERGE..." | |
| # Try to merge changes from Replit's branch | |
| if git merge $BRANCH_TO_MERGE --allow-unrelated-histories -X theirs; then | |
| echo "Merge successful!" | |
| else | |
| echo "Merge conflict detected. Resolving in favor of Replit version..." | |
| git checkout --theirs . | |
| git add . | |
| git commit -m "Resolve merge conflicts in favor of Replit version" | |
| fi | |
| - name: Push to GitHub | |
| if: steps.check-replit.outputs.REPLIT_REPO_CONFIGURED == 'true' | |
| run: | | |
| echo "Pushing changes to GitHub..." | |
| git push origin main |