Skip to content

Commit

Permalink
Improve fast-forward merge
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda committed Oct 20, 2023
1 parent 81ebbb9 commit b71f4c0
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

0 comments on commit b71f4c0

Please sign in to comment.