From 777803ba391e2da07453278c49c4793d6233d053 Mon Sep 17 00:00:00 2001 From: zaidarain1 Date: Fri, 2 Aug 2024 14:26:04 +1000 Subject: [PATCH] feat: [DX-3058] Build examples and test apps against built local SDK (#2053) --- .github/actions/setup-examples/action.yaml | 10 ++ .github/actions/setup-tests/action.yaml | 9 ++ .../build-lint-and-test-examples.yaml | 53 -------- .github/workflows/pr.yaml | 112 +++++++++++----- .nxignore | 3 +- nx.json | 8 -- package.json | 9 +- sdk/package.json | 2 +- tests/func-tests/imx/package.json | 2 +- tests/func-tests/zkevm/package.json | 2 +- tests/smoke/esm/.gitignore | 2 - tests/smoke/esm/index.mjs | 5 - tests/smoke/esm/package.json | 12 -- yarn.lock | 120 ++++++++---------- 14 files changed, 163 insertions(+), 186 deletions(-) create mode 100644 .github/actions/setup-examples/action.yaml create mode 100644 .github/actions/setup-tests/action.yaml delete mode 100644 .github/workflows/build-lint-and-test-examples.yaml delete mode 100644 tests/smoke/esm/.gitignore delete mode 100644 tests/smoke/esm/index.mjs delete mode 100644 tests/smoke/esm/package.json diff --git a/.github/actions/setup-examples/action.yaml b/.github/actions/setup-examples/action.yaml new file mode 100644 index 0000000000..d4e02c3c1f --- /dev/null +++ b/.github/actions/setup-examples/action.yaml @@ -0,0 +1,10 @@ + +name: "Examples setup" +description: "Do necessary setup for examples" + +runs: + using: "composite" + steps: + - name: Prepare examples + shell: bash + run: yarn prepare:examples diff --git a/.github/actions/setup-tests/action.yaml b/.github/actions/setup-tests/action.yaml new file mode 100644 index 0000000000..78876d1c75 --- /dev/null +++ b/.github/actions/setup-tests/action.yaml @@ -0,0 +1,9 @@ +name: "Tests setup" +description: "Do necessary setup for tests" + +runs: + using: "composite" + steps: + - name: Prepare tests + shell: bash + run: yarn prepare:tests diff --git a/.github/workflows/build-lint-and-test-examples.yaml b/.github/workflows/build-lint-and-test-examples.yaml deleted file mode 100644 index b9917a7c15..0000000000 --- a/.github/workflows/build-lint-and-test-examples.yaml +++ /dev/null @@ -1,53 +0,0 @@ -name: Build lint and test all examples - -on: - pull_request: - branches: [main] - merge_group: - branches: [main] - -jobs: - build: - name: Build - runs-on: ubuntu-latest-4-cores - env: - NODE_OPTIONS: --max-old-space-size=14366 - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: setup - uses: ./.github/actions/setup - - - name: Build examples - run: yarn build:examples - - lint: - name: Lint - runs-on: ubuntu-latest-4-cores - env: - NODE_OPTIONS: --max-old-space-size=14366 - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: setup - uses: ./.github/actions/setup - - - name: Lint examples - run: yarn lint:examples - - test: - name: Test - runs-on: ubuntu-latest-4-cores - env: - NODE_OPTIONS: --max-old-space-size=14366 - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: setup - uses: ./.github/actions/setup - - - name: Test examples - run: yarn test:examples diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index f53693848f..6c6f37c9ad 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -55,8 +55,8 @@ jobs: echo "Node.js engine version has not changed" fi - build: - name: Build + build-sdk: + name: Build SDK runs-on: ubuntu-latest-8-cores steps: - name: Checkout code @@ -69,11 +69,10 @@ jobs: - name: Build run: yarn nx affected --target=build --parallel=5 --exclude=@imtbl/checkout-widgets-sample-app - typecheck: - name: Typecheck + typecheck-sdk: + name: Typecheck SDK runs-on: ubuntu-latest-4-cores - needs: - - build + needs: build-sdk steps: - name: Checkout code uses: actions/checkout@v4 @@ -86,11 +85,10 @@ jobs: - name: Typecheck run: yarn typecheck - test: - name: Test + test-sdk: + name: Test SDK runs-on: ubuntu-latest-8-cores - needs: - - build + needs: build-sdk env: NODE_OPTIONS: --max-old-space-size=14366 steps: @@ -111,8 +109,8 @@ jobs: name: coverages path: ./packages/**/coverage/* - lint: - name: Lint + lint-sdk: + name: Lint SDK runs-on: ubuntu-latest-4-cores steps: - name: Checkout code @@ -126,11 +124,68 @@ jobs: - name: Lint run: yarn lint + build-examples: + name: Build Examples + needs: build-sdk + runs-on: ubuntu-latest-4-cores + env: + NODE_OPTIONS: --max-old-space-size=14366 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: setup + uses: ./.github/actions/setup + + - name: Setup examples + uses: ./.github/actions/setup-examples + + - name: Build examples + run: yarn build:examples + + lint-examples: + name: Lint Examples + needs: build-sdk + runs-on: ubuntu-latest-4-cores + env: + NODE_OPTIONS: --max-old-space-size=14366 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: setup + uses: ./.github/actions/setup + + - name: Setup examples + uses: ./.github/actions/setup-examples + + - name: Lint examples + run: yarn lint:examples + + test-examples: + name: Test Examples + needs: build-sdk + runs-on: ubuntu-latest-4-cores + env: + NODE_OPTIONS: --max-old-space-size=14366 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: setup + uses: ./.github/actions/setup + + - name: Setup examples + uses: ./.github/actions/setup-examples + + - name: Test examples + run: yarn test:examples + + func-test-imx: name: imx func tests runs-on: ubuntu-latest-4-cores - needs: - - build + needs: build-sdk env: NETWORK: sepolia TEST_ALCHEMY_API_KEY: ${{ secrets.TEST_ALCHEMY_API_KEY }} @@ -154,14 +209,16 @@ jobs: - name: setup uses: ./.github/actions/setup + - name: Setup tests + uses: ./.github/actions/setup-tests + - name: test - run: yarn nx run func-tests-imx:func-test:ci + run: yarn workspace @tests/func-tests-imx func-test:ci func-test-zkevm: name: zkevm func tests runs-on: ubuntu-latest-4-cores - needs: - - build + needs: build-sdk env: ZKEVM_ORDERBOOK_BANKER: ${{ secrets.ZKEVM_ORDERBOOK_BANKER }} ZKEVM_ORDERBOOK_ERC721: "0xBE8B131f39825282Ace9eFf99C0Bb14972417b49" @@ -177,25 +234,12 @@ jobs: with: ref: ${{ github.event.pull_request.head.ref }} fetch-depth: 0 - - name: setup - uses: ./.github/actions/setup - - - name: test - run: yarn nx run func-tests-zkevm:func-test:ci - smoke-test: - name: smoke test - runs-on: ubuntu-latest-4-cores - needs: - - build - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - ref: ${{ github.event.pull_request.head.ref }} - fetch-depth: 0 - name: setup uses: ./.github/actions/setup + - name: Setup tests + uses: ./.github/actions/setup-tests + - name: test - run: yarn nx run esm-sdk-test:smoke-test + run: yarn workspace @tests/func-tests-zkevm func-test:ci diff --git a/.nxignore b/.nxignore index b7265688ad..74b4a4024b 100644 --- a/.nxignore +++ b/.nxignore @@ -1 +1,2 @@ -examples \ No newline at end of file +examples +tests \ No newline at end of file diff --git a/nx.json b/nx.json index 8c98db92a2..0de4e46318 100644 --- a/nx.json +++ b/nx.json @@ -23,14 +23,6 @@ } } }, - "smoke-test": { - "cache": true, - "dependsOn": ["^build"] - }, - "func-test:ci": { - "cache": true, - "dependsOn": ["^build"] - }, "build": { "dependsOn": ["^build"], "outputs": ["{projectRoot}/dist"], diff --git a/package.json b/package.json index 56ad65953a..032f5f4a56 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,8 @@ "lint:examples": "yarn workspaces foreach -Apt --include='@examples/**' run lint", "nx": "nx", "postinstall": "husky install; ./.husky/install_gitleaks.sh", + "prepare:examples": "yarn build:onlysdk && yarn yalc:sdk:publish && yarn workspaces foreach -Apt --include='@examples/**' exec yarn dlx yalc add @imtbl/sdk && yarn install --no-immutable", + "prepare:tests": "yarn build:onlysdk && yarn yalc:sdk:publish && yarn workspaces foreach -Apt --include='@tests/**' exec yarn dlx yalc add @imtbl/sdk && yarn install --no-immutable", "release": "release-it", "scan:secrets": "./.husky/run_gitleaks.sh", "syncpack:check": "yarn syncpack list-mismatches", @@ -65,7 +67,8 @@ "test": "nx affected -t test --parallel=5", "test:examples": "yarn workspaces foreach -Apt --include='@examples/**' run test", "test:vpn": "RUN_VPN_TESTS=1 wsrun --exclude-missing -e test", - "typecheck": "nx affected -t typecheck --parallel=5" + "typecheck": "nx affected -t typecheck --parallel=5", + "yalc:sdk:publish": "yarn workspace @imtbl/sdk exec yarn dlx yalc publish" }, "workspaces": { "packages": [ @@ -97,9 +100,7 @@ "packages/game-bridge", "packages/webhook/sdk", "packages/minting-backend/sdk", - "tests/smoke/esm", - "tests/func-tests/imx", - "tests/func-tests/zkevm", + "tests/**", "examples/passport/**" ], "nohoist": [ diff --git a/sdk/package.json b/sdk/package.json index 9b85ba03e9..cc6b931596 100644 --- a/sdk/package.json +++ b/sdk/package.json @@ -168,4 +168,4 @@ }, "type": "module", "types": "./dist/index.d.ts" -} +} \ No newline at end of file diff --git a/tests/func-tests/imx/package.json b/tests/func-tests/imx/package.json index 2316709719..1a0cacd786 100644 --- a/tests/func-tests/imx/package.json +++ b/tests/func-tests/imx/package.json @@ -1,5 +1,5 @@ { - "name": "func-tests-imx", + "name": "@tests/func-tests-imx", "dependencies": { "@ethersproject/providers": "^5.7.2", "@ethersproject/units": "^5.7.0", diff --git a/tests/func-tests/zkevm/package.json b/tests/func-tests/zkevm/package.json index a19eb49f3d..74271bf5aa 100644 --- a/tests/func-tests/zkevm/package.json +++ b/tests/func-tests/zkevm/package.json @@ -1,5 +1,5 @@ { - "name": "func-tests-zkevm", + "name": "@tests/func-tests-zkevm", "dependencies": { "@imtbl/contracts": "2.2.6", "@imtbl/sdk": "0.0.0", diff --git a/tests/smoke/esm/.gitignore b/tests/smoke/esm/.gitignore deleted file mode 100644 index 44b274308a..0000000000 --- a/tests/smoke/esm/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -node_modules -.yarn diff --git a/tests/smoke/esm/index.mjs b/tests/smoke/esm/index.mjs deleted file mode 100644 index 104a2378d0..0000000000 --- a/tests/smoke/esm/index.mjs +++ /dev/null @@ -1,5 +0,0 @@ -import { config } from '@imtbl/sdk'; - -console.log('loaded SDK config'); - -process.exit(0); diff --git a/tests/smoke/esm/package.json b/tests/smoke/esm/package.json deleted file mode 100644 index 2a25ce60e3..0000000000 --- a/tests/smoke/esm/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "esm-sdk-test", - "description": "Node ESM smoke test", - "version": "1.0.0", - "dependencies": { - "@imtbl/sdk": "0.0.0" - }, - "main": "index.js", - "scripts": { - "smoke-test": "node index.mjs" - } -} diff --git a/yarn.lock b/yarn.lock index 7575a0ae3a..6059e10f7e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11915,6 +11915,60 @@ __metadata: languageName: node linkType: hard +"@tests/func-tests-imx@workspace:tests/func-tests/imx": + version: 0.0.0-use.local + resolution: "@tests/func-tests-imx@workspace:tests/func-tests/imx" + dependencies: + "@ethersproject/providers": ^5.7.2 + "@ethersproject/units": ^5.7.0 + "@ethersproject/wallet": ^5.7.0 + "@imtbl/sdk": 0.0.0 + "@swc/jest": ^0.2.29 + "@types/node": ^20.10.1 + dotenv: ^16.3.1 + husky: ^8.0.0 + jest: ^29.7.0 + jest-cucumber: ^3.0.1 + pinst: ^3.0.0 + ts-jest: ^29.1.1 + ts-node: ^10.9.1 + typescript: ^5.5.4 + languageName: unknown + linkType: soft + +"@tests/func-tests-zkevm@workspace:tests/func-tests/zkevm": + version: 0.0.0-use.local + resolution: "@tests/func-tests-zkevm@workspace:tests/func-tests/zkevm" + dependencies: + "@imtbl/contracts": 2.2.6 + "@imtbl/sdk": 0.0.0 + "@nomicfoundation/hardhat-chai-matchers": ^1.0.0 + "@nomicfoundation/hardhat-toolbox": ^2.0.2 + "@nomicfoundation/hardhat-verify": ^2.0.0 + "@nomiclabs/hardhat-ethers": ^2.0.0 + "@nomiclabs/hardhat-etherscan": ^3.0.0 + "@openzeppelin/contracts": ^4.9.3 + "@swc/jest": ^0.2.29 + "@typechain/ethers-v6": ^0.5.0 + "@typechain/hardhat": ^9.0.0 + "@types/chai": ^4.2.0 + "@types/node": ^20.10.1 + chai: ^4.2.0 + dotenv: ^16.3.1 + ethers: ^5.7.0 + hardhat: ^2.19.4 + hardhat-gas-reporter: ^1.0.8 + husky: ^8.0.0 + jest: ^29.7.0 + jest-cucumber: ^3.0.1 + pinst: ^3.0.0 + solidity-coverage: ^0.8.1 + ts-jest: ^29.1.1 + ts-node: ^10.9.2 + typescript: ^5.5.4 + languageName: unknown + linkType: soft + "@tokenizer/token@npm:^0.3.0": version: 0.3.0 resolution: "@tokenizer/token@npm:0.3.0" @@ -21717,14 +21771,6 @@ __metadata: languageName: node linkType: hard -"esm-sdk-test@workspace:tests/smoke/esm": - version: 0.0.0-use.local - resolution: "esm-sdk-test@workspace:tests/smoke/esm" - dependencies: - "@imtbl/sdk": 0.0.0 - languageName: unknown - linkType: soft - "espree@npm:^9.6.0, espree@npm:^9.6.1": version: 9.6.1 resolution: "espree@npm:9.6.1" @@ -23333,60 +23379,6 @@ __metadata: languageName: node linkType: hard -"func-tests-imx@workspace:tests/func-tests/imx": - version: 0.0.0-use.local - resolution: "func-tests-imx@workspace:tests/func-tests/imx" - dependencies: - "@ethersproject/providers": ^5.7.2 - "@ethersproject/units": ^5.7.0 - "@ethersproject/wallet": ^5.7.0 - "@imtbl/sdk": 0.0.0 - "@swc/jest": ^0.2.29 - "@types/node": ^20.10.1 - dotenv: ^16.3.1 - husky: ^8.0.0 - jest: ^29.7.0 - jest-cucumber: ^3.0.1 - pinst: ^3.0.0 - ts-jest: ^29.1.1 - ts-node: ^10.9.1 - typescript: ^5.5.4 - languageName: unknown - linkType: soft - -"func-tests-zkevm@workspace:tests/func-tests/zkevm": - version: 0.0.0-use.local - resolution: "func-tests-zkevm@workspace:tests/func-tests/zkevm" - dependencies: - "@imtbl/contracts": 2.2.6 - "@imtbl/sdk": 0.0.0 - "@nomicfoundation/hardhat-chai-matchers": ^1.0.0 - "@nomicfoundation/hardhat-toolbox": ^2.0.2 - "@nomicfoundation/hardhat-verify": ^2.0.0 - "@nomiclabs/hardhat-ethers": ^2.0.0 - "@nomiclabs/hardhat-etherscan": ^3.0.0 - "@openzeppelin/contracts": ^4.9.3 - "@swc/jest": ^0.2.29 - "@typechain/ethers-v6": ^0.5.0 - "@typechain/hardhat": ^9.0.0 - "@types/chai": ^4.2.0 - "@types/node": ^20.10.1 - chai: ^4.2.0 - dotenv: ^16.3.1 - ethers: ^5.7.0 - hardhat: ^2.19.4 - hardhat-gas-reporter: ^1.0.8 - husky: ^8.0.0 - jest: ^29.7.0 - jest-cucumber: ^3.0.1 - pinst: ^3.0.0 - solidity-coverage: ^0.8.1 - ts-jest: ^29.1.1 - ts-node: ^10.9.2 - typescript: ^5.5.4 - languageName: unknown - linkType: soft - "function-bind@npm:^1.1.1": version: 1.1.1 resolution: "function-bind@npm:1.1.1" @@ -35887,7 +35879,7 @@ __metadata: resolution: "seaport-core@https://github.com/immutable/seaport-core.git#commit=0633350ec34f21fcede657ff812f11cf7d19144e" dependencies: seaport-types: ^0.0.1 - checksum: d8adba0d54106c6fe9370f0775fadef2198e5eab440b36919d1f917705ce2f0a7028e4da021b6df049aa3ca35d7e673a28b78a731130f0ff9fdf7a8bd32e3b94 + checksum: 392bce86bbfc4f7c00b65575b238825f4c696bddf5af08be7aa496862e63879375387fd4400f6e900ffee08d65c1f75cf3adad9c6c41ddcf7a3b0389cd73c3c7 languageName: node linkType: hard @@ -35931,7 +35923,7 @@ __metadata: seaport-sol: ^1.5.0 seaport-types: ^0.0.1 solady: ^0.0.84 - checksum: a77e141e4ab5d2c4bb190a38fbb6cda3011fdf5f350b250fbeb4d82ae81cf917a966a2dcb8d9e4fd1bed29e5510ede9b15941b0ac77aeb4272dab94c9f51e7ff + checksum: f31a7443a50fa1c35ec03ea031743d1d10896653ae443fa15ab8e6f5b4a2ca43f6743d523ae4e1f14df867451e5b2b2130b0bfa58a1085b0bcae3fceb8dfdc9b languageName: node linkType: hard