source: |
FULL_URL="{{inputs.parameters.repo_url}}"
DESTINATION="{{inputs.parameters.destination_folder}}"
- CLONE_URL=""
echo "Cloning: ${FULL_URL} . . ."
[[ -n "${DESTINATION}" ]] && mkdir -p "${DESTINATION}"
- # Determine final clone URL
- if [[ -z "${GIT_USER}" ]]; then
- CLONE_URL="${FULL_URL}"
- elif [[ -n "${GIT_PASS}" ]]; then
- PROTOCOL=$(echo "${FULL_URL}" | awk -F '://' '{print $1}')
- BASE_URL=$(echo "${FULL_URL}" | awk -F '://' '{print $2}')
- CLONE_URL="${PROTOCOL}://${GIT_USER}@${BASE_URL}"
+ # Follow recommendation for user auth with git using a script git-creds.sh
+ cat << "EOF" > "${HOME}/git-creds.sh"
+ #!/bin/sh
+ if echo "$1" | grep -q '^Password'; then
+ echo "${GIT_PASS}"
else
- echo "ERROR: Malformed invocation."
- echo " FULL_URL=${FULL_URL}"
- echo " GIT_USER=${GIT_USER}"
- echo " DESTINATION=${DESTINATION}"
- exit 1
+ echo "${GIT_USER}"
fi
+ exit 0
+ EOF
+ chmod +x "${HOME}/git-creds.sh"
# Clone
mkdir -p /repos
cd /repos
if [[ -z "${DESTINATION}" ]]; then
- echo -e "${GIT_PASS}\n" | git clone "${CLONE_URL}"
+ TTY=$(tty) GIT_USERNAME="${GIT_USER}" GIT_ASKPASS=~/git-creds.sh git clone "${FULL_URL}"
else
- echo -e "${GIT_PASS}\n" | git clone "${CLONE_URL}" "${DESTINATION}"
+ TTY=$(tty) GIT_USERNAME="${GIT_USER}" GIT_ASKPASS=~/git-creds.sh git clone "${FULL_URL}" "${DESTINATION}"
fi
- name: git-commit-merge-push
MAIN_BRANCH="{{inputs.parameters.main_branch}}"
DRY_RUN="{{inputs.parameters.dry_run}}"
+ # Follow recommendation for user auth with git using a script git-creds.sh
+ cat << "EOF" > "${HOME}/git-creds.sh"
+ #!/bin/sh
+ if echo "$1" | grep -q '^Password'; then
+ echo "${GIT_PASS}"
+ else
+ echo "${GIT_USER}"
+ fi
+ exit 0
+ EOF
+ chmod +x "${HOME}/git-creds.sh"
+
# Go to the repo folder
cd "${DESTINATION}"
# Pull and merge branch
git checkout ${MAIN_BRANCH}
echo "Pulling latest commits from ${MAIN_BRANCH} branch (if any)..."
- echo -e "${GIT_PASS}\n" | git pull
+ TTY=$(tty) GIT_USERNAME="${GIT_USER}" GIT_ASKPASS=~/git-creds.sh git pull
echo "Merging branch ${CONTRIB_BRANCH} onto ${MAIN_BRANCH}..."
git merge --no-ff "${CONTRIB_BRANCH}"
if [[ "${DRY_RUN}" != "true" ]]
then
echo "Pushing..."
- cat << "EOF" > "${HOME}/git-creds.sh"
- #!/bin/sh
- if echo "$1" | grep -q '^Password'; then
- echo "${GIT_PASS}"
- else
- echo "${GIT_USER}"
- fi
- exit 0
- EOF
-
- chmod +x "${HOME}/git-creds.sh"
TTY=$(tty) GIT_USERNAME="${GIT_USER}" GIT_ASKPASS=~/git-creds.sh git push origin "${MAIN_BRANCH}"
-
else
echo "DRY RUN - NO PUSH"
fi