From d61d54a811e199a3f5e338c65baf382045d2c0de Mon Sep 17 00:00:00 2001 From: Josh Mock Date: Thu, 21 Mar 2024 16:14:53 -0500 Subject: [PATCH] Action to apply stack client patches to serverless (#2169) * GitHub action for applying stack client patches to serverless * Drop unnecessary comment --- .github/workflows/serverless-patch.yml | 45 ++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/serverless-patch.yml diff --git a/.github/workflows/serverless-patch.yml b/.github/workflows/serverless-patch.yml new file mode 100644 index 000000000..c29e0312c --- /dev/null +++ b/.github/workflows/serverless-patch.yml @@ -0,0 +1,45 @@ +--- +name: Apply PR changes to serverless +on: + pull_request_target: + types: + - closed + - labeled + +jobs: + backport: + name: Backport + 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 + - name: Generate patch file + run: | + git format-patch -1 --stdout ${{ github.event.pull_request.merge_commit_sha }} > /tmp/patch.diff + - uses: actions/checkout@v4 + with: + repository: elastic/elasticsearch-serverless-js + ref: main + - name: Apply patch to serverless + run: | + git checkout -b apply-patch-${{ github.event.pull_request.id }} + git apply -C1 --recount --reject /tmp/patch.diff + 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"