Skip to content

Commit

Permalink
Merge pull request #3 from idoberko2/add-git-push-flags
Browse files Browse the repository at this point in the history
Add git push flags
  • Loading branch information
idoberko2 authored Jan 19, 2020
2 parents 858004f + 5b498bf commit 4b326b3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,28 @@ The Dokku app name to be deployed.

The branch to push on the remote repository. If not specified, `master` will be used.

### git-push-flags

You may set additional flags that will be passed to the `git push` command. You might want to set this parameter to `--force` if you're pushing to Dokku from other places and encounter the following error:
```
error: failed to push some refs to 'dokku@mydokkuhost.com:mydokkurepo'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
```

## Example

Note: `actions/checkout` must preceed this action in order for the repository data to be exposed for the action.
It is recommended to pass `actions/checkout` the `fetch-depth: 0` parameter to avoid errors such as `shallow update not allowed`

```
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v2
with:
fetch-depth: 0
- id: deploy
name: Deploy to dokku
uses: idoberko2/dokku-deploy-github-action@v1
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ inputs:
description: "The branch to push on the remote repository (Default: master)"
required: false
default: "master"
git-push-flags:
description: "Additional flags to be passed to the git push command. Could be used to force push"
required: false
default: ""
runs:
using: "docker"
image: "Dockerfile"
Expand All @@ -31,3 +35,4 @@ runs:
- ${{ inputs.dokku-host }}
- ${{ inputs.app-name }}
- ${{ inputs.remote-branch }}
- ${{ inputs.git-push-flags }}
26 changes: 22 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
#!/bin/bash

SSH_PRIVATE_KEY=$1
DOKKU_USER=$2
DOKKU_HOST=$3
DOKKU_APP_NAME=$4
DOKKU_REMOTE_BRANCH=$5
GIT_PUSH_FLAGS=$6

# Setup the SSH environment
mkdir -p ~/.ssh
eval `ssh-agent -s`
ssh-add - <<< "$1"
ssh-keyscan $3 >> ~/.ssh/known_hosts
git_repo="$2@$3:$4"
ssh-add - <<< "$SSH_PRIVATE_KEY"
ssh-keyscan $DOKKU_HOST >> ~/.ssh/known_hosts

# Setup the git environment
git_repo="$DOKKU_USER@$DOKKU_HOST:$DOKKU_APP_NAME"
cd "$GITHUB_WORKSPACE"
git remote add deploy "$git_repo"
GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" git push deploy "$GITHUB_SHA:refs/heads/$5"

# Prepare to push to Dokku git repository
REMOTE_REF="$GITHUB_SHA:refs/heads/$DOKKU_REMOTE_BRANCH"

GIT_COMMAND="git push deploy $REMOTE_REF $GIT_PUSH_FLAGS"
echo "GIT_COMMAND=$GIT_COMMAND"

# Push to Dokku git repository
GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" $GIT_COMMAND

0 comments on commit 4b326b3

Please sign in to comment.