diff --git a/.github/workflows/serverless-patch.sh b/.github/workflows/serverless-patch.sh index 58f822100..2cf8d90ca 100755 --- a/.github/workflows/serverless-patch.sh +++ b/.github/workflows/serverless-patch.sh @@ -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" diff --git a/.github/workflows/serverless-patch.yml b/.github/workflows/serverless-patch.yml index b7796d5ed..bf0af9100 100644 --- a/.github/workflows/serverless-patch.yml +++ b/.github/workflows/serverless-patch.yml @@ -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'