/
make-repo
executable file
·214 lines (188 loc) · 5.23 KB
/
make-repo
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/bin/bash
HELP=$(
cat <<EOF
This program produces a sample puppet repo used for testing
EOF
)
set -o errexit
set -o pipefail
set -o nounset
shopt -s lastpipe
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
HECKLERD_CONF="${THIS_DIR}/doc/sample-configs/hecklerd_conf.yaml"
usage() {
cat <<EOF
${HELP}
Usage:
${0} -u <repo_url>
${0} -h
Options:
-u <repo url> Repo url to set up this example repo in. Should be uninitialized, but we do try to work around the case where you have already initialized it.
-h Print this help message
EOF
}
function main() {
NODES=(
fozzie
statler
waldorf
)
MODULES=(
fozzie
statler
waldorf
muppetshow
)
AUTHORS=(
[1]='misspiggy <heckler+misspiggy@getbraintree.com>'
[2]='kermit <heckler+kermit@getbraintree.com>'
[3]='misspiggy <heckler+misspiggy@getbraintree.com>'
[4]='misspiggy <heckler+misspiggy@getbraintree.com>'
[5]='misspiggy <heckler+misspiggy@getbraintree.com>'
[6]='kermit <heckler+kermit@getbraintree.com>'
[7]='kermit <heckler+kermit@getbraintree.com>'
[8]='kermit <heckler+kermit@getbraintree.com>'
[9]='misspiggy <heckler+misspiggy@getbraintree.com>'
[10]='kermit <heckler+kermit@getbraintree.com>'
)
CO_AUTHORS=(
[3]='kermit <heckler+kermit@getbraintree.com>'
[5]='kermit <heckler+kermit@getbraintree.com>'
[8]='misspiggy <heckler+misspiggy@getbraintree.com>'
)
MSGS=(
[1]='commit1'
[2]='stop nginx on fozzie & add episode one
stop nginx on fozzie
add episode one
modify wit on statler
modify poignant on waldor
modify slapstick on fozzie'
[3]='finish the muppet show lyrics
finish composing the muppet show lyrics
move index out of muppetshow class into node
class'
[4]='New Movie'
[5]='Gonzo'
[6]='add some fun diversions
add bsdgames on fozzie
add sl to statler & waldorf
'
[7]='add kermit user, modify sail input
add kermit user and muppetshow group
modify the input to the sail game
'
[8]='More Statler'
[9]='Even more Statler'
[10]='add gonzo user'
)
# commit number -> tag to give it
TAGS=(
[1]='v1'
[7]='v2'
[9]='v3'
[10]='v4'
)
while getopts ":hu:" opt; do
case "${opt}" in
h)
usage
return
;;
u)
REPO_URL=$OPTARG
;;
\?)
usage 1>&2
return 1
;;
:)
printf "ERROR: Option -%s requires an argument\n" "${OPTARG}" >&2
usage 1>&2
return 1
;;
esac
done
shift $((OPTIND - 1))
if ! [[ -v REPO_URL ]]; then
printf 'ERROR: You must specify a repo url\n' >&2
usage >&2
return 1
fi
## Initialize the repo, ensuring your integration test branch and the remote
## tags are all clear. We assume that your default branch might be different
## from the one in the hecklerd config and take care not to touch other
## branches, since you may have protections on them, even at an
## organizational level (like we do.)
tmp_repo=$(mktemp -d)
pushd "${tmp_repo}"
git init
HECKLER_BRANCH="$(yq -r '.repo_branch' "${HECKLERD_CONF}")"
git checkout -b "${HECKLER_BRANCH}"
git config advice.detachedHead false
mkdir -p nodes
mkdir -p modules
cp -r "${THIS_DIR}"/manifests/vendor/* modules/
git add -f modules
for module in "${MODULES[@]}"; do
mkdir -p 'modules/'"${module}"'/manifests'
done
for ((commit = 1; commit <= "${#AUTHORS[@]}"; commit++)); do
if ((commit == 1)); then
for f in site.pp CODEOWNERS; do
cp "${THIS_DIR}"/manifests/"${f}" ./
git add -f "${f}"
done
cp "${THIS_DIR}"/puppet.conf ./
git add -f puppet.conf
fi
if ((commit == 4)); then
git checkout -b manhattan
fi
if ((commit == 6)); then
git checkout "${HECKLER_BRANCH}"
fi
for module in "${MODULES[@]}"; do
printf -v src '%s/manifests/modules/%s/manifests' "${THIS_DIR}" "${module}"
printf -v dst 'modules/%s/manifests' "${module}"
pushd "${src}"
pps=(*"${commit}".pp)
popd
for pp in "${pps[@]}"; do
base_file=${pp%%"${commit}"'.pp'}
mkdir -p "${dst}"
cp "${src}"/"${pp}" "${dst}"/"${base_file}".pp
git add -f "${dst}"/"${base_file}".pp
done
done
for node in "${NODES[@]}"; do
printf -v src '%s/manifests/nodes/%s%d.pp' "${THIS_DIR}" "${node}" "${commit}"
printf -v dst 'nodes/%s.pp' "${node}"
cp "${src}" "${dst}"
git add -f "${dst}"
done
msg="${MSGS[commit]}"
if [[ -v "CO_AUTHORS[${commit}]" ]]; then
printf -v co_author '\n\nCo-authored-by: %s' "${CO_AUTHORS[${commit}]}"
msg+="${co_author}"
fi
git commit --author "${AUTHORS[$commit]}" -F - <<<"${msg}"
if ((commit == 7)); then
git merge -m 'Take Manhattan' manhattan
fi
if [[ -v "TAGS[${commit}]" ]]; then
git tag "${TAGS[${commit}]}" -m "Release ${TAGS[${commit}]}"
fi
done
git remote add origin "${REPO_URL}"
git push -fu origin "${HECKLER_BRANCH}"
## Clear out all remote tags so only the ones we just made will remain
git ls-remote --tags origin | sed -E 's/(^.*refs\/tags\/)([^\^]+)(\^\{\})?/\2/' \
| sort | uniq | mapfile -t remote_tags
for tag in "${remote_tags[@]}"; do
git push --delete origin "${tag}"
done
git push -f --tags
popd
}
main "${@}"