-
Notifications
You must be signed in to change notification settings - Fork 727
52 lines (51 loc) · 1.86 KB
/
serverless-patch.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
---
name: Apply PR changes to serverless
on:
pull_request_target:
types:
- closed
- labeled
jobs:
apply-patch:
name: Apply patch
runs-on: ubuntu-latest
# Only react to merged PRs for security reasons.
# See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target.
if: >
github.event.pull_request.merged
&& (
(
github.event.action == 'closed'
&& contains(github.event.pull_request.labels.*.name, 'apply-to-serverless')
)
||
(
github.event.action == 'labeled'
&& github.event.label.name == 'apply-to-serverless'
)
)
steps:
- uses: actions/checkout@v4
with:
repository: elastic/elasticsearch-js
ref: '${{ github.event.pull_request.merge_commit_sha }}'
path: elasticsearch-js
- uses: actions/checkout@v4
with:
repository: elastic/elasticsearch-serverless-js
ref: main
path: elasticsearch-serverless-js
- name: Generate patch file
run: |
cd $GITHUB_WORKSPACE/elasticsearch-js
git format-patch -1 --stdout ${{ github.event.pull_request.merge_commit_sha }} > /tmp/patch.diff
- name: Apply patch file
run: |
cd $GITHUB_WORKSPACE/elasticsearch-serverless-js
git checkout -b apply-patch-${{ github.event.pull_request.id }}
git apply -C1 --recount --reject /tmp/patch.diff || exit 0
comment='Patch applied from elastic/elasticsearch-js#${{ github.event.pull_request.id }}'
for f in $(find . -name '*.rej'); do
comment="$comment\n\n## Rejected patch \`$f`\:\n\`\`\`\n$(cat $f)\n\`\`\`"
done
gh pr create -t "Apply PR changes from elastic/elasticsearch-js#${{ github.event.pull_request.id }}" --body "$comment"