-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from WilliamMayor/feature/pass-shellcheck
Pass shellcheck plus small other things (4/4)
- Loading branch information
Showing
8 changed files
with
46 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/tests/_run.sh | ||
/tests/*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,31 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
echo "Setting up SSH directory" | ||
SSH_PATH="$HOME/.ssh" | ||
mkdir -p "$SSH_PATH" | ||
chmod 700 "$SSH_PATH" | ||
|
||
DEPLOY_BRANCH="${BRANCH-master}" | ||
FORCE=$([ "$FORCE_DEPLOY" = true ] && echo "--force" || echo "") | ||
|
||
echo "Saving SSH key" | ||
echo "$PRIVATE_KEY" > "$SSH_PATH/deploy_key" | ||
chmod 600 "$SSH_PATH/deploy_key" | ||
|
||
GIT_COMMAND="git push dokku@$HOST:$PROJECT HEAD:master" | ||
if [ -n "$FORCE_DEPLOY" ]; then | ||
echo "Enabling force deploy" | ||
GIT_COMMAND="$GIT_COMMAND --force" | ||
fi | ||
|
||
GIT_SSH_COMMAND="ssh -p ${PORT-22} -i $SSH_PATH/deploy_key" | ||
|
||
|
||
if [ -n "$HOST_KEY" ]; then | ||
echo "Adding hosts key to known_hosts" | ||
echo "$HOST_KEY" >> "$SSH_PATH/known_hosts" | ||
chmod 600 "$SSH_PATH/known_hosts" | ||
else | ||
GIT_SSH_COMMAND="$GIT_SSH_COMMAND -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" | ||
echo "Disabling host key checking" | ||
GIT_SSH_COMMAND="$GIT_SSH_COMMAND -o StrictHostKeyChecking=no" | ||
fi | ||
|
||
git checkout $DEPLOY_BRANCH | ||
|
||
echo "The deploy is starting" | ||
|
||
GIT_SSH_COMMAND="$GIT_SSH_COMMAND" git push dokku@$HOST:$PROJECT $DEPLOY_BRANCH:master $FORCE | ||
GIT_SSH_COMMAND="$GIT_SSH_COMMAND" $GIT_COMMAND |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/sh | ||
|
||
docker run \ | ||
--env "BRANCH=$BRANCH" \ | ||
--env "PRIVATE_KEY=$PRIVATE_KEY" \ | ||
--env "HOST=$HOST" \ | ||
--env "PROJECT=$PROJECT" \ | ||
--env "FORCE_DEPLOY=1" \ | ||
--workdir "/repo" \ | ||
--volume "$LOCAL_REPO:/repo" \ | ||
dokku-github-action |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,42 @@ | ||
#!/bin/sh | ||
# Sets up the environment for running the tests, then runs them. | ||
# Use this as a way to test that the action works in lots of different scenarios | ||
# Tries to deploy to a dokku project using the docker image and entrypoint. | ||
# Use this as a way to test that the action works. | ||
# | ||
# Make a copy of this file called _run.sh and fill in the env vars. | ||
# Make a copy of this file called _run.sh and fill in the env vars in the copy. | ||
# _run.sh is gitignored so you won't accidently commit your SSH keys. | ||
set -eu | ||
|
||
docker build --tag dokku-github-action . | ||
|
||
# Set these as you would expect to set them when using the action | ||
export HOST= | ||
export PROJECT= | ||
export BRANCH= | ||
|
||
|
||
# An absolute path to a git repo on your local machine that can be pushed to dokku | ||
export LOCAL_REPO= | ||
# An absolute path to the private key that can be used to deploy this project | ||
PRIVATE_KEY= | ||
PRIVATE_KEY=$(cat $PRIVATE_KEY) | ||
export PRIVATE_KEY | ||
# An absolute path to the public key for the above private key | ||
PUBLIC_KEY= | ||
PUBLIC_KEY=$(cat $PUBLIC_KEY) | ||
export PUBLIC_KEY | ||
|
||
# This grabs the current host key for HOST | ||
HOST_KEY=$(ssh-keyscan -t rsa "$HOST") | ||
HOST_KEY=$(ssh-keyscan -t rsa "$HOST" 2> /dev/null) | ||
export HOST_KEY | ||
|
||
./tests/host_key_fails.sh | ||
./tests/host_key_skipped.sh | ||
./tests/host_key_works.sh | ||
runtest() { | ||
echo "Running $1" | ||
PASS_CODE="${2-0}" | ||
"./tests/$1.sh" > "./tests/$1.log" 2>&1 | ||
CODE="$?" | ||
if [ "$CODE" = "$PASS_CODE" ]; then | ||
echo " Passed!" | ||
else | ||
echo " Failed (exit code was $CODE not $PASS_CODE)" | ||
fi | ||
} | ||
|
||
echo "Building docker image" | ||
docker build --tag dokku-github-action . > "./tests/build.log" 2>&1 | ||
|
||
runtest "host_key_fails" 128 | ||
runtest "host_key_skipped" | ||
runtest "host_key_works" | ||
runtest "force_deploy" |