Skip to content

Commit

Permalink
fix: fix for the comparison/replacement script for sdk md files (#30)
Browse files Browse the repository at this point in the history
* Update to script

* Update sync_script.sh

* remove sdk

* Update copy-md.yml

* sync simapp changes

* Update copy-md.yml

* Update sync_script.sh

* sync documentation changes

---------

Co-authored-by: samricotta <[email protected]>
  • Loading branch information
samricotta and samricotta authored Sep 13, 2023
1 parent d736f9e commit f7def73
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 83 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/copy-md.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
schedule:
- cron: '0 0,12 * * *'

push:

jobs:
sync-docs:
Expand All @@ -27,3 +27,8 @@ jobs:
run: |
chmod +x sync_script.sh
./sync_script.sh
- uses: stefanzweifel/git-auto-commit-action@v4
if: always()
with:
commit_message: sync documentation changes
72 changes: 40 additions & 32 deletions sync_script.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ for version in "${VERSIONS[@]}"; do
branch="release/v$version.x" # Determine the branch name
version_directory="version-$version" # Create a directory name based on the version

# Skip the '0.47' branch until docs backported
if [ "$branch" = "release/v0.47.x" ]; then
echo "Skipping branch $branch..."
continue
fi
# Skip the '0.47' branch until docs backported
if [ "$branch" = "release/v0.47.x" ]; then
echo "Skipping branch $branch..."
continue
fi

# Change to the 'cosmos-sdk' directory
cd cosmos-sdk
Expand All @@ -51,39 +51,47 @@ for version in "${VERSIONS[@]}"; do
# Change back to the original working directory
cd "$WORK_DIR"

# Find all Markdown files in the local versioned_docs directory
local_md_files=$(find "versioned_docs/$version_directory" -name "*.md")
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

if [ -n "$(find "versioned_docs/$version_directory" -type f -name "*.md")" ]; then
if [ "$local_md_files" ]; then
echo "There are Markdown files in the directory."
# Iterate over each local Markdown file
# Iterate over each local Markdown file
for local_file in $local_md_files; do
local_basename=$(basename "$local_file")

# Iterate over each remote Markdown file
for remote_file in $remote_md_files; do
remote_basename=$(basename "$remote_file")

# Compare the filenames to find matching files
if [ "$local_basename" = "$remote_basename" ]; then
# Check for differences between the local and remote files
if diff "$local_file" "./cosmos-sdk/$remote_file" &>/dev/null; then
echo "No differences found for $local_basename"
else
# Replace the local file with the remote file if differences are found
echo "Differences found for $local_basename and $remote_file. Replacing $local_file with remote file..."
pwd
cp "./cosmos-sdk/docs/$remote_file" "$local_file"
echo "Local file replaced."
fi
elif [ -z "$local_md_files" ]; then
# If there are no local Markdown files, copy the remote file to the local directory
# 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..."
cp "./cosmos-sdk/docs/$remote_file" "$local_file"
echo "Local file $local_file replaced with ./cosmos-sdk/docs/$remote_file"
fi
done
fi
done
done
else
echo "No Markdown files found in the directory, copying over docs folder."
cp -r "./cosmos-sdk/docs/docs" "$WORK_DIR/versioned_docs/$version_directory"
# 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
done

rm -rf ./cosmos-sdk
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Let us go through the different parameters:

* An expected `keeper` is a `keeper` external to a module that is required by the internal `keeper` of said module. External `keeper`s are listed in the internal `keeper`'s type definition as interfaces. These interfaces are themselves defined in an `expected_keepers.go` file in the root of the module's folder. In this context, interfaces are used to reduce the number of dependencies, as well as to facilitate the maintenance of the module itself.
* `storeKey`s grant access to the store(s) of the [multistore](../../develop/advanced/04-store.md) managed by the module. They should always remain unexposed to external modules.
* `cdc` is the [codec](../../develop/advanced/05-encoding.md) used to marshall and unmarshall structs to/from `[]byte`. The `cdc` can be any of `codec.BinaryCodec`, `codec.JSONCodec` or `codec.Codec` based on your requirements. It can be either a proto or amino codec as long as they implement these interfaces. The authority listed is a module account or user account that has the right to change module level parameters. Previously this was handled by the param module, which has been deprecated.
* `cdc` is the [codec](../develop/advanced/05-encoding.md) used to marshall and unmarshall structs to/from `[]byte`. The `cdc` can be any of `codec.BinaryCodec`, `codec.JSONCodec` or `codec.Codec` based on your requirements. It can be either a proto or amino codec as long as they implement these interfaces. The authority listed is a module account or user account that has the right to change module level parameters. Previously this was handled by the param module, which has been deprecated.

Of course, it is possible to define different types of internal `keeper`s for the same module (e.g. a read-only `keeper`). Each type of `keeper` comes with its own constructor function, which is called from the [application's constructor function](../../develop/beginner/00-app-anatomy.md). This is where `keeper`s are instantiated, and where developers make sure to pass correct instances of modules' `keeper`s to other modules that require them.

Expand Down
54 changes: 5 additions & 49 deletions versioned_docs/version-0.50/develop/advanced/05-encoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,58 +42,14 @@ In the `codec` package, there exists two core interfaces, `BinaryCodec` and `JSO
where the former encapsulates the current Amino interface except it operates on
types implementing the latter instead of generic `interface{}` types.

In addition, there exists two implementations of `Codec`. The first being
`AminoCodec`, where both binary and JSON serialization is handled via Amino. The
second being `ProtoCodec`, where both binary and JSON serialization is handled
via Protobuf.

This means that modules may use Amino or Protobuf encoding, but the types must
The `ProtoCodec`, where both binary and JSON serialization is handled
via Protobuf. This means that modules may use Protobuf encoding, but the types must
implement `ProtoMarshaler`. If modules wish to avoid implementing this interface
for their types, they may use an Amino codec directly.

### Amino

Every module uses an Amino codec to serialize types and interfaces. This codec typically
has types and interfaces registered in that module's domain only (e.g. messages),
but there are exceptions like `x/gov`. Each module exposes a `RegisterLegacyAminoCodec` function
that allows a user to provide a codec and have all the types registered. An application
will call this method for each necessary module.

Where there is no protobuf-based type definition for a module (see below), Amino
is used to encode and decode raw wire bytes to the concrete type or interface:

```go
bz := keeper.cdc.MustMarshal(typeOrInterface)
keeper.cdc.MustUnmarshal(bz, &typeOrInterface)
```

Note, there are length-prefixed variants of the above functionality and this is
typically used for when the data needs to be streamed or grouped together
(e.g. `ResponseDeliverTx.Data`)

#### Authz authorizations and Gov/Group proposals
for their types, this is autogenerated via [buf](https://buf.build/)

Since authz's `MsgExec` and `MsgGrant` message types, as well as gov's and group's `MsgSubmitProposal`, can contain different messages instances, it is important that developers
add the following code inside the `init` method of their module's `codec.go` file:
If modules use [Collections](../../build/packages/02-collections.md) or [ORM](../../build/packages/03-orm.md), encoding and decoding are handled, marshal and unmarshal should not be handled manually unless for specific cases identified by the developer.

```go
import (
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
govcodec "github.com/cosmos/cosmos-sdk/x/gov/codec"
groupcodec "github.com/cosmos/cosmos-sdk/x/group/codec"
)

init() {
// Register all Amino interfaces and concrete types on the authz and gov Amino codec so that this can later be
// used to properly serialize MsgGrant, MsgExec and MsgSubmitProposal instances
RegisterLegacyAminoCodec(authzcodec.Amino)
RegisterLegacyAminoCodec(govcodec.Amino)
RegisterLegacyAminoCodec(groupcodec.Amino)
}
```

This will allow the `x/authz` module to properly serialize and de-serializes `MsgExec` instances using Amino,
which is required when signing this kind of messages using a Ledger.
```go reference

### Gogoproto

Expand Down

0 comments on commit f7def73

Please sign in to comment.