Skip to content

Commit

Permalink
refactor: alternative script copying over the whole of the docs direc…
Browse files Browse the repository at this point in the history
…tory (#50)
  • Loading branch information
samricotta authored Sep 25, 2023
1 parent f6e1e46 commit 56dad83
Showing 1 changed file with 15 additions and 58 deletions.
73 changes: 15 additions & 58 deletions sync_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ for version in "${VERSIONS[@]}"; do
fi

# Change to the 'cosmos-sdk' directory
cd cosmos-sdk
cd $WORK_DIR/cosmos-sdk

# Fetch the branch from the remote repository and switch to it
git fetch origin "$branch"
Expand All @@ -50,63 +50,20 @@ for version in "${VERSIONS[@]}"; do
echo "Branch $branch exists, continuing..."
fi

# Find all Markdown files in the 'docs' directory
if [ "$version" == "main" ]; then # update for 0.51
# main has a different strucutre then versions
remote_md_files=$(find "docs" -name "*.md")
else
cd docs
remote_md_files=$(find "docs" -name "*.md")
fi

# Change back to the original working directory
cd "$WORK_DIR"

if [ "$version" == "main" ]; then
local_md_files=$(find "docs" -name "*.md") # For 'main', the version directory is empty
else
# Find all Markdown files in the local versioned_docs directory
local_md_files=$(find "versioned_docs/$version_directory" -name "*.md")
fi
# Run the pre.sh script
cd docs && sh ./pre.sh

if [ "$local_md_files" ]; then
echo "There are Markdown files in the directory."
# Iterate over each local Markdown file
for local_file in $local_md_files; do
# Construct the relative path of the local file
if [ "$version" != "main" ]; then
local_relative_path="${local_file#versioned_docs/$version_directory/}"
else
local_relative_path="${local_file#docs/}"
fi
# Iterate over each remote Markdown file
for remote_file in $remote_md_files; do
# Construct the relative path of the remote file
remote_relative_path="${remote_file#docs/}"


# Compare the relative paths to find matching files
if [ "$local_relative_path" = "$remote_relative_path" ]; then
# Check for differences between the local and remote files
if diff "$local_file" "./cosmos-sdk/docs/$remote_file" &>/dev/null; then
echo "No differences found for $local_file and $remote_file"
else
# Replace the local file with the remote file if differences are found
echo "Differences found for $local_file and $remote_file. Replacing $local_file with remote file..."
if [ "$version" == "main" ]; then
cp "./cosmos-sdk/$remote_file" "$local_file"
else
cp "./cosmos-sdk/docs/$remote_file" "$local_file"
fi
fi
fi
done
done
else
# The file does not exist, so copy the remote file
cp "./cosmos-sdk/docs/$remote_file" "$local_file"
echo "File $local_file created and replaced with ./cosmos-sdk/docs/$remote_file"
fi
for folder in "build" "user" "learn"; do
if [ "$version" == "main" ]; then
cp -r "$WORK_DIR/cosmos-sdk/docs/$folder" "$WORK_DIR/docs/"
else
cp -r "$WORK_DIR/cosmos-sdk/docs/docs/$folder" "$WORK_DIR/versioned_docs/$version_directory/"
fi
done
done

rm -rf ./cosmos-sdk
# Leave the 'cosmos-sdk' directory after processing
cd "$WORK_DIR"

# Remove the 'cosmos-sdk' directory if needed
rm -rf ./cosmos-sdk

0 comments on commit 56dad83

Please sign in to comment.