From 6e572f08c244e2f04f9beb85a943eb618218714d Mon Sep 17 00:00:00 2001 From: Sam Holmes Date: Tue, 10 May 2022 08:38:18 -0700 Subject: [PATCH] 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 --- README.md | 10 ++++++++-- action.yml | 14 ++++++++++++++ entrypoint.sh | 6 +++++- 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 action.yml diff --git a/README.md b/README.md index fa494bf..d6bd4ce 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 }} ``` diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..fd82666 --- /dev/null +++ b/action.yml @@ -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 \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh index f80d05c..e776c9d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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