Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Commit

Permalink
Add autosquash (#83)
Browse files Browse the repository at this point in the history
* Add action.yml metadata file

* Add and use autosquash action input

By using an input to trigger whether to rebase with autosquash, we can
enable other kinds of workflow configurations (e.g. other events and
criteria).

* Include autosquash feature in README installation section
  • Loading branch information
samholmes authored May 10, 2022
1 parent 99b0226 commit 6e572f0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ on:
jobs:
rebase:
name: Rebase
if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/rebase')
runs-on: ubuntu-latest
if: >-
github.event.issue.pull_request != '' &&
(
contains(github.event.comment.body, '/rebase') ||
contains(github.event.comment.body, '/autosquash')
) runs-on: ubuntu-latest
steps:
- name: Checkout the latest code
uses: actions/checkout@v2
Expand All @@ -28,6 +32,8 @@ jobs:
fetch-depth: 0 # otherwise, you will fail to push refs to dest repo
- name: Automatic Rebase
uses: cirrus-actions/rebase@1.5
with:
autosquash: ${{ contains(github.event.comment.body, '/autosquash') || contains(github.event.comment.body, '/rebase-autosquash') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
Expand Down
14 changes: 14 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Automatic Rebase
description: Automatically rebases PR on '/rebase' comment
maintainer: Cirrus Labs
runs:
using: 'docker'
image: 'Dockerfile'
inputs:
autosquash:
description: Should the rebase autosquash fixup and squash commits
required: false
default: false
branding:
icon: git-pull-request
color: purple
6 changes: 5 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ git fetch fork $HEAD_BRANCH

# do the rebase
git checkout -b fork/$HEAD_BRANCH fork/$HEAD_BRANCH
git rebase origin/$BASE_BRANCH
if [[ $INPUT_AUTOSQUASH -eq 'true' ]]; then
GIT_SEQUENCE_EDITOR=: git rebase -i --autosquash origin/$BASE_BRANCH
else
git rebase origin/$BASE_BRANCH
fi

# push back
git push --force-with-lease fork fork/$HEAD_BRANCH:$HEAD_BRANCH

0 comments on commit 6e572f0

Please sign in to comment.