Skip to content

Rebuild scoped Rector after a pull request is merged#962

Merged
TomasVotruba merged 1 commit into
mainfrom
dispatch-build-scoped-rector
Jul 15, 2026
Merged

Rebuild scoped Rector after a pull request is merged#962
TomasVotruba merged 1 commit into
mainfrom
dispatch-build-scoped-rector

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Port of rectorphp/rector-phpunit#730 and rectorphp/rector-phpunit#731 to this repository.

Merging a rule pull request here changes rectorphp/rector only once something else lands in rector-src main and retriggers its build. This dispatches that build directly instead.

New .github/workflows/dispatch_build_scoped_rector.yaml, identical to the rector-phpunit one except for the repository guard:

on:
    pull_request:
        types:
            - closed

jobs:
    dispatch_build_scoped_rector:
        # only for merged pull requests in this repository, not forks
        if: github.event.pull_request.merged == true && github.repository == 'rectorphp/rector-symfony'

pull_request: closed fires on every close, so the merged == true check is what limits it to merges. Closed-without-merge dispatches nothing. Reuses the ACCESS_TOKEN secret already used by rector.yaml.yml.

Tag check

Carried over from rector-phpunit#731. When rector-src main sits on a release tag commit, that commit is already being published to rectorphp/rector by the tag build. Dispatching a second build makes the two race each other for git push origin main, and the loser fails on a non fast forward push.

git ls-remote --tags is used rather than the tags API because git/refs/tags exposes the sha of the tag object for an annotated tag, not of the commit, so a comparison against a commit sha silently never matches. ls-remote lists a lightweight tag with the commit itself and an annotated tag with an extra ^{} line, so matching on line start covers both.

Verified

Preconditions checked against live repositories rather than assumed:

  • build_scoped_rector.yaml in rector-src carries workflow_dispatch: null, commented "allows rector-* package repositories to rebuild after their pull request is merged", so gh workflow run resolves here. (This was the HTTP 422 blocker in rector-phpunit#730; Allow dispatching Build Scoped Rector manually rector-src#8188 has since landed.)
  • ACCESS_TOKEN already exists in this repository, used by rector.yaml.yml.

The tag-check script was run as is against live rector-src:

  • main c607ef0, untagged, writes no output, so the dispatch runs
  • lightweight tag 2.5.7 (653ec23), detected, writes tagged=true, so the dispatch is skipped

Two things worth confirming before merging

ACCESS_TOKEN needs actions: write on rectorphp/rector-src. rector.yaml.yml only uses it to push to this repository, so cross-repository scope is unconfirmed here just as it was in rector-phpunit#730 — if that has since been verified for rector-phpunit, the same token settings apply and this is a non-issue.

The dispatch fires at merge time, but the build resolves rector-symfony dev-main through Packagist, which can lag a merge by a few minutes. A dispatched build may rebuild against the previous main. A Packagist update hook on this repository is the fix; not included here.

Port of rectorphp/rector-phpunit#730 and #731. Merging a rule pull request
here only reaches rectorphp/rector once something else lands in rector-src
main and retriggers its build. This dispatches that build directly.

The tag check skips the dispatch when rector-src main sits on a release tag
commit, which the tag build is already publishing, to avoid racing it for
the push to rectorphp/rector.
@TomasVotruba TomasVotruba enabled auto-merge (squash) July 15, 2026 09:01
@TomasVotruba TomasVotruba merged commit edc3ebf into main Jul 15, 2026
8 checks passed
@TomasVotruba TomasVotruba deleted the dispatch-build-scoped-rector branch July 15, 2026 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant