diff --git a/.github/workflows/auto-update-prs.yml b/.github/workflows/auto-update-prs.yml new file mode 100644 index 0000000..61ac774 --- /dev/null +++ b/.github/workflows/auto-update-prs.yml @@ -0,0 +1,36 @@ +name: Auto-update PRs + +on: + push: + branches: [main] + +# Serialize so two close-together merges don't race the update API. +concurrency: + group: auto-update-prs + cancel-in-progress: false + +permissions: + pull-requests: write + contents: write + +jobs: + update: + runs-on: ubuntu-latest + steps: + - name: Update PRs labeled 'updateme' to latest main + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + set -euo pipefail + gh pr list --repo "$GITHUB_REPOSITORY" --state open --label updateme --limit 200 \ + --json number,isCrossRepository,baseRefName \ + --jq '.[] | select(.baseRefName == "main") | "\(.number) \(.isCrossRepository)"' \ + | while read -r num is_fork; do + if [ "$is_fork" = "true" ]; then + echo "Skip PR #$num (fork — cannot push via GITHUB_TOKEN)" + continue + fi + echo "Updating PR #$num" + gh pr update-branch "$num" --repo "$GITHUB_REPOSITORY" \ + || echo " -> PR #$num: update-branch failed (see preceding gh output; possible causes: merge conflict, branch protection, transient API error)" + done diff --git a/README.md b/README.md index 4e352f4..9650b1f 100644 --- a/README.md +++ b/README.md @@ -90,3 +90,14 @@ Demonstrates most `get...()` methods. [Asyncio](https://docs.python.org/3/library/asyncio.html) might seem intimidating in the beginning, but for basic stuff, it is quite easy to follow the examples above, and just remeber to prefix functions that use the API with `async def ...` and to `await` all API-calls and all calls to said functions. [This article](https://realpython.com/async-io-python/) will give a nice introduction to both why, when and how to use asyncio in projects. + +## Contributing + +### Keeping a PR up to date with `main` + +Add the `updateme` label to a PR targeting `main` and a GitHub Actions workflow will automatically merge `main` into the PR branch every time `main` advances. This is opt-in: PRs without the label are left alone. + +Limitations: +- Only acts on PRs whose base branch is `main`. PRs targeting other branches are ignored even with the label. +- Only works for PRs from branches in this repository. PRs from forks cannot be pushed to via the workflow's token and will be skipped (the workflow logs which PRs it skipped). +- If `gh pr update-branch` fails for a given PR (merge conflict, branch protection rule, transient API error, etc.), that PR is skipped for this run and the failure is logged. The label stays on, so the next push to `main` will retry automatically.