publish.sh 986 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/bash
  2. set -e
  3. PACKAGE_DIR="."
  4. echo "building package to generate type files"
  5. OUT_DIR=$(cargo build --message-format=json | jq -r 'select(.reason == "build-script-executed") | .out_dir' | grep "pyth-lazer-publisher-sdk")
  6. echo "using output directory: ${OUT_DIR}"
  7. echo "copying files from protobuf output to package directory"
  8. cp -r "${OUT_DIR}/protobuf" "${PACKAGE_DIR}/src/"
  9. echo "deleting build.rs file"
  10. rm -f "${PACKAGE_DIR}/build.rs"
  11. echo "updating lib.rs to export local protobuf files"
  12. python3 -c "
  13. import re
  14. def replace_mod_protobuf(file_path):
  15. with open(file_path, 'r') as f:
  16. content = f.read()
  17. pattern = re.compile(r'mod\s+protobuf\s*\{.*?\}', re.DOTALL)
  18. replacement = 'mod protobuf;'
  19. new_content = pattern.sub(replacement, content)
  20. with open(file_path, 'w') as f:
  21. f.write(new_content)
  22. replace_mod_protobuf('${PACKAGE_DIR}/src/lib.rs')
  23. "
  24. echo "publishing package"
  25. cargo publish --token ${CARGO_REGISTRY_TOKEN} --allow-dirty