2021-06-03 21:05:33 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# Script to mirror a tag from Prysm into EthereumAPIs protocol buffers
|
|
|
|
#
|
|
|
|
# Example:
|
|
|
|
#
|
2021-06-04 16:15:19 +00:00
|
|
|
# mirror-ethereumapis.sh
|
2021-06-03 21:05:33 +00:00
|
|
|
#
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Validate settings.
|
|
|
|
[ "$TRACE" ] && set -x
|
|
|
|
|
2021-06-04 16:15:19 +00:00
|
|
|
## Define variables.
|
2021-06-03 21:05:33 +00:00
|
|
|
GH_API="https://api.github.com"
|
|
|
|
GH_REPO="$GH_API/repos/prysmaticlabs/ethereumapis"
|
|
|
|
|
2021-06-04 16:15:19 +00:00
|
|
|
AUTH="Authorization: token $GITHUB_SECRET_ACCESS_TOKEN"
|
|
|
|
## skipcq: SH-2034
|
2021-06-03 21:05:33 +00:00
|
|
|
export WGET_ARGS="--content-disposition --auth-no-challenge --no-cookie"
|
2021-06-04 16:15:19 +00:00
|
|
|
## skipcq: SH-2034
|
2021-06-03 21:05:33 +00:00
|
|
|
export CURL_ARGS="-LJO#"
|
|
|
|
|
2021-06-04 16:15:19 +00:00
|
|
|
## Validate token.
|
2021-06-03 21:05:33 +00:00
|
|
|
curl -o /dev/null -sH "$AUTH" "$GH_REPO" || { echo "Error: Invalid repo, token or network issue!"; exit 1; }
|
|
|
|
|
|
|
|
# Clone ethereumapis and prysm
|
2021-06-03 21:30:24 +00:00
|
|
|
git clone https://github.com/prysmaticlabs/prysm /tmp/prysm/
|
|
|
|
git clone https://github.com/prysmaticlabs/ethereumapis /tmp/ethereumapis/
|
2021-06-03 21:05:33 +00:00
|
|
|
|
|
|
|
# Checkout the release tag in prysm and copy over protos
|
2021-06-04 16:15:19 +00:00
|
|
|
cd /tmp/prysm && git checkout "$BUILDKITE_COMMIT"
|
|
|
|
|
|
|
|
# Copy proto files, go files, and markdown files
|
|
|
|
find proto/eth \( -name '*.go' -o -name '*.proto' -o -name '*.md' \) -print0 |
|
|
|
|
while IFS= read -r -d '' line; do
|
|
|
|
item_path=$(dirname "$line")
|
|
|
|
mkdir -p /tmp/ethereumapis"${item_path#*proto}" && cp "$line" /tmp/ethereumapis"${line#*proto}"
|
|
|
|
done
|
|
|
|
|
2021-06-03 21:05:33 +00:00
|
|
|
cd /tmp/ethereumapis || exit
|
|
|
|
|
2021-06-04 16:15:19 +00:00
|
|
|
## Replace imports in go files and proto files as needed
|
2021-06-03 21:05:33 +00:00
|
|
|
find ./eth -name '*.go' -print0 |
|
|
|
|
while IFS= read -r -d '' line; do
|
|
|
|
sed -i 's/prysm\/proto\/eth/ethereumapis\/eth/g' "$line"
|
|
|
|
done
|
|
|
|
|
2021-06-04 16:15:19 +00:00
|
|
|
find ./eth -name '*.go' -print0 |
|
|
|
|
while IFS= read -r -d '' line; do
|
|
|
|
sed -i 's/proto\/eth/eth/g' "$line"
|
|
|
|
done
|
|
|
|
|
|
|
|
find ./eth -name '*.go' -print0 |
|
|
|
|
while IFS= read -r -d '' line; do
|
|
|
|
sed -i 's/proto_eth/eth/g' "$line"
|
|
|
|
done
|
|
|
|
|
2021-06-03 21:05:33 +00:00
|
|
|
find ./eth -name '*.proto' -print0 |
|
|
|
|
while IFS= read -r -d '' line; do
|
|
|
|
sed -i 's/"proto\/eth/"eth/g' "$line"
|
|
|
|
done
|
|
|
|
|
2021-06-04 16:15:19 +00:00
|
|
|
find ./eth -name '*.proto' -print0 |
|
|
|
|
while IFS= read -r -d '' line; do
|
|
|
|
sed -i 's/prysmaticlabs\/prysm\/proto\/eth/prysmaticlabs\/ethereumapis\/eth/g' "$line"
|
|
|
|
done
|
|
|
|
|
|
|
|
if git diff-index --quiet HEAD --; then
|
|
|
|
echo "nothing to push, exiting early"
|
2021-06-11 03:05:50 +00:00
|
|
|
exit 0
|
2021-06-04 16:15:19 +00:00
|
|
|
else
|
2023-05-11 20:45:43 +00:00
|
|
|
echo "changes detected, committing and pushing to ethereumapis"
|
2021-06-04 16:15:19 +00:00
|
|
|
fi
|
|
|
|
|
2021-06-03 21:05:33 +00:00
|
|
|
# Push to the mirror repository
|
|
|
|
git add --all
|
2021-06-09 17:09:09 +00:00
|
|
|
GIT_AUTHOR_EMAIL=contact@prysmaticlabs.com GIT_AUTHOR_NAME=prysm-bot GIT_COMMITTER_NAME=prysm-bot GIT_COMMITTER_EMAIL=contact@prysmaticlabs.com git commit -am "Mirrored from github.com/prysmaticlabs/prysm@$BUILDKITE_COMMIT"
|
2021-06-04 22:50:41 +00:00
|
|
|
git remote set-url origin https://prylabs:"$GITHUB_SECRET_ACCESS_TOKEN"@github.com/prysmaticlabs/ethereumapis.git
|
2021-06-03 21:05:33 +00:00
|
|
|
git push origin master
|