-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathload-projects.sh
75 lines (64 loc) · 2.13 KB
/
load-projects.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env bash
set -o errexit
set -o pipefail
SSH_DIR="$HOME/.ssh"
GIT_DIR="$HOME/.gitconfig"
GERRIT_URL="ssh.gerrit.home.arpa"
GERRIT_USERNAME="jjuly"
GERRIT_BRANCH="main"
function actOnGerrit() {
ssh -p 29418 \
-o "StrictHostKeyChecking no" \
-i ~/.ssh/id_rsa \
${GERRIT_USERNAME}@${GERRIT_URL} \
${@}
}
function deleteProject() {
local project_name="${1}"
echo >&2 "[${project_name}] Deleting project"
actOnGerrit \
delete-project delete --yes-really-delete --force \
"${project_name}"
}
function loadProject() {
local project_directory="${1}"
local project_name="${2}"
local current_directory="${PWD}"
echo >&2 "[${project_name}] Copy code to temporary directory"
local temp_directory="$(mktemp -d)"
trap 'rm -rf -- "${temp_directory}"' EXIT INT
echo >&2 "[${project_name}] Preparing repository from ${project_directory}"
rsync --recursive -P --exclude="node_modules" --exclude=".git" "${project_directory}" "${temp_directory}"
cd ${temp_directory}
git init
git commit --allow-empty --message "Initial commit"
git add --all
git commit --message "Add initial code" || true
echo >&2 "[${project_name}] Creating project in gerrit"
actOnGerrit \
gerrit create-project \
--branch=${GERRIT_BRANCH} \
"${project_name}.git"
echo >&2 "[${project_name}] Pushing to gerrit"
git push ssh://${GERRIT_USERNAME}@${GERRIT_URL}:29418/${project_name} HEAD:refs/heads/${GERRIT_BRANCH} --force
cd "${current_directory}"
}
function install_update() {
deleteProject "${2}" || true
loadProject "${1}/" "${2}"
}
if [[ ${#} -ne 0 ]]; then
if declare -f "$1" > /dev/null; then
# call arguments verbatim
"${@}"
else
# Show a helpful error
>&2 echo "'$1' is not a known function name"
exit 1
fi
else
install_update ./projects/Bootstrap-Repositories/Example-Service Example-Service
install_update ./projects/Bootstrap-Repositories/jenkins Jenkins-Libraries
install_update ./projects/Experiments/Deployment-Configuration/ArgocdExampleService ArgocdExampleService
install_update ./projects/Bootstrap-Repositories/State-Repository State-Repository
fi