Sync Fork with Upstream #553
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: Sync Fork with Upstream | |
| on: | |
| schedule: | |
| - cron: "*/30 * * * *" | |
| workflow_dispatch: # Allows manual triggering | |
| jobs: | |
| sync: | |
| if: github.repository == 'ShreyashSri/pbctf' | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| branch: [prod, staging] # Each branch syncs from its matching upstream branch | |
| permissions: | |
| contents: write # Required to push to the repository | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ matrix.branch }} | |
| fetch-depth: 0 # Fetch all history for proper merging | |
| token: ${{ secrets.PAT_TOKEN }} | |
| - name: Configure Git | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Add upstream remote | |
| run: | | |
| UPSTREAM_REPO="https://github.com/pointblank-club/pbctf.git" | |
| # Check if upstream remote already exists | |
| if git remote | grep -q "^upstream$"; then | |
| git remote set-url upstream "$UPSTREAM_REPO" | |
| else | |
| git remote add upstream "$UPSTREAM_REPO" | |
| fi | |
| - name: Fetch upstream | |
| run: git fetch upstream | |
| - name: Merge upstream changes | |
| run: | | |
| BRANCH="${{ matrix.branch }}" | |
| git checkout $BRANCH | |
| # Try to merge from the matching upstream branch | |
| if git merge "upstream/$BRANCH" --no-edit; then | |
| echo "Successfully merged upstream/$BRANCH into $BRANCH" | |
| else | |
| echo "Merge failed or no changes to merge" | |
| # Check if there are actual conflicts or just no changes | |
| if [ -n "$(git status --porcelain)" ]; then | |
| echo "Merge conflicts detected, skipping push" | |
| exit 1 | |
| else | |
| echo "No changes to merge" | |
| exit 0 | |
| fi | |
| fi | |
| - name: Push changes | |
| run: | | |
| BRANCH="${{ matrix.branch }}" | |
| if git push origin $BRANCH; then | |
| echo "Successfully pushed changes to $BRANCH" | |
| else | |
| echo "No changes to push or push failed" | |
| exit 0 | |
| fi |