forked from elastic/eui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_kibana_dependencies__open_pr.yml
More file actions
132 lines (124 loc) Β· 4.11 KB
/
update_kibana_dependencies__open_pr.yml
File metadata and controls
132 lines (124 loc) Β· 4.11 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
name: 'Update Kibana dependencies - Open PR'
on:
workflow_dispatch:
inputs:
pr_head:
description: HEAD ref
required: true
type: string
pr_title:
description: Title of the PR
required: true
type: string
pr_body:
description: Body of the PR
type: string
pr_draft:
description: Whether the PR should be marked as draft
type: boolean
default: true
pr_labels:
description: Comma-separated list of labels to add to the PR
type: string
default: 'EUI,backport:skip,release_note:skip'
workflow_call:
inputs:
pr_head:
description: HEAD ref
required: true
type: string
pr_title:
description: Title of the PR
required: true
type: string
pr_body:
description: Body of the PR
type: string
pr_draft:
description: Whether the PR should be marked as draft
type: boolean
pr_labels:
description: Comma-separated list of labels to add to the PR
type: string
outputs:
pr_url:
description: 'URL of the created pull request'
value: ${{ jobs.open_pr.outputs.pr_url }}
permissions:
id-token: write
jobs:
open_pr:
name: Open PR
runs-on: ubuntu-latest
outputs:
pr_url: ${{ steps.open_pr.outputs.pr_url }}
steps:
- name: Fetch GitHub token
id: ephemeral_token
uses: elastic/ci-gh-actions/fetch-github-token@v1.5.0
with:
vault-instance: ci-prod
vault-role: token-policy-6becee3e5a43
- name: Open PR
id: open_pr
env:
GH_TOKEN: ${{ steps.ephemeral_token.outputs.token }}
PR_HEAD: ${{ inputs.pr_head }}
PR_TITLE: ${{ inputs.pr_title }}
PR_BODY: ${{ inputs.pr_body }}
PR_DRAFT: ${{ inputs.pr_draft }}
PR_LABELS: ${{ inputs.pr_labels }}
# language=bash
run: |
set -euo pipefail
# `gh pr create` cannot open a PR from `elastic/eui-kibana` into `elastic/kibana`
# because both repositories are under the same org.
# GraphQL createPullRequest with `headRepositoryId` identifies the head fork explicitly.
base_repo='elastic/kibana'
head_repo='elastic/eui-kibana'
base_repo_id="$(gh api "repos/$base_repo" --jq .node_id)"
head_repo_id="$(gh api "repos/$head_repo" --jq .node_id)"
IFS=$'\t' read -r err_msg pr_url pr_number < <(
gh api graphql \
-f query='mutation ($input: CreatePullRequestInput!) {
createPullRequest(input: $input) {
pullRequest {
url
number
}
}
}' \
-F "input[repositoryId]=$base_repo_id" \
-F "input[headRepositoryId]=$head_repo_id" \
-F "input[baseRefName]=main" \
-F "input[headRefName]=$PR_HEAD" \
-F "input[title]=$PR_TITLE" \
-F "input[body]=${PR_BODY:-}" \
-F "input[draft]=${PR_DRAFT:-true}" \
-F "input[maintainerCanModify]=false" \
-q 'def pr: .data.createPullRequest.pullRequest;
[
((.errors // []) | .[0].message // ""),
(pr | if . then .url else "" end),
(pr | if . then (.number | tostring) else "" end)
] | @tsv'
)
if [[ -n "$err_msg" ]]; then
echo "::error::$err_msg" >&2
{
echo "### Failed to create pull request"
echo ""
echo "Check job logs for details."
} >> "$GITHUB_STEP_SUMMARY"
exit 1
fi
# Add labels to the PR
if [[ -n "${PR_LABELS:-}" ]]; then
gh pr edit "$pr_number" -R "$base_repo" --add-label "$PR_LABELS"
fi
echo "pr_url=$pr_url" >> "$GITHUB_OUTPUT"
{
echo "### Pull request created"
echo ""
echo "$pr_url"
} >> "$GITHUB_STEP_SUMMARY"