-
Notifications
You must be signed in to change notification settings - Fork 4
/
sync_script.sh
executable file
·91 lines (73 loc) · 2.62 KB
/
sync_script.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
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
set -e -o pipefail
# Set the remote repository URL to clone from
# TODO: pull from https://github.com/provenance-io/cosmos-modules as well
REMOTE_REPO_URL="https://github.com/provenance-io/provenance.git"
# Store the current working directory in WORK_DIR
WORK_DIR=$(pwd)
# Remove any existing 'prov-sdk' directory and clone the remote repository
rm -rf ./prov-sdk
git clone "$REMOTE_REPO_URL" prov-sdk
# Read the versions from a JSON file and remove the 'v' prefix
VERSIONS=($(jq -r '.[]' versions.json))
VERSIONS+=("main")
# Iterate over each version
for version in "${VERSIONS[@]}"; do
echo "$version"
if [ "$version" == "main" ]; then
branch="main" # Set the branch to 'main'
version_directory="" # For 'main', the version directory is empty
else
version="${version#v}" # Remove the 'v' prefix from the version number
branch="release/v$version.x" # Determine the branch name
version_directory="version-$version" # Create a directory name based on the version
fi
# Change to the 'prov-sdk' directory
cd $WORK_DIR/prov-sdk
# Fetch the branch from the remote repository and switch to it
git fetch origin "$branch"
git checkout "$branch"
# Check if the branch exists in the remote repository
if ! git show-ref --verify "refs/remotes/origin/$branch" &>/dev/null; then
echo "Branch $branch does not exist in the remote repository."
continue
else
echo "Branch $branch exists, continuing..."
fi
# build the docs
cd $WORK_DIR/prov-sdk/docs
for D in ../x/*; do
echo "Processing ${D}"
if [ -d "${D}" ]; then
DIR_NAME=$(echo $D | awk -F/ '{print $NF}')
MODDOC=sdk/$DIR_NAME
rm -rf $MODDOC
mkdir -p $MODDOC
# ibchooks doesn't have a spec folder
if [ -f "$D/README.md" ]; then
cp -r $D/README.md $MODDOC/
fi
# The rest of the modules have a spec folder
if [ -f "$D/spec/README.md" ]; then
cp -r $D/spec/* $MODDOC/
fi
fi
done
# Add modules page list
cat ../x/README.md | sed 's/\/spec\//\//g' > ./sdk/README.md
echo -e "---\nsidebar_position: 0\n---\n\n$(cat ./sdk/README.md)" > ./sdk/README.md
for folder in "sdk"; do
if [ "$version" == "main" ]; then
cp -r "$WORK_DIR/prov-sdk/docs/$folder" "$WORK_DIR/docs/"
else
cp -r "$WORK_DIR/prov-sdk/docs/$folder" "$WORK_DIR/versioned_docs/$version_directory/"
fi
done
if [ "$version" == "main" ]; then
cp -r "$WORK_DIR/prov-sdk/client/docs/swagger-ui/swagger.yaml" "$WORK_DIR/openapi/"
fi
done
# Leave the 'prov-sdk' directory after processing
cd "$WORK_DIR"
# Remove the 'prov-sdk' directory if needed
rm -rf ./prov-sdk