-
Notifications
You must be signed in to change notification settings - Fork 8
108 lines (101 loc) · 4.71 KB
/
Copy pathtrigger-colab-tests-pr.yml
File metadata and controls
108 lines (101 loc) · 4.71 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
name: Trigger Colab CI Tests for Pull Request
on:
issue_comment:
types: [created]
defaults:
run:
shell: bash -leo pipefail {0}
jobs:
trigger-tests-from-comment:
name: "Trigger Colab CI Tests from PR Comment"
runs-on: ubuntu-latest
# run if all of the following are true:
# - the comment was made on a pull request (rather than an issue)
# - the base of the pull request is ContextLab/davos
# - the head of the pull request is a different fork (rather than just a branch)
# - the comment was made by paxtonfitzpatrick
# - the github-actions bot was tagged at the beginning of the comment
if: >
github.event.issue.pull_request
&& github.repository_owner == 'ContextLab'
&& github.event.issue.user.login != 'ContextLab'
&& (github.event.comment.user.login == 'paxtonfitzpatrick' || github.event.comment.user.login == 'jeremymanning')
&& startsWith(github.event.comment.body, '@github-actions ')
steps:
- name: Check Whether Comment Triggers Workflow
id: check-comment
uses: actions/github-script@v4
with:
script: |
console.log(`Possible dispatch comment by ${context.payload.comment.user.login} on pull PR #${context.issue.number}`)
// keywords that trigger Colab CI tests
const approveStrings = ['approve', 'run', 'yes', '👍'],
// comment body with @github-actions bot tag removed
commentBody = context.payload.comment.body.replace(/@github-actions\s+/, '');
console.log(`parsing possible dispatch trigger comment:
${context.payload.comment.body}
for dispatch keywords:
${approveStrings}`)
// if the comment contains any of the keyword strings
if (approveStrings.some(str => commentBody.includes(str))) {
console.log('comment contains dispatch keyword');
try {
// request pull_request event from rest API
console.log('getting data for pull request...');
const response = await github.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
const pullRequest = response.data;
// set outputs for use in next step
console.log('setting outputs...')
core.setOutput('head_fork', pullRequest.head.user.login);
core.setOutput('head_sha', pullRequest.head.sha);
core.setOutput('trigger_tests', 'true');
console.log(`head_fork: ${pullRequest.head.user.login}`);
console.log(`head_sha: ${pullRequest.head.sha}`);
} catch(error) {
core.setFailed(`Failed to get pull_request event from issue_comment: ${error}`);
}
// react to comment with thumbs-up to confirm
console.log('adding reaction to triggering comment...');
await github.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: context.payload.comment.id,
content: 'rocket'
});
} else {
console.log('comment does not trigger tests');
core.setOutput('trigger_tests', 'false');
}
- name: Dispatch Colab CI Test Workflow
if: steps.check-comment.outputs.trigger_tests == 'true'
env:
HEAD_FORK: ${{ steps.check-comment.outputs.head_fork }}
HEAD_SHA: ${{ steps.check-comment.outputs.head_sha }}
uses: actions/github-script@v4
with:
github-token: ${{ secrets.API_PAT }}
script: |
console.log(`dispatching Colab CI test workflow...
owner: ${context.repo.owner},
repo: ${context.repo.repo},
ref: ${context.ref},
inputs.fork: ${process.env.HEAD_FORK},
inputs.commit: ${process.env.HEAD_SHA}
`);
const dispatchResponse = await github.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'ci-tests-colab.yml',
ref: context.ref,
inputs: {
fork: process.env.HEAD_FORK,
commit: process.env.HEAD_SHA,
debug_enabled: 'false'
}
});
console.log('dispatch response:');
console.log(dispatchResponse)