From 1d84468762643ba5504f9d114ecf403f5aec8ab7 Mon Sep 17 00:00:00 2001 From: Josh Mock Date: Thu, 21 Mar 2024 16:33:43 -0500 Subject: [PATCH] Move between two repositories more cleanly during patch (#2172) * fix: checkout multiple repos cleanly * fix: ensure git apply exits cleanly --- .github/workflows/serverless-patch.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/serverless-patch.yml b/.github/workflows/serverless-patch.yml index d0f2aed39..8f204bbea 100644 --- a/.github/workflows/serverless-patch.yml +++ b/.github/workflows/serverless-patch.yml @@ -30,17 +30,21 @@ jobs: with: repository: elastic/elasticsearch-js ref: '${{ github.event.pull_request.merge_commit_sha }}' - - name: Generate patch file - run: | - git format-patch -1 --stdout ${{ github.event.pull_request.merge_commit_sha }} > /tmp/patch.diff + path: elasticsearch-js - uses: actions/checkout@v4 with: repository: elastic/elasticsearch-serverless-js ref: main - - name: Apply patch to serverless + 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 + 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\`\`\`"