From 90f7616bb55726424f2d4dde48e01f607ce84cff Mon Sep 17 00:00:00 2001
From: Santiago Fraire <santiwilly@gmail.com>
Date: Fri, 3 Mar 2023 13:23:22 +0100
Subject: [PATCH] fix: remove use_ssh flag

BREAKING CHANGE: Remove `use_ssh`. Documentation is in place to deploy using SSH keys
---
 Dockerfile    |  1 -
 README.md     | 45 +++++++++++++++++++++++++++++++++++++++++----
 action.yml    |  4 ----
 entrypoint.sh |  8 ++------
 4 files changed, 43 insertions(+), 15 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 33d2073..ab2a687 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -6,7 +6,6 @@ RUN set -eux; \
         gpg \
         alpine-sdk \
         bash \
-        openssh \
         libffi-dev \
     ;
 COPY entrypoint.sh /entrypoint.sh
diff --git a/README.md b/README.md
index cb604a5..9b23a7d 100644
--- a/README.md
+++ b/README.md
@@ -66,8 +66,7 @@ jobs:
 
 | Name                           | Description                                                                                                                                                                                                                       | Default                                                         |
 | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- |
-| `github_token`                 | Token for the repo. Can be passed in using `${{ secrets.GITHUB_TOKEN }}`. Required if `use_ssh: false`                                                                                                                            | -                                                               |
-| `use_ssh`                      | Set to true if ssh-key has been configured for the `actions/checkout`                                                                                                                                                               | `false`                                                         |
+| `github_token`                 | Token for the repo. Can be passed in using `${{ secrets.GITHUB_TOKEN }}`. Required if `push: true`                                                                                                                                | -                                                               |
 | `dry_run`                      | Run without creating commit, output to stdout                                                                                                                                                                                     | false                                                           |
 | `repository`                   | Repository name to push. Default or empty value represents current github repository                                                                                                                                              | current one                                                     |
 | `branch`                       | Destination branch to push changes                                                                                                                                                                                                | Same as the one executing the action by default                 |
@@ -119,11 +118,49 @@ jobs:
         uses: actions/checkout@v3
         with:
           fetch-depth: 0
-          ssh-key: '${{ secrets.COMMIT_KEY }}'
+          ssh-key: "${{ secrets.COMMIT_KEY }}"
       - name: Create bump and changelog
         uses: commitizen-tools/commitizen-action@master
         with:
-          use_ssh: true
+          push: false
+      - name: Push using ssh
+        run: |
+          git push origin main --tags
+```
+
+## Creating a Github release
+
+```yaml
+name: Bump version
+
+on:
+  push:
+    branches:
+      - main
+
+jobs:
+  bump-version:
+    if: "!startsWith(github.event.head_commit.message, 'bump:')"
+    runs-on: ubuntu-latest
+    name: "Bump version and create changelog with commitizen"
+    steps:
+      - name: Check out
+        uses: actions/checkout@v3
+        with:
+          fetch-depth: 0
+          token: "${{ secrets.PERSONAL_ACCESS_TOKEN }}"
+      - name: Create bump and changelog
+        uses: commitizen-tools/commitizen-action@master
+        with:
+          github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
+          changelog_increment_filename: body.md
+      - name: Release
+        uses: softprops/action-gh-release@v1
+        with:
+          body_path: "body.md"
+          tag_name: ${{ env.REVISION }}
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
 ```
 
 ## Troubleshooting
diff --git a/action.yml b/action.yml
index 546a303..d3e5d16 100644
--- a/action.yml
+++ b/action.yml
@@ -37,10 +37,6 @@ inputs:
   github_token:
     description: 'Token for the repo. Can be passed in using $\{{ secrets.GITHUB_TOKEN }}'
     required: false
-  use_ssh:
-    description: 'Set to true if ssh-key has been configured for the actions/checkout'
-    required: false
-    default: "false"
   repository:
     description: 'Repository name to push. Default or empty value represents current github repository (${GITHUB_REPOSITORY})'
     default: ''
diff --git a/entrypoint.sh b/entrypoint.sh
index 3a33dad..7a27397 100755
--- a/entrypoint.sh
+++ b/entrypoint.sh
@@ -6,8 +6,8 @@ set -e
 gpg --version
 git --version
 
-if [[ -z $INPUT_GITHUB_TOKEN && $INPUT_USE_SSH != "true" ]]; then
-  echo 'Missing input "github_token: ${{ secrets.GITHUB_TOKEN }}" or "use_ssh", choose one.' >&2
+if [[ -z $INPUT_GITHUB_TOKEN && $INPUT_PUSH == "true" ]]; then
+  echo 'Missing input "github_token: ${{ secrets.GITHUB_TOKEN }}" which is required to push.' >&2
   exit 1
 fi
 
@@ -92,10 +92,6 @@ if [[ $INPUT_PUSH == 'true' ]]; then
   if [[ $INPUT_MERGE != 'true' && $GITHUB_EVENT_NAME == 'pull_request' ]]; then
     echo "Refusing to push on pull_request event since that would merge the pull request." >&2
     echo "You probably want to run on push to your default branch instead." >&2
-  elif [[ $INPUT_USE_SSH == "true" ]]; then
-    echo "Pushing to branch using SSH..."
-    REMOTE_REPO="git@github.com:${INPUT_REPOSITORY}.git"
-    git push "$REMOTE_REPO" "HEAD:${INPUT_BRANCH}" --tags
   else
     echo "Pushing to branch..."
     REMOTE_REPO="https://${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@github.com/${INPUT_REPOSITORY}.git"