difftreelog
ci type package generation script
in: master
8 files changed
tests/scripts/functions.shdiffbeforeafterboth--- /dev/null
+++ b/tests/scripts/functions.sh
@@ -0,0 +1,4 @@
+
+function do_rpc {
+ curl -s --header "Content-Type: application/json" -XPOST --data "{\"id\":1,\"jsonrpc\":\"2.0\",\"method\":\"$1\",\"params\":[$2]}" $RPC_URL
+}
tests/scripts/generate_types_package.shdiffbeforeafterboth1#!/usr/bin/env bash23set -eu45DIR=realpathdirname"$0"6TEMPLATE=$DIR/types_template7GIT_REPO=git@github.com:UniqueNetwork/unique-types-js.git89. $DIR/functions.sh1011usage() {12 echo "Usage: [RPC_URL=http://localhost:9933] $0 [--rc|--release|--sapphire] [--force] [--rpc-url=http://localhost:9933]" 1>&213 exit 114}1516rc=17sapphire=18release=19force=2021for i in "$@"; do22case $i in23 --rc)24 rc=125 if test "$release" -o "$sapphire"; then usage; fi26 ;;27 --sapphire)28 sapphire=129 if test "$rc" -o "$release"; then usage; fi30 ;;31 --release)32 release=133 if test "$rc" -o "$sapphire"; then usage; fi34 ;;35 --force)36 force=137 ;;38 --rpc-url=*)39 RPC_URL=i40 ;;41 *)42 usage43 ;;44esac45done4647if test \( ! \( "$rc" -o "$release" -o "$sapphire" \) \) -o \( "RPC_URL" = "" \); then48 usage49elif test "$rc"; then50 echo "Rc build"51else52 echo "Release build"53fi5455cd $DIR/..56yarn polkadot-types5758version=do_rpc""59spec_version=echo$version|jq-r60spec_name=echo$version|jq-r61echo "Spec version: $spec_version, name: $spec_name"6263case $spec_name in64 opal)65 package_name=@unique-nft/opal-testnet-types66 repo_branch=opal-testnet67 repo_tag=$repo_branch68 ;;69 quartz)70 package_name=@unique-nft/quartz-mainnet-types71 repo_branch=quartz-mainnet72 repo_tag=$repo_branch73 ;;74 unique)75 package_name=@unique-nft/unique-mainnet-types76 repo_branch=master77 repo_tag=unique-mainnet78 ;;79 *)80 echo "unknown spec name: $spec_name"81 exit 182 ;;83esac8485if test "$rc" = 1; then86 if "$spec_name" != opal; then87 echo "rc types can only be based on opal spec"88 exit 189 fi90 package_name=@unique-nft/rc-types91 repo_branch=rc92 repo_tag=$repo_branch93fi94if test "$sapphire" = 1; then95 if "$spec_name" != opal; then96 echo "sapphire types can only be based on opal spec"97 exit 198 fi99 package_name=@unique-nft/sapphire-mainnet-types100 repo_branch=sapphire-mainnet101 repo_tag=$repo_branch102fi103104package_version=spec_version.echospec_version|sed's/^0*//'.105last_patch=NEVER106for tag in git-t--refs$GIT_REPO|cut-f|sort-r; do107 tag_prefix=refs/tags/$repo_tag-v$package_version108 if [[ $tag == $tag_prefix* ]]; then109 last_patch=tag110 break;111 fi112done113echo "Package version: package_versionX, name: $package_name"114echo "Last published: $package_version$last_patch"115116if test "$last_patch" = "NEVER"; then117 new_package_version=package_version0118else119 new_package_version=package_version$((last_patch+1))120fi121package_version=package_version$last_patch122echo "New package version: $new_package_version"123124pjsapi_ver=^cat$DIR|jq-r'.dependencies."@polkadot/api"'|sed-e"s/^\^//"125tsnode_ver=^cat$DIR|jq-r'.devDependencies."ts-node"'|sed-e"s/^\^//"126ts_ver=^cat$DIR|jq-r'.devDependencies."typescript"'|sed-e"s/^\^//"127128gen=mktemp-d129pushd $gen130git clone $GIT_REPO -b $repo_branch --depth 1 .131if test "$last_patch" != "NEVER"; then132 git reset --hard $repo_tag-v$package_version133fi134git rm -r "*"135popd136137# Using old package_version here, becaue we first check if138# there is any difference between generated and already uplaoded types139cat $TEMPLATE/package.json \140| jq '.private = false' - \141| jq '.name = "'$package_name'"' - \142| jq '.version = "'$package_version'"' - \143| jq '.peerDependencies."@polkadot/api" = "'$pjsapi_ver'"' - \144| jq '.peerDependencies."@polkadot/types" = "'$pjsapi_ver'"' - \145| jq '.devDependencies."@polkadot/api" = "'$pjsapi_ver'"' - \146| jq '.devDependencies."@polkadot/types" = "'$pjsapi_ver'"' - \147| jq '.devDependencies."ts-node" = "'$tsnode_ver'"' - \148| jq '.devDependencies."typescript" = "'$ts_ver'"' - \149> $gen/package.json150for file in .gitignore .npmignore README.md tsconfig.json; do151 cp $TEMPLATE/$file $gen/152done153package_name_replacement=printf'%s\n'"$package_name"|sed-e's/[\/&]/\\&/g'154sed -i 's/PKGNAME/'$package_name_replacement'/' $gen/README.md155156rsync -ar --exclude .gitignore src/interfaces/ $gen157for file in $gen/augment-* $gen/**/types.ts $gen/registry.ts; do158 sed -i '1s;^;//@ts-nocheck\n;' $file159done160161pushd $gen162git add .163popd164165pushd $gen166if git diff --quiet HEAD && test ! "$force"; then167 echo "no changes detected"168 exit 0169fi170popd171172mv $gen/package.json $gen/package.old.json173cat $gen/package.old.json \174| jq '.version = "'$new_package_version'"' - \175> $gen/package.json176rm $gen/package.old.json177pushd $gen178git add package.json179popd180181echo "package.json contents:"182cat $gen/package.json183echo "overall diff:"184pushd $gen185git status186git diff HEAD || true187popd188189# This check is only active if running in interactive terminal190if [ -t 0 ]; then191 read -p "Is everything ok at $gen? " -n 1 -r192 echo193 if [[ ! $REPLY =~ ^[Yy]$ ]]; then194 echo "Aborting!"195 exit 1196 fi197fi198199pushd $gen200yarn201yarn prepublish202git commit -m "chore: upgrade types to v$new_package_version"203git tag --force $repo_tag-v$new_package_version204git push --tags --force -u origin HEAD205#yarn publish206popdtests/scripts/types_template/.gitignorediffbeforeafterboth--- /dev/null
+++ b/tests/scripts/types_template/.gitignore
@@ -0,0 +1,5 @@
+*.js
+*.map
+*.d.ts
+/node_modules
+metadata.json
tests/scripts/types_template/.npmignorediffbeforeafterboth--- /dev/null
+++ b/tests/scripts/types_template/.npmignore
@@ -0,0 +1 @@
+/src
tests/scripts/types_template/README.mddiffbeforeafterboth--- /dev/null
+++ b/tests/scripts/types_template/README.md
@@ -0,0 +1,31 @@
+# PKGNAME
+
+Unique network api types
+
+Do not edit by hand, those types are generated automatically, and definitions are located in chain repo
+
+## Using types
+
+Install library:
+
+```bash
+yarn add --dev PKGNAME
+```
+
+Replace polkadot.js types with our chain types adding corresponding path override to the tsconfig `compilerOptions.paths` section:
+
+```json
+// in tsconfig.json
+{
+ "compilerOptions": {
+ "paths": {
+ "@polkadot/types/lookup": ["node_modules/PKGNAME/types-lookup"]
+ }
+ }
+}
+```
+
+Since polkadot v7 api augmentations not loaded by default, in every file, where you need to access `api.tx`, `api.query`, `api.rpc`, etc; you should explicitly import corresponding augmentation before any other `polkadot.js` related import:
+```
+import 'PKGNAME/augment-api';
+```
tests/scripts/types_template/package.jsondiffbeforeafterboth--- /dev/null
+++ b/tests/scripts/types_template/package.json
@@ -0,0 +1,22 @@
+{
+ "name": "TODO",
+ "private": true,
+ "version": "TODO",
+ "main": "index.js",
+ "repository": "git@github.com:UniqueNetwork/unique-types-js.git",
+ "homepage": "https://unique.network/",
+ "license": "MIT",
+ "scripts": {
+ "prepublish": "tsc -d"
+ },
+ "peerDependencies": {
+ "@polkadot/api": "TODO",
+ "@polkadot/types": "TODO"
+ },
+ "devDependencies": {
+ "@polkadot/api": "TODO",
+ "@polkadot/types": "TODO",
+ "ts-node": "TODO",
+ "typescript": "TODO"
+ }
+}
tests/scripts/types_template/tsconfig.jsondiffbeforeafterboth--- /dev/null
+++ b/tests/scripts/types_template/tsconfig.json
@@ -0,0 +1,28 @@
+{
+ "exclude": [
+ "node_modules",
+ "node_modules/**/*",
+ "../node_modules/**/*",
+ "**/node_modules/**/*"
+ ],
+ "compilerOptions": {
+ "target": "ES2020",
+ "moduleResolution": "node",
+ "esModuleInterop": true,
+ "resolveJsonModule": true,
+ "module": "commonjs",
+ "sourceMap": true,
+ "outDir": ".",
+ "rootDir": ".",
+ "strict": true,
+ "paths": {
+ },
+ "skipLibCheck": true,
+ },
+ "include": [
+ "**/*",
+ ],
+ "lib": [
+ "es2017"
+ ],
+}
tests/scripts/wait_for_first_block.shdiffbeforeafterboth--- a/tests/scripts/wait_for_first_block.sh
+++ b/tests/scripts/wait_for_first_block.sh
@@ -1,15 +1,11 @@
#!/usr/bin/env bash
-function do_rpc {
- curl -s --header "Content-Type: application/json" -XPOST --data "{\"id\":1,\"jsonrpc\":\"2.0\",\"method\":\"$1\",\"params\":[$2]}" $RPC_URL
-}
+DIR=$(dirname "$0")
+
+. $DIR/functions.sh
function is_started {
- block_hash_rpc=$(do_rpc chain_getFinalizedHead)
- echo Rpc response = $block_hash_rpc
- block_hash=$(echo $block_hash_rpc | jq -r .result)
- echo Head = $block_hash
- block_id_hex=$(do_rpc chain_getHeader "\"$block_hash\"" | jq -r .result.number)
+ block_id_hex=$(do_rpc chain_getHeader | jq -r .result.number)
block_id=$((${block_id_hex}))
echo Id = $block_id
if (( $block_id > 1 )); then