|
| 1 | +name: Sync Upstream |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Runs weekly on Monday at 9am UTC |
| 6 | + - cron: '0 9 * * 1' |
| 7 | + workflow_dispatch: # Manual trigger |
| 8 | + |
| 9 | +jobs: |
| 10 | + sync: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Checkout |
| 14 | + uses: actions/checkout@v4 |
| 15 | + with: |
| 16 | + fetch-depth: 0 |
| 17 | + |
| 18 | + - name: Configure Git |
| 19 | + run: | |
| 20 | + git config user.name "github-actions[bot]" |
| 21 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 22 | +
|
| 23 | + - name: Add upstream remote |
| 24 | + run: git remote add upstream https://github.com/gitroomhq/postiz-app.git || true |
| 25 | + |
| 26 | + - name: Fetch upstream |
| 27 | + run: git fetch upstream |
| 28 | + |
| 29 | + - name: Check for updates |
| 30 | + id: check |
| 31 | + run: | |
| 32 | + BEHIND=$(git rev-list --count HEAD..upstream/main) |
| 33 | + echo "behind=$BEHIND" >> $GITHUB_OUTPUT |
| 34 | + if [ "$BEHIND" -gt 0 ]; then |
| 35 | + echo "::notice::$BEHIND commits behind upstream" |
| 36 | + fi |
| 37 | +
|
| 38 | + - name: Create sync branch and PR |
| 39 | + if: steps.check.outputs.behind > 0 |
| 40 | + env: |
| 41 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 42 | + run: | |
| 43 | + BRANCH="sync-upstream-$(date +%Y%m%d)" |
| 44 | + git checkout -b $BRANCH |
| 45 | + git merge upstream/main --no-edit || true |
| 46 | +
|
| 47 | + # Check if there are conflicts |
| 48 | + if git diff --name-only --diff-filter=U | grep -q .; then |
| 49 | + echo "::warning::Merge conflicts detected - manual resolution required" |
| 50 | + git merge --abort |
| 51 | + git checkout main |
| 52 | +
|
| 53 | + # Create issue instead of PR |
| 54 | + gh issue create \ |
| 55 | + --title "Upstream sync has conflicts - $(date +%Y-%m-%d)" \ |
| 56 | + --body "Upstream has updates but automatic merge failed due to conflicts. |
| 57 | +
|
| 58 | + **Commits behind:** ${{ steps.check.outputs.behind }} |
| 59 | +
|
| 60 | + To resolve manually: |
| 61 | + \`\`\`bash |
| 62 | + git fetch upstream |
| 63 | + git merge upstream/main |
| 64 | + # resolve conflicts |
| 65 | + git commit |
| 66 | + git push |
| 67 | + \`\`\`" |
| 68 | + else |
| 69 | + git push origin $BRANCH |
| 70 | + gh pr create \ |
| 71 | + --title "Sync upstream changes - $(date +%Y-%m-%d)" \ |
| 72 | + --body "Automated PR to sync with upstream Postiz repository. |
| 73 | +
|
| 74 | + **Commits behind:** ${{ steps.check.outputs.behind }} |
| 75 | +
|
| 76 | + Review the changes and merge when ready." \ |
| 77 | + --base main \ |
| 78 | + --head $BRANCH |
| 79 | + fi |
0 commit comments