forked from deepinv/deepinv
-
Notifications
You must be signed in to change notification settings - Fork 0
142 lines (125 loc) · 5.12 KB
/
gpu_trigger.yml
File metadata and controls
142 lines (125 loc) · 5.12 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: PR Comment Trigger
on:
issue_comment:
types: [created]
workflow_dispatch:
inputs:
pr_number:
description: "PR number to trigger tests for"
required: true # Making this required for manual runs
type: string # Inputs are always strings
permissions:
pull-requests: write
issues: write
contents: read
actions: write # Needed to trigger other workflows
jobs:
trigger-gpu-workflows:
# Run on manual trigger OR if a comment on a PR starts with "/gpu-tests"
if: >
github.event_name == 'workflow_dispatch' ||
(github.event.issue.pull_request && startsWith(github.event.comment.body, '/gpu-tests'))
runs-on: ubuntu-latest
steps:
- name: Get PR number
id: pr
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "pr_number=${{ github.event.inputs.pr_number }}" >> $GITHUB_OUTPUT
else
echo "pr_number=${{ github.event.issue.number }}" >> $GITHUB_OUTPUT
fi
- name: Verify commenter permissions
if: github.event_name == 'issue_comment'
id: check
uses: actions/github-script@v7
with:
script: |
const commenter = context.payload.comment.user.login;
const { data: perm } = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username: commenter
});
// Valid permissions are 'admin', 'write', 'read', 'none'
core.setOutput('permission', perm.permission);
- name: Stop if user is not a maintainer
if: github.event_name == 'issue_comment' && steps.check.outputs.permission != 'admin' && steps.check.outputs.permission != 'write'
run: |
echo "❌ User @${{ github.event.comment.user.login }} is not authorized (needs write/admin access to trigger workflows)."
exit 1
- name: Add 'Rocket' reaction to comment
if: github.event_name == 'issue_comment'
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ github.event.comment.id }}
reactions: rocket
- name: Trigger GPU Tests
uses: benc-uk/workflow-dispatch@v1
with:
workflow: test_gpu.yml
ref: ${{ github.event.pull_request.head.ref }}
inputs: '{ "pr_number": "${{ steps.pr.outputs.pr_number }}" }'
- name: Trigger GPU Docs Check
uses: benc-uk/workflow-dispatch@v1
with:
workflow: gpu_docs.yml
ref: ${{ github.event.pull_request.head.ref }}
inputs: '{ "pr_number": "${{ steps.pr.outputs.pr_number }}" }'
post-comment:
needs: trigger-gpu-workflows
if: needs.trigger-gpu-workflows.result == 'success'
runs-on: ubuntu-latest
steps:
- name: Post confirmation comment
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.issue.number || inputs.pr_number }}
body: |
🚀 GPU test workflows successfully triggered!
token: ${{ secrets.GITHUB_TOKEN }}
trigger-examples-workflows:
# Run on manual trigger OR if a comment on a PR starts with "/test-examples"
if: >
(github.event.issue.pull_request && startsWith(github.event.comment.body, '/test-examples'))
runs-on: ubuntu-latest
steps:
- name: Get PR number
id: pr
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "pr_number=${{ github.event.inputs.pr_number }}" >> $GITHUB_OUTPUT
else
echo "pr_number=${{ github.event.issue.number }}" >> $GITHUB_OUTPUT
fi
- name: Verify commenter permissions
if: github.event_name == 'issue_comment'
id: check
uses: actions/github-script@v7
with:
script: |
const commenter = context.payload.comment.user.login;
const { data: perm } = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username: commenter
});
// Valid permissions are 'admin', 'write', 'read', 'none'
core.setOutput('permission', perm.permission);
- name: Stop if user is not a maintainer
if: github.event_name == 'issue_comment' && steps.check.outputs.permission != 'admin' && steps.check.outputs.permission != 'write'
run: |
echo "❌ User @${{ github.event.comment.user.login }} is not authorized (needs write/admin access to trigger workflows)."
exit 1
- name: Add 'Rocket' reaction to comment
if: github.event_name == 'issue_comment'
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ github.event.comment.id }}
reactions: rocket
- name: Trigger CPU Docs Check
uses: benc-uk/workflow-dispatch@v1
with:
workflow: documentation.yml
ref: ${{ github.event.pull_request.head.ref }}
inputs: '{ "pr_number": "${{ steps.pr.outputs.pr_number }}" }'