|
| 1 | +# Safety net for the event-driven dispatch_build_scoped_rector.yaml in each rector-* sibling. |
| 2 | +# If a sibling's merged-PR dispatch is ever dropped, this cron notices the newer sibling main |
| 3 | +# and re-runs build_scoped_rector.yaml. It is a backstop, not the primary trigger. |
| 4 | +name: Poll Siblings And Rebuild |
| 5 | + |
| 6 | +on: |
| 7 | + schedule: |
| 8 | + # every 15 min; GitHub floors scheduled runs at ~5 min and delays high-frequency crons |
| 9 | + - cron: '*/15 * * * *' |
| 10 | + workflow_dispatch: null |
| 11 | + |
| 12 | +permissions: |
| 13 | + actions: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + poll_siblings_rebuild: |
| 17 | + # only on the canonical repo, never forks |
| 18 | + if: github.repository == 'rectorphp/rector-src' |
| 19 | + |
| 20 | + runs-on: ubuntu-latest |
| 21 | + timeout-minutes: 10 |
| 22 | + |
| 23 | + steps: |
| 24 | + - |
| 25 | + name: "Rebuild if any sibling main is newer than the last scoped build" |
| 26 | + env: |
| 27 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 28 | + run: | |
| 29 | + set -euo pipefail |
| 30 | +
|
| 31 | + SIBLINGS="rector-phpunit rector-doctrine rector-symfony rector-downgrade-php" |
| 32 | +
|
| 33 | + # skip while rector-src main sits on a tagged release commit; the tag/empty-commit |
| 34 | + # path is handled by the sibling dispatcher, not by this backstop |
| 35 | + MAIN_SHA=$(gh api repos/rectorphp/rector-src/commits/main --jq '.sha') |
| 36 | + if gh api repos/rectorphp/rector-src/tags --jq '.[].commit.sha' | grep -qx "$MAIN_SHA"; then |
| 37 | + echo "rector-src main $MAIN_SHA is a tagged commit, skipping" |
| 38 | + exit 0 |
| 39 | + fi |
| 40 | +
|
| 41 | + # start of the most recent build_scoped_rector run (any conclusion) |
| 42 | + LAST_BUILD=$(gh api \ |
| 43 | + repos/rectorphp/rector-src/actions/workflows/build_scoped_rector.yaml/runs \ |
| 44 | + --jq '.workflow_runs[0].created_at // "1970-01-01T00:00:00Z"') |
| 45 | + LAST_BUILD_TS=$(date -d "$LAST_BUILD" +%s) |
| 46 | + echo "last scoped build: $LAST_BUILD" |
| 47 | +
|
| 48 | + NEWER=0 |
| 49 | + for SIB in $SIBLINGS; do |
| 50 | + COMMIT_DATE=$(gh api "repos/rectorphp/$SIB/commits/main" --jq '.commit.committer.date') |
| 51 | + COMMIT_TS=$(date -d "$COMMIT_DATE" +%s) |
| 52 | + if [ "$COMMIT_TS" -gt "$LAST_BUILD_TS" ]; then |
| 53 | + echo "$SIB main ($COMMIT_DATE) is newer than the last build" |
| 54 | + NEWER=1 |
| 55 | + else |
| 56 | + echo "$SIB main ($COMMIT_DATE) already built" |
| 57 | + fi |
| 58 | + done |
| 59 | +
|
| 60 | + if [ "$NEWER" -eq 1 ]; then |
| 61 | + echo "Dispatching build_scoped_rector.yaml" |
| 62 | + gh workflow run build_scoped_rector.yaml --repo rectorphp/rector-src --ref main |
| 63 | + else |
| 64 | + echo "All siblings already built, nothing to do" |
| 65 | + fi |
0 commit comments