github.com/prysmaticlabs/prysm@v1.4.4/scripts/mirror-ethereumapis.sh (about)

     1  #!/usr/bin/env bash
     2  #
     3  # Script to mirror a tag from Prysm into EthereumAPIs protocol buffers
     4  #
     5  # Example:
     6  #
     7  # mirror-ethereumapis.sh
     8  #
     9  set -e
    10  
    11  # Validate settings.
    12  [ "$TRACE" ] && set -x
    13  
    14  ## Define variables.
    15  GH_API="https://api.github.com"
    16  GH_REPO="$GH_API/repos/prysmaticlabs/ethereumapis"
    17  
    18  AUTH="Authorization: token $GITHUB_SECRET_ACCESS_TOKEN"
    19  ## skipcq: SH-2034
    20  export WGET_ARGS="--content-disposition --auth-no-challenge --no-cookie"
    21  ## skipcq: SH-2034
    22  export CURL_ARGS="-LJO#"
    23  
    24  ## Validate token.
    25  curl -o /dev/null -sH "$AUTH" "$GH_REPO" || { echo "Error: Invalid repo, token or network issue!";  exit 1; }
    26  
    27  # Clone ethereumapis and prysm
    28  git clone https://github.com/prysmaticlabs/prysm /tmp/prysm/
    29  git clone https://github.com/prysmaticlabs/ethereumapis /tmp/ethereumapis/
    30  
    31  # Checkout the release tag in prysm and copy over protos
    32  cd /tmp/prysm && git checkout "$BUILDKITE_COMMIT"
    33  
    34  # Copy proto files, go files, and markdown files
    35  find proto/eth \( -name '*.go' -o -name '*.proto' -o -name '*.md' \) -print0 |
    36      while IFS= read -r -d '' line; do
    37          item_path=$(dirname "$line")
    38          mkdir -p /tmp/ethereumapis"${item_path#*proto}" && cp "$line" /tmp/ethereumapis"${line#*proto}"
    39      done
    40  
    41  cd /tmp/ethereumapis || exit
    42  
    43  ## Replace imports in go files and proto files as needed
    44  find ./eth -name '*.go' -print0 |
    45      while IFS= read -r -d '' line; do
    46          sed -i 's/prysm\/proto\/eth/ethereumapis\/eth/g' "$line"
    47      done
    48  
    49  find ./eth -name '*.go' -print0 |
    50      while IFS= read -r -d '' line; do
    51          sed -i 's/proto\/eth/eth/g' "$line"
    52      done
    53  
    54  find ./eth -name '*.go' -print0 |
    55      while IFS= read -r -d '' line; do
    56          sed -i 's/proto_eth/eth/g' "$line"
    57      done
    58  
    59  find ./eth -name '*.proto' -print0 |
    60      while IFS= read -r -d '' line; do
    61          sed -i 's/"proto\/eth/"eth/g' "$line"
    62      done
    63  
    64  find ./eth -name '*.proto' -print0 |
    65      while IFS= read -r -d '' line; do
    66          sed -i 's/prysmaticlabs\/prysm\/proto\/eth/prysmaticlabs\/ethereumapis\/eth/g' "$line"
    67      done
    68  
    69  if git diff-index --quiet HEAD --; then
    70     echo "nothing to push, exiting early"
    71     exit 0
    72  else
    73     echo "changes detected, commiting and pushing to ethereumapis"
    74  fi
    75  
    76  # Push to the mirror repository
    77  git add --all
    78  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"
    79  git remote set-url origin https://prylabs:"$GITHUB_SECRET_ACCESS_TOKEN"@github.com/prysmaticlabs/ethereumapis.git
    80  git push origin master