|
| 1 | +name: Universal Fork Sync Workflow (ostrojs & any fork) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + - dev |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + universal-sync: |
| 14 | + name: Universal Branch Sync (ostrojs & any fork) |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + # Prevent infinite loop if commit message contains [skip sync] or is from bot |
| 18 | + if: | |
| 19 | + !contains(github.event.head_commit.message, '[skip sync]') && |
| 20 | + github.actor != 'github-actions[bot]' |
| 21 | +
|
| 22 | + steps: |
| 23 | + - name: Checkout repository |
| 24 | + uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + fetch-depth: 0 |
| 27 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 28 | + |
| 29 | + - name: Configure Git User |
| 30 | + run: | |
| 31 | + git config user.name "github-actions[bot]" |
| 32 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 33 | +
|
| 34 | + - name: Branch Sync Operations |
| 35 | + env: |
| 36 | + GH_TOKEN: ${{ secrets.SYNC_TOKEN || secrets.GITHUB_TOKEN }} |
| 37 | + REPO_OWNER: ${{ github.repository_owner }} |
| 38 | + REPO_NAME: ${{ github.event.repository.name }} |
| 39 | + REF_NAME: ${{ github.ref_name }} |
| 40 | + CROSS_REPO_TOKEN: ${{ secrets.SYNC_TOKEN || secrets.GITHUB_TOKEN }} |
| 41 | + run: | |
| 42 | + echo "==================================================" |
| 43 | + echo "Repository Owner : $REPO_OWNER" |
| 44 | + echo "Repository Name : $REPO_NAME" |
| 45 | + echo "Push Branch : $REF_NAME" |
| 46 | + echo "==================================================" |
| 47 | +
|
| 48 | + if [ "$REPO_OWNER" == "ostrojs" ]; then |
| 49 | + if [ "$REF_NAME" == "master" ]; then |
| 50 | + echo "--> [OSTROJS MASTER PUSH] Merging ostrojs/master -> ostrojs/dev..." |
| 51 | + git fetch origin dev 2>/dev/null || true |
| 52 | + git checkout dev 2>/dev/null || git checkout -b dev origin/dev 2>/dev/null || true |
| 53 | + git merge master --no-edit -X theirs || git rebase master || true |
| 54 | + git push origin dev || git push origin dev --force-with-lease |
| 55 | + fi |
| 56 | + else |
| 57 | + echo "--> [FORK REPO EVENT ($REPO_OWNER)] Syncing ostrojs/dev -> $REPO_OWNER/dev..." |
| 58 | + gh repo sync "$REPO_OWNER/$REPO_NAME" --branch "dev" --source "ostrojs/$REPO_NAME:dev" || { |
| 59 | + echo "--> Fast-forwarding / pushing directly from upstream ostrojs/dev..." |
| 60 | + git remote add upstream "https://github.com/ostrojs/${REPO_NAME}.git" 2>/dev/null || true |
| 61 | + git fetch upstream dev 2>/dev/null || true |
| 62 | + git push origin upstream/dev:refs/heads/dev --force-with-lease || true |
| 63 | + } |
| 64 | + fi |
0 commit comments