-
Notifications
You must be signed in to change notification settings - Fork 239
/
create-repos.sh
executable file
·74 lines (63 loc) · 2.54 KB
/
create-repos.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
# !/bin/bash
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# [START anthosconfig_multi_environments_kustomize_create_repos]
if [[ -z "$GITHUB_USERNAME" ]]; then
echo "Must provide GITHUB_USERNAME in environment" 1>&2
exit 1
fi
## Returns 0 if arg $1 is a reachable git remote url
git-remote-url-reachable() {
git ls-remote "$1" CHECK_GIT_REMOTE_URL_REACHABILITY >/dev/null 2>&1
}
echo "😸 Creating foo-config-source repo..."
url="https://github.com/$GITHUB_USERNAME/foo-config-source"
if git-remote-url-reachable "$url"; then
echo "✅ foo-config-source repo already exists"
else
curl -u ${GITHUB_USERNAME}:${GITHUB_TOKEN} https://api.github.com/user/repos -d '{"name":"foo-config-source"}'
fi
git clone "https://github.com/${GITHUB_USERNAME}/foo-config-source.git"
cp -r config-source/* foo-config-source
cd foo-config-source
git checkout -b main
git add .; git commit -m "Initialize"; git push origin main
cd ..
echo "😸 Creating foo-config-dev repo..."
url="https://github.com/$GITHUB_USERNAME/foo-config-dev"
if git-remote-url-reachable "$url"; then
echo "✅ foo-config-dev repo already exists"
else
curl -u ${GITHUB_USERNAME}:${GITHUB_TOKEN} https://api.github.com/user/repos -d '{"name":"foo-config-dev"'
fi
git clone "https://github.com/${GITHUB_USERNAME}/foo-config-dev.git"
cd foo-config-dev
git checkout -b main
echo "Foo Config Dev" >> README.md
git add .; git commit -m "Initialize"; git push origin main
cd ..
echo "😸 Creating foo-config-prod repo..."
url="https://github.com/$GITHUB_USERNAME/foo-config-prod"
if git-remote-url-reachable "$url"; then
echo "✅ foo-config-prod repo already exists"
else
curl -u ${GITHUB_USERNAME}:${GITHUB_TOKEN} https://api.github.com/user/repos -d '{"name":"foo-config-prod"}'
fi
git clone "https://github.com/${GITHUB_USERNAME}/foo-config-prod.git"
cd foo-config-prod
git checkout -b main
echo "Foo Config Prod" >> README.md
git add .; git commit -m "Initialize"; git push origin main
cd ..
# [END anthosconfig_multi_environments_kustomize_create_repos]