-
Notifications
You must be signed in to change notification settings - Fork 2
/
update_services.sh
executable file
·81 lines (66 loc) · 2.65 KB
/
update_services.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
75
76
77
78
79
80
81
#!/bin/bash
# when editing repositories, make sure to update mkdocs.yml accordingly
declare -A repos=(
["Landing page UI"]="https://github.com/RedHatInsights/landing-page-frontend.git"
["Settings UI"]="https://github.com/RedHatInsights/settings-frontend.git"
["User preferences UI"]="https://github.com/RedHatInsights/user-preferences-frontend.git"
["API catalog"]="https://github.com/RedHatInsights/api-documentation-frontend.git"
["Notifications UI"]="https://github.com/RedHatInsights/notifications-frontend.git"
["RBAC UI"]="https://github.com/RedHatInsights/insights-rbac-ui.git"
["Sources UI"]="https://github.com/RedHatInsights/sources-ui.git"
["Learning resource page"]="https://github.com/RedHatInsights/learning-resources.git"
["Payload tracker UI"]="https://github.com/RedHatInsights/payload-tracker-frontend.git"
["UI starter app"]="https://github.com/RedHatInsights/frontend-starter-app.git"
["Frontend components"]="https://github.com/RedHatInsights/frontend-components.git"
["PF Component groups"]="https://github.com/patternfly/react-component-groups.git"
["PF Data view"]="https://github.com/patternfly/react-data-view.git"
["PF Virtual assistant"]="https://github.com/patternfly/virtual-assistant.git"
)
TARGET_DIR="pages/services"
TEMP_DIR="temp_repos"
get_default_branch() {
local repo_dir=$1
cd "$repo_dir" || exit
git remote set-head origin -a >/dev/null 2>&1
local default_branch=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')
cd - >/dev/null || exit
echo "$default_branch"
}
# clone or pull the latest repo changes
clone_or_pull_repo() {
local repo_name=$1
local repo_url=$2
local repo_dir="${TEMP_DIR}/${repo_name}"
if [ ! -d "$repo_dir" ]; then
echo "Cloning $repo_name..."
git clone "$repo_url" "$repo_dir"
else
echo "Pulling latest changes for $repo_name..."
cd "$repo_dir" || exit
default_branch=$(get_default_branch "$repo_dir")
git pull origin "$default_branch"
cd - || exit
fi
}
copy_readme() {
local repo_name=$1
local repo_dir="${TEMP_DIR}/${repo_name}"
local readme_path="${repo_dir}/README.md"
local dest_path="${TARGET_DIR}/${repo_name}.md"
if [ -f "$readme_path" ]; then
cp -f "$readme_path" "$dest_path"
else
echo "README.md not found in $repo_name!"
fi
}
main() {
mkdir -p "$TARGET_DIR"
mkdir -p "$TEMP_DIR"
for repo_name in "${!repos[@]}"; do
repo_url="${repos[$repo_name]}"
clone_or_pull_repo "$repo_name" "$repo_url"
copy_readme "$repo_name"
done
rm -rf "$TEMP_DIR"
}
main