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 23, 2023
1 parent 81ebbb9 commit 475489e
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,44 @@ 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
pull-requests: write

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Minimize calling comment
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.graphql(`mutation { minimizeComment(input: { subjectId: "${context.payload.comment.node_id}", classifier: OUTDATED }) { clientMutationId } }`)
- 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 pr checkout ${{ github.event.issue.number }}
echo "base_ref=$(gh pr view 5 --json baseRefName)" >> $GITHUB_OUTPUT
- name: Fast-forward merge
run: |
export PR_COMMIT=$(git rev-parse HEAD)
git checkout ${{ fromJSON(steps.base-ref.outputs.base_ref).baseRefName }}
git merge --ff-only "$PR_COMMIT"
git push origin ${{ fromJSON(steps.base-ref.outputs.base_ref).baseRefName }}
git checkout ${{ fromJSON(steps.pr.outputs.base_ref).baseRefName }}
git merge --ff-only "$PR_COMMIT" 2>output.log
git push origin ${{ fromJSON(steps.pr.outputs.base_ref).baseRefName }} 2>output.log
- name: Post errors
if: ${{ failure() }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr comment ${{ github.event.issue.number }} -b "Failure merging:
\`\`\`
$(cat output.log)
\`\`\`"

0 comments on commit 475489e

Please sign in to comment.