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

Commit 6e572f0

Browse files
authoredMay 10, 2022
Add autosquash (#83)
* 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
1 parent 99b0226 commit 6e572f0

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed
 

‎README.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ on:
1818
jobs:
1919
rebase:
2020
name: Rebase
21-
if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/rebase')
22-
runs-on: ubuntu-latest
21+
if: >-
22+
github.event.issue.pull_request != '' &&
23+
(
24+
contains(github.event.comment.body, '/rebase') ||
25+
contains(github.event.comment.body, '/autosquash')
26+
) runs-on: ubuntu-latest
2327
steps:
2428
- name: Checkout the latest code
2529
uses: actions/checkout@v2
@@ -28,6 +32,8 @@ jobs:
2832
fetch-depth: 0 # otherwise, you will fail to push refs to dest repo
2933
- name: Automatic Rebase
3034
uses: cirrus-actions/rebase@1.5
35+
with:
36+
autosquash: ${{ contains(github.event.comment.body, '/autosquash') || contains(github.event.comment.body, '/rebase-autosquash') }}
3137
env:
3238
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3339
```

‎action.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Automatic Rebase
2+
description: Automatically rebases PR on '/rebase' comment
3+
maintainer: Cirrus Labs
4+
runs:
5+
using: 'docker'
6+
image: 'Dockerfile'
7+
inputs:
8+
autosquash:
9+
description: Should the rebase autosquash fixup and squash commits
10+
required: false
11+
default: false
12+
branding:
13+
icon: git-pull-request
14+
color: purple

‎entrypoint.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ git fetch fork $HEAD_BRANCH
100100

101101
# do the rebase
102102
git checkout -b fork/$HEAD_BRANCH fork/$HEAD_BRANCH
103-
git rebase origin/$BASE_BRANCH
103+
if [[ $INPUT_AUTOSQUASH -eq 'true' ]]; then
104+
GIT_SEQUENCE_EDITOR=: git rebase -i --autosquash origin/$BASE_BRANCH
105+
else
106+
git rebase origin/$BASE_BRANCH
107+
fi
104108

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

0 commit comments

Comments
 (0)