|
| 1 | +name: Sync from upstream |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + schedule: |
| 6 | + - cron: "17 * * * *" |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + pull-requests: write |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: sync-upstream |
| 14 | + cancel-in-progress: false |
| 15 | + |
| 16 | +jobs: |
| 17 | + sync: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + env: |
| 20 | + UPSTREAM_REPO: ReactiveDrop/reactivedrop_public_src |
| 21 | + SYNC_BRANCH: chore/sync-upstream |
| 22 | + steps: |
| 23 | + - name: Checkout fork |
| 24 | + uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + fetch-depth: 0 |
| 27 | + |
| 28 | + - name: Sync branch with upstream |
| 29 | + id: sync |
| 30 | + env: |
| 31 | + BASE_BRANCH: ${{ github.event.repository.default_branch }} |
| 32 | + run: | |
| 33 | + set -euo pipefail |
| 34 | +
|
| 35 | + git remote add upstream "https://github.com/${UPSTREAM_REPO}.git" |
| 36 | + git fetch origin "$BASE_BRANCH" |
| 37 | + git fetch upstream "$BASE_BRANCH" --prune |
| 38 | +
|
| 39 | + upstream_ahead_count="$(git rev-list --count "origin/$BASE_BRANCH..upstream/$BASE_BRANCH")" |
| 40 | + if [ "$upstream_ahead_count" -eq 0 ]; then |
| 41 | + echo "has_updates=false" >> "$GITHUB_OUTPUT" |
| 42 | + exit 0 |
| 43 | + fi |
| 44 | +
|
| 45 | + git checkout -B "$SYNC_BRANCH" "upstream/$BASE_BRANCH" |
| 46 | + git push --force-with-lease origin "$SYNC_BRANCH" |
| 47 | + echo "has_updates=true" >> "$GITHUB_OUTPUT" |
| 48 | +
|
| 49 | + - name: Create pull request |
| 50 | + if: steps.sync.outputs.has_updates == 'true' |
| 51 | + env: |
| 52 | + BASE_BRANCH: ${{ github.event.repository.default_branch }} |
| 53 | + GH_TOKEN: ${{ github.token }} |
| 54 | + run: | |
| 55 | + set -euo pipefail |
| 56 | +
|
| 57 | + existing_pr="$(gh pr list --state open --head "$SYNC_BRANCH" --base "$BASE_BRANCH" --json number --jq '.[0].number')" |
| 58 | + if [ -n "$existing_pr" ]; then |
| 59 | + echo "PR #$existing_pr already open." |
| 60 | + exit 0 |
| 61 | + fi |
| 62 | +
|
| 63 | + gh pr create \ |
| 64 | + --base "$BASE_BRANCH" \ |
| 65 | + --head "$SYNC_BRANCH" \ |
| 66 | + --title "Sync from upstream" \ |
| 67 | + --body "Automated sync from upstream." |
| 68 | +
|
0 commit comments