Skip to content
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

Automate syncing main branch with staging #15

Open
mtuchi opened this issue May 31, 2024 · 1 comment
Open

Automate syncing main branch with staging #15

mtuchi opened this issue May 31, 2024 · 1 comment

Comments

@mtuchi
Copy link
Collaborator

mtuchi commented May 31, 2024

Background:

Maintaining synchronization between the main branch (production) and the staging branch (development) is crucial for ensuring that changes made in the development environment are properly tested before being deployed to production. Automating this synchronization process will streamline our workflow and reduce the likelihood of manual errors or discrepancies between branches.

Request:

Create an automation workflow that automatically syncs changes from the main branch to the staging branch on GitHub. This workflow should trigger whenever changes are pushed to the main branch, ensuring that the staging branch remains up-to-date with the latest production code.

Workflow Steps:

  1. Trigger: The workflow should be triggered by a push event to the main branch.
  2. Syncing: Upon triggering, the workflow should:
    • Checkout the staging branch.
    • Pull changes from the main branch.
    • Push the updated staging branch to the repository.

Testing:

Test the automation workflow by pushing changes to the main branch and verifying that the staging branch is automatically updated accordingly. Additionally, manual verification can be performed by reviewing the commit history and branch status on GitHub.

Additional Notes:

  • Ensure that appropriate access permissions are set to allow the workflow to perform the required actions.
  • Consider implementing error handling and notifications in case of any issues during the synchronization process.
@mtuchi
Copy link
Collaborator Author

mtuchi commented May 31, 2024

Sync Main to Staging GitHub workflow

This is chatGPT sample code, i am not expecting it to work out of the box. The idea is it should handle automate sync of main to staging and incase of merge conflict it should open a PR instead.

name: Sync Main to Staging

on:
  push:
    branches:
      - main

jobs:
  sync_main_to_staging:
    runs-on: ubuntu-latest
    
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Set up Git
        run: |
          git config --global user.name 'github-actions[bot]'
          git config --global user.email 'github-actions[bot]@users.noreply.github.com'

      - name: Merge main into staging
        run: |
          git checkout staging
          git pull origin staging
          git merge --no-ff origin/main || echo "Merge conflict detected" > merge_conflict.txt
          if [ -f merge_conflict.txt ]; then 
            echo "::set-output name=merge_conflict::true" 
            exit 1 
          fi
          git push origin staging

      - name: Create PR if conflict
        if: steps.merge_main_into_staging.outputs.merge_conflict == 'true'
        uses: peter-evans/create-pull-request@v3
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          commit-message: Automatically create PR for conflict resolution
          title: Resolve conflicts between main and staging branches
          labels: conflict
          branch: staging
          base: main
          body: |
            Automatic PR created to resolve conflicts between main and staging branches.
            Please review and resolve conflicts as necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant