1 #######################################################################################
2 # Copyright ETSI Contributors and Others.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #######################################################################################
18 apiVersion: argoproj.io/v1alpha1
19 kind: WorkflowTemplate
22 namespace: osm-workflows
30 - name: destination_folder
31 - name: git_cred_secret
32 - name: git_volume_name
36 persistentVolumeClaim:
37 claimName: '{{inputs.parameters.git_volume_name}}'
39 image: alpine/git:2.45.1
44 name: "{{inputs.parameters.git_cred_secret}}"
49 name: "{{inputs.parameters.git_cred_secret}}"
53 mountPath: '{{inputs.parameters.mount_path}}'
56 FULL_URL="{{inputs.parameters.repo_url}}"
57 DESTINATION="{{inputs.parameters.destination_folder}}"
60 echo "Cloning: ${FULL_URL} . . ."
62 [[ -n "${DESTINATION}" ]] && mkdir -p "${DESTINATION}"
64 # Determine final clone URL
65 if [[ -z "${GIT_USER}" ]]; then
66 CLONE_URL="${FULL_URL}"
67 elif [[ -n "${GIT_PASS}" ]]; then
68 PROTOCOL=$(echo "${FULL_URL}" | awk -F '://' '{print $1}')
69 BASE_URL=$(echo "${FULL_URL}" | awk -F '://' '{print $2}')
70 CLONE_URL="${PROTOCOL}://${GIT_USER}@${BASE_URL}"
72 echo "ERROR: Malformed invocation."
73 echo " FULL_URL=${FULL_URL}"
74 echo " GIT_USER=${GIT_USER}"
75 echo " DESTINATION=${DESTINATION}"
82 if [[ -z "${DESTINATION}" ]]; then
83 echo -e "${GIT_PASS}\n" | git clone "${CLONE_URL}"
85 echo -e "${GIT_PASS}\n" | git clone "${CLONE_URL}" "${DESTINATION}"
88 - name: git-commit-merge-push
92 - name: git_cred_secret
93 - name: git_volume_name
95 - name: commit_message
98 - name: contrib_branch
104 persistentVolumeClaim:
105 claimName: '{{inputs.parameters.git_volume_name}}'
107 image: alpine/git:2.45.1
112 name: "{{inputs.parameters.git_cred_secret}}"
117 name: "{{inputs.parameters.git_cred_secret}}"
121 mountPath: '{{inputs.parameters.mount_path}}'
124 DESTINATION="{{inputs.parameters.repo_folder}}"
125 COMMIT_MESSAGE="{{inputs.parameters.commit_message}}"
126 CONTRIB_BRANCH="{{inputs.parameters.contrib_branch}}"
127 MAIN_BRANCH="{{inputs.parameters.main_branch}}"
128 DRY_RUN="{{inputs.parameters.dry_run}}"
130 # Go to the repo folder
133 # Setup global Git user and email
134 echo "Setting up global Git user and e-mail..."
135 git config --global user.name "${GIT_USER}"
136 git config --global user.email "${GIT_USER}@${GIT_USER}.local"
138 # Create contrib branch
139 echo "Creating ${CONTRIB_BRANCH} branch into ${DESTINATION}..."
140 git checkout -b ${CONTRIB_BRANCH}
145 git commit -m "Operation ${CONTRIB_BRANCH}: ${COMMIT_MESSAGE}"
147 # Pull and merge branch
148 git checkout ${MAIN_BRANCH}
149 echo "Pulling latest commits from ${MAIN_BRANCH} branch (if any)..."
150 echo -e "${GIT_PASS}\n" | git pull
152 echo "Merging branch ${CONTRIB_BRANCH} onto ${MAIN_BRANCH}..."
153 git merge --no-ff "${CONTRIB_BRANCH}"
155 if [[ "${DRY_RUN}" != "true" ]]
158 cat << "EOF" > "${HOME}/git-creds.sh"
160 if echo "$1" | grep -q '^Password'; then
168 chmod +x "${HOME}/git-creds.sh"
169 TTY=$(tty) GIT_USERNAME="${GIT_USER}" GIT_ASKPASS=~/git-creds.sh git push origin "${MAIN_BRANCH}"
172 echo "DRY RUN - NO PUSH"