From 06c023cc1a473f0e612943253de5ddfc0eb63556 Mon Sep 17 00:00:00 2001 From: Samuel Holmes Date: Thu, 1 Jul 2021 14:47:54 -0700 Subject: [PATCH] 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). --- README.md | 2 ++ action.yml | 5 +++++ entrypoint.sh | 6 +++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2667b7f..f824efa 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,8 @@ jobs: fetch-depth: 0 # otherwise, you will fail to push refs to dest repo - name: Automatic Rebase uses: cirrus-actions/rebase@1.4 + with: + autosquash: ${{ contains(github.event.comment.body, '/rebase-autosquash') }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ``` diff --git a/action.yml b/action.yml index eb3d1cd..fd82666 100644 --- a/action.yml +++ b/action.yml @@ -4,6 +4,11 @@ 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 a3afb4a..8f12ba9 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -97,7 +97,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