From b71f4c002b7f9cf62b2721904b7a8b6f4fd6a6f8 Mon Sep 17 00:00:00 2001 From: daxpedda Date: Thu, 19 Oct 2023 15:25:29 +0200 Subject: [PATCH] Improve fast-forward merge --- .github/workflows/merge.yml | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/.github/workflows/merge.yml b/.github/workflows/merge.yml index 1082c24..bc1566e 100644 --- a/.github/workflows/merge.yml +++ b/.github/workflows/merge.yml @@ -12,27 +12,39 @@ jobs: if: | github.event.issue.pull_request && + github.event.issue.state == 'open' && github.event.comment.author_association == 'OWNER' && github.event.comment.body == '/fast-forward-merge' permissions: contents: write + issues: write + pull-requests: write steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Checkout pull request + id: pr env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: gh pr checkout ${{ github.event.issue.number }} - - name: Get target branch - id: base-ref - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: echo "base_ref=$(gh pr view 5 --json baseRefName)" >> $GITHUB_OUTPUT + run: | + gh api -X DELETE -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/{owner}/{repo}/issues/comments/${{ github.event.comment.id }} + gh pr checkout ${{ github.event.issue.number }} + echo "base_ref=$(gh pr view 5 --json baseRefName)" >> $GITHUB_OUTPUT - name: Fast-forward merge + id: push run: | export PR_COMMIT=$(git rev-parse HEAD) - git checkout ${{ fromJSON(steps.base-ref.outputs.base_ref).baseRefName }} + git checkout ${{ fromJSON(steps.pr.outputs.base_ref).baseRefName }} git merge --ff-only "$PR_COMMIT" - git push origin ${{ fromJSON(steps.base-ref.outputs.base_ref).baseRefName }} + output=$(git push origin ${{ fromJSON(steps.pr.outputs.base_ref).baseRefName }} 2>&1); status=$? + echo "output=$output" >> $GITHUB_OUTPUT + exit $status + - name: Post errors + if: ${{ failure() }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: gh pr comment ${{ github.event.issue.number }} -b ${{ steps.push.outputs.output }}