|
| 1 | +# SPDX-FileCopyrightText: 2026 The RISE Project |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +name: PR package build trigger |
| 5 | + |
| 6 | +on: |
| 7 | + pull_request: |
| 8 | + types: [opened, edited, synchronize, reopened] |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: read |
| 12 | + actions: write |
| 13 | + pull-requests: read |
| 14 | + |
| 15 | +jobs: |
| 16 | + dispatch-triggers: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + if: contains(github.event.pull_request.body, 'Trigger:') |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + package_version: ${{ github.event.pull_request.head.sha }} |
| 23 | + |
| 24 | + - name: Dispatch build/test workflows for Trigger directives |
| 25 | + env: |
| 26 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 27 | + PR_BODY: ${{ github.event.pull_request.body }} |
| 28 | + HEAD_REF: ${{ github.event.pull_request.head.ref }} |
| 29 | + HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }} |
| 30 | + BASE_REPO: ${{ github.repository }} |
| 31 | + run: | |
| 32 | + set -euo pipefail |
| 33 | +
|
| 34 | + if [ "$HEAD_REPO" != "$BASE_REPO" ]; then |
| 35 | + echo "PR from fork ($HEAD_REPO); cannot dispatch workflows against fork ref. Skipping." |
| 36 | + exit 0 |
| 37 | + fi |
| 38 | +
|
| 39 | + triggers=$(printf '%s\n' "$PR_BODY" | grep -oE '^Trigger:[[:space:]]*[^[:space:]]+' || true) |
| 40 | +
|
| 41 | + if [ -z "$triggers" ]; then |
| 42 | + echo "No Trigger: directives found." |
| 43 | + exit 0 |
| 44 | + fi |
| 45 | +
|
| 46 | + printf '%s\n' "$triggers" | while IFS= read -r line; do |
| 47 | + directive=${line#Trigger:} |
| 48 | + directive=${directive# } |
| 49 | + package_name=${directive%:*} |
| 50 | + package_version=${directive#*:} |
| 51 | +
|
| 52 | + if [ -z "$package_name" ] || [ -z "$package_version" ] || [ "$package_name" = "$package_version" ]; then |
| 53 | + echo "Skipping malformed directive: $line" |
| 54 | + continue |
| 55 | + fi |
| 56 | +
|
| 57 | + # Normalize: build workflows prepend `v` to the version themselves |
| 58 | + # (e.g. `ref: v${{ env.NUMPY_VERSION }}`). Strip any leading v/V |
| 59 | + # in the directive so `Trigger: numpy:v2.5.1` and |
| 60 | + # `Trigger: numpy:2.5.1` behave identically. |
| 61 | + package_version=${package_version#[vV]} |
| 62 | +
|
| 63 | + build_wf=".github/workflows/build-${package_name}.yml" |
| 64 | + test_wf=".github/workflows/test-${package_name}.yml" |
| 65 | +
|
| 66 | + if [ ! -f "$build_wf" ]; then |
| 67 | + echo "No build workflow for $package_name at $build_wf; skipping." |
| 68 | + continue |
| 69 | + fi |
| 70 | +
|
| 71 | + echo "Dispatching build-${package_name}.yml on $HEAD_REF with version=$package_version" |
| 72 | + gh workflow run "build-${package_name}.yml" --ref "$HEAD_REF" -f "version=$package_version" |
| 73 | +
|
| 74 | + if [ -f "$test_wf" ]; then |
| 75 | + echo "Dispatching test-${package_name}.yml on $HEAD_REF with version=$package_version" |
| 76 | + gh workflow run "test-${package_name}.yml" --ref "$HEAD_REF" -f "version=$package_version" |
| 77 | + fi |
| 78 | + done |
0 commit comments