-
Notifications
You must be signed in to change notification settings - Fork 134
134 lines (123 loc) · 5.17 KB
/
update_screenshots.yml
File metadata and controls
134 lines (123 loc) · 5.17 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
name: Trigger Buildkite update screenshots build
on:
issue_comment:
types: [created]
permissions:
issues: write
pull-requests: write
contents: read
jobs:
check-and-trigger:
if: |
github.event.issue.pull_request &&
(
contains(github.event.comment.body, 'buildkite update screenshots') ||
contains(github.event.comment.body, 'buildkite update vrt')
)
runs-on: ubuntu-latest
steps:
- name: Check elastic org membership
id: check-elastic-member
uses: actions/github-script@v7
with:
github-token: ${{ secrets.ADMIN_TOKEN_GH }}
script: |
const org = 'elastic';
const username = '${{ github.event.comment.user.login }}';
try {
await github.request('GET /orgs/{org}/members/{username}', {
org,
username,
headers: { Accept: 'application/vnd.github.v3+json' }
});
core.setOutput('is_member', 'true');
core.info(`${username} is a member of ${org}`);
} catch (err) {
if (err.status === 404) {
core.setOutput('is_member', 'false');
core.info(`${username} is NOT a member of ${org}`);
} else {
core.setFailed(`Failed to check membership: ${err}`);
}
}
- name: Add 😕 reaction to comment
if: steps.check-elastic-member.outputs.is_member == 'false'
uses: peter-evans/create-or-update-comment@v5
with:
comment-id: ${{ github.event.comment.id }}
reactions: 'confused'
- name: Fail if not Elastic org member
if: steps.check-elastic-member.outputs.is_member == 'false'
run: |
echo "User ${{ github.event.comment.user.login }} is not a member of elastic organization"
echo "Aborting Buildkite trigger"
- name: Add 👍 reaction to comment
if: steps.check-elastic-member.outputs.is_member == 'true'
uses: peter-evans/create-or-update-comment@v5
with:
comment-id: ${{ github.event.comment.id }}
reactions: '+1'
- name: Fetch PR head commit and branch
id: get-pr-info
if: steps.check-elastic-member.outputs.is_member == 'true'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.ADMIN_TOKEN_GH }}
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const prNumber = ${{ github.event.issue.number }};
try {
const { data: pr } = await github.rest.pulls.get({
owner,
repo,
pull_number: prNumber
});
core.setOutput('commit_sha', pr.head.sha);
core.setOutput('branch', pr.head.ref);
core.setOutput('prefixed_branch', pr.head.label);
core.setOutput('base_branch', pr.base.ref);
core.setOutput('can_modify', pr.maintainer_can_modify);
core.setOutput('pr_repo', pr.head.repo?.git_url);
core.info(`PR #${prNumber}: ${pr.head.sha} on branch ${pr.head.ref}`);
} catch (error) {
core.setFailed(`Failed to fetch PR info: ${error.message}`);
}
- name: Trigger Buildkite pipeline
if: steps.check-elastic-member.outputs.is_member == 'true'
env:
BUILDKITE_API_TOKEN: ${{ secrets.BUILDKITE_API_TOKEN }}
PR_NUMBER: ${{ github.event.issue.number }}
TRIGGERED_BY: ${{ github.event.comment.user.login }}
COMMIT_SHA: ${{ steps.get-pr-info.outputs.commit_sha }}
BRANCH: ${{ steps.get-pr-info.outputs.branch }}
BASE_BRANCH: ${{ steps.get-pr-info.outputs.base_branch }}
PREFIXED_BRANCH: ${{ steps.get-pr-info.outputs.prefixed_branch }}
PR_REPO: ${{ steps.get-pr-info.outputs.pr_repo }}
CAN_MODIFY: ${{ steps.get-pr-info.outputs.can_modify }}
run: |
curl -s -X POST "https://api.buildkite.com/v2/organizations/elastic/pipelines/elastic-charts-build/builds" \
-H "Authorization: Bearer $BUILDKITE_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"message": "Updating screenshots - triggered by @'"${TRIGGERED_BY}"'",
"commit": "'"$COMMIT_SHA"'",
"branch": "'"$PREFIXED_BRANCH"'",
"pull_request_id": "'"$PR_NUMBER"'",
"pull_request_base_branch": "'"$BASE_BRANCH"'",
"pull_request_repository": "'"$PR_REPO"'",
"ignore_pipeline_branch_filters": true,
"author": {
"name": "'"$TRIGGERED_BY"'",
"email": "'"$TRIGGERED_BY"'@users.noreply.github.com"
},
"env": {
"ECH_STEP_PLAYWRIGHT_UPDATE_SCREENSHOTS": "true",
"GITHUB_PR_MAINTAINER_CAN_MODIFY": "'"$CAN_MODIFY"'"
},
"meta_data": {
"github_pr_number": "'"$PR_NUMBER"'",
"triggered_via": "github-comment",
"triggered_by": "'"$TRIGGERED_BY"'"
}
}' | jq .