Skip to content

Commit

Permalink
Correctly apply and commit patch changes in patch automation workflow (
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshMock authored Mar 26, 2024
1 parent c106146 commit 2721008
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/serverless-patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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")
pr_shortcode="elastic/elasticsearch-js#$pull_request_id"

# generate patch file
cd "$GITHUB_WORKSPACE/stack"
Expand All @@ -12,11 +13,16 @@ git format-patch -1 --stdout "$merge_commit_sha" > /tmp/patch.diff
# apply patch file
cd "$GITHUB_WORKSPACE/serverless"
git checkout -b "apply-patch-$pull_request_id"
git apply -C1 --recount --reject /tmp/patch.diff || exit 0
git am -C1 --reject /tmp/patch.diff || git am --quit

comment="Patch applied from elastic/elasticsearch-js#$pull_request_id"
# commit changes, ignoring rejects
git add -A
git reset -- **/*.rej
git commit -m "Apply changes from $pr_shortcode"

# check for rejected patches
comment="Patch applied from $pr_shortcode"

# enumerate rejected patches in PR comment
tick='\`' # just trying to satisfy shellcheck here
has_rejects=''
for f in ./**/*.rej; do
Expand All @@ -33,6 +39,7 @@ done

# open a PR
gh pr create \
-t "Apply PR changes from elastic/elasticsearch-js#$pull_request_id" \
--repo elastic/elasticsearch-serverless-js \
-t "Apply PR changes from $pr_shortcode" \
--body "$comment" \
"$has_rejects"

0 comments on commit 2721008

Please sign in to comment.