Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use git commands instead of action to perform git merge fast for… #71

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 54 additions & 7 deletions .github/workflows/fast_forward.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,69 @@ on:
issue_comment:
types: [created]

permissions:
contents: read

jobs:
fast_forward_job:
name: Fast Forward
if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/fast-forward')
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write

steps:
# To use this repository's private action, you must check out the repository
- name: Checkout
uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 #v4.2.0

# Basic use case example
- name: Fast Forward PR
id: ff-action
uses: endre-spotlab/[email protected]
# Get details of the PR. The target and base branch. And also whether the PR can be merged in or not.
- name: Get PR details
uses: octokit/[email protected]
id: get-pr-details
with:
route: GET /repos/{repository}/pulls/{pull_number}
repository: ${{ github.repository }}
pull_number: ${{ github.event.issue.number }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Merge (rebase) the PR if it is allowed.
- name: Fast forward the PR
id: merge-status
shell: bash
env:
HEAD_BRANCH: ${{ fromJson(steps.get-pr-details.outputs.data).head.ref }}
BASE_BRANCH: ${{ fromJson(steps.get-pr-details.outputs.data).base.ref }}
run: |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "GitHub Actions"
git checkout $HEAD_BRANCH
git checkout $BASE_BRANCH
git merge $HEAD_BRANCH --ff-only
git push
echo "::set-output name=message::'Fast forward successful.'"

# Post a success/failure comment to the PR.
- name: Add comment to PR
uses: octokit/[email protected]
with:
route: POST /repos/{repository}/issues/{issue_number}/comments
repository: ${{ github.repository }}
issue_number: ${{ github.event.issue.number }}
body: ${{ steps.merge-status.outputs.message }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
success_message: 'Success! Fast forwarded ***target_base*** to ***source_head***! ```git checkout target_base && git merge source_head --ff-only``` '
failure_message: 'Failed! Cannot do fast forward!'
production_branch: 'main'

# Post a failure message when any of the previous steps fail.
- name: Add failure comment to PR
if: ${{ failure() }}
uses: octokit/[email protected]
with:
route: POST /repos/{repository}/issues/{issue_number}/comments
repository: ${{ github.repository }}
issue_number: ${{ github.event.issue.number }}
body: Unable to fast forward. Check the Actions execution tab for details.
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}