Refactor patch action to use create-pull-request action (#2186)
This commit is contained in:
28
.github/workflows/serverless-patch.sh
vendored
28
.github/workflows/serverless-patch.sh
vendored
@ -15,31 +15,25 @@ cd "$GITHUB_WORKSPACE/serverless"
|
||||
git checkout -b "apply-patch-$pull_request_id"
|
||||
git am -C1 --reject /tmp/patch.diff || git am --quit
|
||||
|
||||
# commit changes, ignoring rejects
|
||||
git add -A
|
||||
git reset -- **/*.rej
|
||||
git commit -m "Apply changes from $pr_shortcode"
|
||||
|
||||
# generate PR body comment
|
||||
comment="Patch applied from $pr_shortcode"
|
||||
|
||||
# enumerate rejected patches in PR comment
|
||||
tick='\`' # just trying to satisfy shellcheck here
|
||||
has_rejects=''
|
||||
has_rejects='false'
|
||||
for f in ./**/*.rej; do
|
||||
has_rejects='--draft'
|
||||
has_rejects='true'
|
||||
comment="$comment
|
||||
|
||||
## Rejected patch $tick$f$tick must be resolved:
|
||||
## Rejected patch \`$f\` must be resolved:
|
||||
|
||||
$tick$tick$tick
|
||||
\`\`\`diff
|
||||
$(cat "$f")
|
||||
$tick$tick$tick
|
||||
\`\`\`
|
||||
"
|
||||
done
|
||||
|
||||
# open a PR
|
||||
gh pr create \
|
||||
--repo elastic/elasticsearch-serverless-js \
|
||||
-t "Apply PR changes from $pr_shortcode" \
|
||||
--body "$comment" \
|
||||
"$has_rejects"
|
||||
# send data to output parameters
|
||||
{
|
||||
echo "PR_BODY='$comment'"
|
||||
echo "PR_DRAFT=$has_rejects"
|
||||
} >> "$GITHUB_OUTPUT"
|
||||
|
||||
17
.github/workflows/serverless-patch.yml
vendored
17
.github/workflows/serverless-patch.yml
vendored
@ -37,11 +37,16 @@ jobs:
|
||||
repository: elastic/elasticsearch-serverless-js
|
||||
ref: main
|
||||
path: serverless
|
||||
- name: Set Git user
|
||||
run: |
|
||||
git config --global user.name "Elastic Machine"
|
||||
git config --global user.email "elasticmachine@users.noreply.github.com"
|
||||
- name: Apply patch from stack to serverless
|
||||
env:
|
||||
GH_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
|
||||
id: apply-patch
|
||||
run: $GITHUB_WORKSPACE/stack/.github/workflows/serverless-patch.sh
|
||||
- uses: peter-evans/create-pull-request@v6
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
path: $GITHUB_WORKSPACE/serverless
|
||||
title: 'Apply patch from elastic/elasticsearch-js#${{ github.event.pull_request.number }}'
|
||||
commit-message: 'Apply patch from elastic/elasticsearch-js#${{ github.event.pull_request.number }}'
|
||||
branch-suffix: short-commit-hash
|
||||
body: '${{ steps.apply-patch.outputs.PR_BODY }}'
|
||||
draft: '${{ steps.apply-patch.outputs.PR_DRAFT }}'
|
||||
add-paths: ':!*.rej'
|
||||
|
||||
Reference in New Issue
Block a user