-
Notifications
You must be signed in to change notification settings - Fork 8
130 lines (125 loc) · 4.59 KB
/
retest.yml
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
name: "Retest chroots on testing-farm"
on:
issue_comment:
types: created
permissions:
issues: write
jobs:
show-reaction-eyes:
if: ${{ !github.event.issue.pull_request && startsWith(github.event.comment.body, '/retest')}}
runs-on: ubuntu-latest
steps:
- name: Add reaction to trigger comment
uses: actions/github-script@v7
with:
script: |
const mutation = `mutation($comment_id: ID!, $reaction: ReactionContent!) {
addReaction(input: {subjectId: $comment_id, content: $reaction}) {
reaction {
content
}
subject {
id
}
}
}`;
const variables = {
comment_id: '${{ github.event.comment.node_id }}',
reaction: 'EYES'
}
const result = await github.graphql(mutation, variables)
console.log(result)
check-team-membership:
if: ${{ !github.event.issue.pull_request && startsWith(github.event.comment.body, '/retest')}}
runs-on: ubuntu-latest
steps:
- name: Check if commenter is member of the required team.
uses: actions/github-script@v7
with:
github-token: ${{secrets.GH_ORG_READ_MEMBERS_PAT}}
script: |
const query = `query check_if_user_is_team_member($user_login: String!, $org: String!, $team_slug: String!) {
organization(login: $org) {
team(slug: $team_slug) {
members(query: $user_login) {
totalCount
}
}
}
}`;
const variables = {
"user_login": "${{github.event.comment.user.login}}",
"org": "${{github.repository_owner}}",
"team_slug": "llvm-toolset-engineers"
}
const result = await github.graphql(query, variables)
console.log(result)
if(result['organization']['team']['members']['totalCount'] != 1) {
core.setFailed("User is not allowed to use the /retest command");
}
retest:
needs: check-team-membership
if: ${{ !github.event.issue.pull_request && startsWith(github.event.comment.body, '/retest')}}
runs-on: ubuntu-latest
steps:
- name: Get Chroots
id: chroots-step
run: |
echo "${{ github.event.comment.body }}" | grep -Pe '^\s*/retest\s+'
chroots=$(echo "${{ github.event.comment.body }}" | sed 's/^\s*\/retest\s*//g')
echo "chroots=$chroots" >> "$GITHUB_ENV"
- uses: actions/checkout@v4
- uses: ./.github/actions/prepare-python
- name: Run retest script
shell: bash -e {0}
env:
GITHUB_TOKEN: ${{ secrets.GH_TEST_TOKEN }}
chroots: ${{ env.chroots }}
run: |
python3 snapshot_manager/main.py \
--github-repo ${GITHUB_REPOSITORY} \
--github-token-env GITHUB_TOKEN \
retest \
--trigger-comment-id ${{ github.event.comment.id }} \
--issue-number ${{ github.event.issue.number }} \
--chroots ${{ env.chroots }}
show-reaction-thumbs-up:
needs: retest
runs-on: ubuntu-latest
steps:
- name: Add reaction to trigger comment
uses: actions/github-script@v7
with:
script: |
const add_reaction = `mutation($comment_id: ID!, $reaction: ReactionContent!) {
addReaction(input: {subjectId: $comment_id, content: $reaction}) {
reaction {
content
}
subject {
id
}
}
}`;
const remove_reaction = `mutation($comment_id: ID!, $reaction: ReactionContent!) {
removeReaction(input: {subjectId: $comment_id, content: $reaction}) {
reaction {
content
}
subject {
id
}
}
}`;
const add_reaction_variables = {
comment_id: '${{ github.event.comment.node_id }}',
reaction: 'THUMBS_UP'
}
const result = await github.graphql(add_reaction, add_reaction_variables)
console.log(result)
const remove_reaction_variables = {
comment_id: '${{ github.event.comment.node_id }}',
reaction: 'EYES'
}
const result_removal = await github.graphql(remove_reaction, remove_reaction_variables)
console.log(result_removal)