Fixes to serverless patch script (#2175)

This commit is contained in:
Josh Mock
2024-03-26 12:17:30 -05:00
committed by GitHub
parent 86d89a47a0
commit 6a821583c0
2 changed files with 40 additions and 14 deletions

38
.github/workflows/serverless-patch.sh vendored Executable file
View File

@ -0,0 +1,38 @@
#!/usr/bin/env bash
set -exuo pipefail
merge_commit_sha=$(jq -r '.pull_request.merge_commit_sha' "$GITHUB_EVENT_PATH")
pull_request_id=$(jq -r '.pull_request.number' "$GITHUB_EVENT_PATH")
# generate patch file
cd "$GITHUB_WORKSPACE/elasticsearch-js"
git format-patch -1 --stdout "$merge_commit_sha" > /tmp/patch.diff
# apply patch file
cd "$GITHUB_WORKSPACE/elasticsearch-serverless-js"
git checkout -b "apply-patch-$pull_request_id"
git apply -C1 --recount --reject /tmp/patch.diff || exit 0
comment="Patch applied from elastic/elasticsearch-js#$pull_request_id"
# check for rejected patches
tick='\`' # just trying to satisfy shellcheck here
has_rejects=''
for f in ./**/*.rej; do
has_rejects=' --draft'
comment="$comment
## Rejected patch $tick$f$tick must be resolved:
$tick$tick$tick
$(cat "$f")
$tick$tick$tick
"
done
# open a PR
gh pr create \
-t "Apply PR changes from elastic/elasticsearch-js#$pull_request_id" \
--body "$comment" \
"$has_rejects"

View File

@ -36,17 +36,5 @@ jobs:
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"
- name: Apply patch from stack to serverless
run: ./.github/serverless-patch.sh