git-docker/posix/clone

84 lines
2.2 KiB
Plaintext
Raw Normal View History

2018-08-08 21:43:53 +00:00
#!/bin/sh
if [[ ! -z "${DRONE_WORKSPACE}" ]]; then
cd ${DRONE_WORKSPACE}
fi
# if the netrc enviornment variables exist, write
# the netrc file.
if [[ ! -z "${DRONE_NETRC_MACHINE}" ]]; then
cat <<EOF > /root/.netrc
machine ${DRONE_NETRC_MACHINE}
login ${DRONE_NETRC_USERNAME}
password ${DRONE_NETRC_PASSWORD}
EOF
fi
# if the ssh_key environment variable exists, write
# the ssh key and add the netrc machine to the
# known hosts file.
2020-11-06 14:10:13 +00:00
if [[ ! -z "${DRONE_SSH_KEY}" ]]; then
2018-08-08 21:43:53 +00:00
mkdir /root/.ssh
2020-11-06 14:10:13 +00:00
echo -n "$DRONE_SSH_KEY" > /root/.ssh/id_rsa
2018-08-08 21:43:53 +00:00
chmod 600 /root/.ssh/id_rsa
touch /root/.ssh/known_hosts
chmod 600 /root/.ssh/known_hosts
ssh-keyscan -H ${DRONE_NETRC_MACHINE} > /etc/ssh/ssh_known_hosts 2> /dev/null
fi
# AWS codecommit support using AWS access key & secret key
# Refer: https://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-https-unixes.html
if [[ ! -z "$DRONE_AWS_ACCESS_KEY" ]]; then
aws configure set aws_access_key_id $DRONE_AWS_ACCESS_KEY
aws configure set aws_secret_access_key $DRONE_AWS_SECRET_KEY
aws configure set default.region $DRONE_AWS_REGION
git config --global credential.helper '!aws codecommit credential-helper $@'
git config --global credential.UseHttpPath true
fi
2018-08-08 21:43:53 +00:00
# configure git global behavior and parameters via the
# following environment variables:
2019-01-21 20:30:42 +00:00
if [[ -z "${DRONE_COMMIT_AUTHOR_NAME}" ]]; then
export DRONE_COMMIT_AUTHOR_NAME=drone
fi
2019-01-21 20:30:42 +00:00
if [[ -z "${DRONE_COMMIT_AUTHOR_EMAIL}" ]]; then
export DRONE_COMMIT_AUTHOR_EMAIL=drone@localhost
fi
export GIT_AUTHOR_NAME=${DRONE_COMMIT_AUTHOR_NAME}
export GIT_AUTHOR_EMAIL=${DRONE_COMMIT_AUTHOR_EMAIL}
export GIT_COMMITTER_NAME=${DRONE_COMMIT_AUTHOR_NAME}
export GIT_COMMITTER_EMAIL=${DRONE_COMMIT_AUTHOR_EMAIL}
2018-08-08 21:43:53 +00:00
# invoke the sub-script based on the drone event type.
# TODO we should ultimately look at the ref, since
# we need something compatible with deployment events.
CLONE_TYPE=$DRONE_BUILD_EVENT
case $DRONE_COMMIT_REF in
refs/tags/* ) CLONE_TYPE=tag ;;
refs/pull/* ) CLONE_TYPE=pull_request ;;
refs/pull-request/* ) CLONE_TYPE=pull_request ;;
refs/merge-requests/* ) CLONE_TYPE=pull_request ;;
esac
case $CLONE_TYPE in
2018-08-08 21:43:53 +00:00
pull_request)
clone-pull-request
;;
tag)
clone-tag
;;
*)
clone-commit
;;
esac