Skip to content

Commit

Permalink
fix: Fix spelling and order of branches in workflow
Browse files Browse the repository at this point in the history
Signed-off-by: Whiteflight <[email protected]>
  • Loading branch information
Whiteflight committed Oct 2, 2024
1 parent 20e8428 commit 774ed44
Showing 1 changed file with 54 additions and 7 deletions.
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 }}

0 comments on commit 774ed44

Please sign in to comment.