From 84d637d5122bacd7c53832406fb139895a5f5a8f Mon Sep 17 00:00:00 2001 From: Samuel Holmes Date: Thu, 1 Jul 2021 14:33:50 -0700 Subject: [PATCH 1/3] Add action.yml metadata file --- action.yml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 action.yml diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..eb3d1cd --- /dev/null +++ b/action.yml @@ -0,0 +1,9 @@ +name: Automatic Rebase +description: Automatically rebases PR on '/rebase' comment +maintainer: Cirrus Labs +runs: + using: 'docker' + image: 'Dockerfile' +branding: + icon: git-pull-request + color: purple \ No newline at end of file From 450ffc19507c5e3cb5b74fde803a67555fd81d96 Mon Sep 17 00:00:00 2001 From: Samuel Holmes Date: Thu, 1 Jul 2021 14:47:54 -0700 Subject: [PATCH 2/3] 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). --- action.yml | 5 +++++ entrypoint.sh | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) 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 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 From 4ad145348bb2c401693797cab7b492e13b861bc6 Mon Sep 17 00:00:00 2001 From: Samuel Holmes Date: Thu, 1 Jul 2021 15:59:45 -0700 Subject: [PATCH 3/3] Include autosquash feature in README installation section --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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 }} ```