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