diff --git a/.eslintrc.js b/.eslintrc.js index ad00ee98a..1c89d0f81 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -72,8 +72,7 @@ module.exports = { '**/dist/**/', '**/lib/**/', 'deps/**/*', - '**/nodejs/grpc-api/*', - '**/common/src/grpc-api/*', + '**/src/grpc-api/*', 'typedoc/**', ], settings: { diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index 4296dddb7..0e563bc78 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -70,7 +70,6 @@ jobs: packages/nodejs/lib packages/web/lib packages/rust-bindings/lib/**/index* - packages/nodejs/grpc-api packages/*/package.json packages/*/README.md diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 5d8dfdbcd..f0b55ae68 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -1,262 +1,337 @@ name: Build, lint and typecheck examples on: - # Triggers the workflow on push or pull request events but only for the main branch - push: - branches: [ main, release** ] - pull_request: - branches: [ main, release** ] - # Don't run on draft PR's, see: https://github.com/orgs/community/discussions/25722#discussioncomment-3248917 - types: [ opened, synchronize, reopened, ready_for_review ] - # Allows us to run the workflow manually from the Actions tab - workflow_dispatch: + # Triggers the workflow on push or pull request events but only for the main branch + push: + branches: [ main, release** ] + pull_request: + branches: [ main, release** ] + # Don't run on draft PR's, see: https://github.com/orgs/community/discussions/25722#discussioncomment-3248917 + types: [ opened, synchronize, reopened, ready_for_review ] + # Allows us to run the workflow manually from the Actions tab + workflow_dispatch: env: - NODE_VERSION: 18.16.0 - RUST_VERSION: 1.65 - RUST_FMT: nightly-2023-04-01-x86_64-unknown-linux-gnu + NODE_VERSION: 18.16.0 + RUST_VERSION: 1.65 + RUST_FMT: nightly-2023-04-01-x86_64-unknown-linux-gnu jobs: - build: - if: github.event.pull_request.draft == false - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v3 - with: - submodules: "recursive" - - - uses: actions/setup-node@v3 - with: - node-version: ${{ env.NODE_VERSION }} - cache: yarn - - - name: Cache GRPC - id: cache-grpc - uses: actions/cache@v3 - with: - path: | - ./packages/common/grpc-api - ./packages/nodejs/grpc-api - key: ${{ runner.os }}-grpc-${{ hashFiles('deps/concordium-base/concordium-grpc-api') }} - - - name: Cache WebPack - uses: actions/cache@v3 - with: - path: ./packages/web/.webpack-cache - # These two lines ensure that a fresh cache is generated after each run - key: ${{ runner.os }}-webpack-${{ github.run_id }} - restore-keys: ${{ runner.os }}-webpack - - - name: Get dependencies - run: yarn install --immutable - - - name: Install rust - run: rustup default ${{ env.RUST_VERSION }} - - - uses: Swatinem/rust-cache@v2 - with: - workspaces: | - packages/rust-bindings - deps/concordium-deps - - - name: Get wasm-pack - uses: jetli/wasm-pack-action@v0.4.0 - with: - version: 'latest' - - - name: Build GRPC bindings - if: steps.cache-grpc.outputs.cache-hit != 'true' - run: | - mkdir -p packages/common/grpc-api - mkdir -p packages/nodejs/grpc-api - yarn workspace @concordium/common-sdk generate - yarn workspace @concordium/node-sdk generate - - - name: Build - run: yarn build:rust-bindings && yarn build:dev - - - name: Store build-debug - uses: ./.github/actions/upload-artifact - with: - name: build-debug - path: | - ./node_modules/@concordium - ./packages/rust-bindings/lib - ./packages/common/lib - ./packages/nodejs/lib - ./packages/*/grpc-api - ./packages/ccd-js-gen/lib - - typecheck-examples: - runs-on: ubuntu-22.04 - needs: build - steps: - - uses: actions/checkout@v3 - - - uses: actions/setup-node@v3 - with: - node-version: ${{ env.NODE_VERSION }} - cache: yarn - - - name: Get build-debug - uses: ./.github/actions/download-artifact - with: - name: build-debug - - - name: Get dependencies - run: yarn install --immutable - - - name: Typecheck examples - run: yarn workspace @concordium/examples typecheck - - common-tests: - runs-on: ubuntu-22.04 - needs: build - defaults: - run: - working-directory: packages/common - steps: - - uses: actions/checkout@v3 - - - uses: actions/setup-node@v3 - with: - node-version: ${{ env.NODE_VERSION }} - cache: yarn - - - name: Get build-debug - uses: ./.github/actions/download-artifact - with: - name: build-debug - - - name: Get dependencies - run: yarn install --immutable - - - name: Run Tests - run: yarn test - - typedoc: - runs-on: ubuntu-22.04 - needs: build - steps: - - uses: actions/checkout@v3 - - - uses: actions/setup-node@v3 - with: - node-version: ${{ env.NODE_VERSION }} - cache: yarn - - - name: Get build-debug - uses: ./.github/actions/download-artifact - with: - name: build-debug - - - name: Get dependencies - run: yarn install --immutable - - - name: Build typedoc - run: yarn typedoc - - lint: - runs-on: ubuntu-22.04 - needs: build - if: github.event.pull_request.draft == false - steps: - - uses: actions/checkout@v3 - - - uses: actions/setup-node@v3 - with: - node-version: ${{ env.NODE_VERSION }} - cache: yarn - - - name: Get build-debug - uses: ./.github/actions/download-artifact - with: - name: build-debug - - - name: Install dependencies - run: yarn install --immutable - - - name: Lint - run: yarn lint - - markdown-lint: - runs-on: ubuntu-22.04 - if: github.event.pull_request.draft == false - steps: - - uses: actions/checkout@v3 - - - uses: actions/setup-node@v3 - with: - node-version: ${{ env.NODE_VERSION }} - cache: yarn - - - name: Install dependencies - run: yarn install --immutable - - - name: Lint markdown - run: yarn markdown:lint - - markdown-linkcheck: - runs-on: ubuntu-22.04 - if: github.event.pull_request.draft == false - steps: - - uses: actions/checkout@v3 - - - uses: actions/setup-node@v3 - with: - node-version: ${{ env.NODE_VERSION }} - cache: yarn - - - name: Install dependencies - run: yarn install --immutable - - - name: Lint markdown - run: yarn markdown:linkcheck - - rust_lint_fmt: - runs-on: ubuntu-22.04 - if: github.event.pull_request.draft == false - defaults: - run: - working-directory: packages/rust-bindings - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - submodules: "recursive" - - - name: Install formatter - run: | - rustup default ${{ env.RUST_FMT }} - rustup component add rustfmt - - - name: Format - run: cargo fmt -- --color=always --check - - rust_lint_clippy: - runs-on: ubuntu-22.04 - needs: rust_lint_fmt - if: github.event.pull_request.draft == false - defaults: - run: - working-directory: packages/rust-bindings - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - submodules: "recursive" - - - name: Install clippy - run: | - rustup default ${{ env.RUST_VERSION }} - rustup component add clippy - - - uses: Swatinem/rust-cache@v2 - with: - workspaces: | - packages/rust-bindings - deps/concordium-deps - - - name: Run clippy - run: cargo clippy --color=always --tests --benches -- -Dclippy::all + build: + if: github.event.pull_request.draft == false + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + with: + submodules: "recursive" + + - uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODE_VERSION }} + cache: yarn + + - name: Cache GRPC + id: cache-grpc + uses: actions/cache@v3 + with: + path: | + ./packages/common/src/grpc-api + ./packages/nodejs/src/grpc-api + key: ${{ runner.os }}-grpc-${{ hashFiles('deps/concordium-base/concordium-grpc-api') }} + restore-key: ${{ runner.os }}-grpc + + - name: Cache dependencies + id: yarn-cache + uses: actions/cache@v3 + with: + path: node_modules + key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }} + + - name: Cache WebPack + uses: actions/cache@v3 + with: + path: ./packages/web/.webpack-cache + # These two lines ensure that a fresh cache is generated after each run + key: ${{ runner.os }}-webpack-${{ github.run_id }} + restore-keys: ${{ runner.os }}-webpack + + - name: Get dependencies + run: yarn install --immutable + + - name: Install rust + run: rustup default ${{ env.RUST_VERSION }} + + - uses: Swatinem/rust-cache@v2 + with: + workspaces: | + packages/rust-bindings + deps/concordium-deps + + - name: Get wasm-pack + uses: jetli/wasm-pack-action@v0.4.0 + with: + version: 'latest' + + - name: Build GRPC bindings + if: steps.cache-grpc.outputs.cache-hit != 'true' + run: | + mkdir -p packages/common/src/grpc-api + mkdir -p packages/nodejs/src/grpc-api + yarn workspace @concordium/common-sdk generate + yarn workspace @concordium/node-sdk generate + + - name: Build + run: yarn build:rust-bindings && yarn build:dev + + - name: Store build-debug + uses: ./.github/actions/upload-artifact + with: + name: build-debug + path: | + ./packages/rust-bindings/lib + ./packages/common/lib + ./packages/web/lib + ./packages/nodejs/lib + ./packages/ccd-js-gen/lib + + typecheck-examples: + runs-on: ubuntu-22.04 + needs: build + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODE_VERSION }} + cache: yarn + + - name: Restore dependencies + uses: actions/cache/restore@v3 + with: + path: node_modules + key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }} + + - name: Restore grpc + uses: actions/cache/restore@v3 + with: + path: | + ./packages/common/src/grpc-api + ./packages/nodejs/src/grpc-api + key: ${{ runner.os }}-grpc + + - name: Get build-debug + uses: ./.github/actions/download-artifact + with: + name: build-debug + + - name: Typecheck examples + run: yarn workspace @concordium/examples typecheck + + common-tests: + runs-on: ubuntu-22.04 + needs: build + defaults: + run: + working-directory: packages/common + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODE_VERSION }} + cache: yarn + + - name: Restore dependencies + uses: actions/cache/restore@v3 + with: + path: node_modules + key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }} + + - name: Restore grpc + uses: actions/cache/restore@v3 + with: + path: | + ./packages/common/src/grpc-api + ./packages/nodejs/src/grpc-api + key: ${{ runner.os }}-grpc + + - name: Get build-debug + uses: ./.github/actions/download-artifact + with: + name: build-debug + + - name: Run Tests + run: yarn test + + typedoc: + runs-on: ubuntu-22.04 + needs: build + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODE_VERSION }} + cache: yarn + + - name: Restore dependencies + uses: actions/cache/restore@v3 + with: + path: node_modules + key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }} + + - name: Restore grpc + uses: actions/cache/restore@v3 + with: + path: | + ./packages/common/src/grpc-api + ./packages/nodejs/src/grpc-api + key: ${{ runner.os }}-grpc + + - name: Get build-debug + uses: ./.github/actions/download-artifact + with: + name: build-debug + + - name: Build typedoc + run: yarn typedoc + + lint: + runs-on: ubuntu-22.04 + needs: build + if: github.event.pull_request.draft == false + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODE_VERSION }} + cache: yarn + + - name: Restore dependencies + uses: actions/cache/restore@v3 + with: + path: node_modules + key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }} + + - name: Restore grpc + uses: actions/cache/restore@v3 + with: + path: | + ./packages/common/src/grpc-api + ./packages/nodejs/src/grpc-api + key: ${{ runner.os }}-grpc + + - name: Get build-debug + uses: ./.github/actions/download-artifact + with: + name: build-debug + + - name: Lint + run: yarn lint + + markdown-lint: + runs-on: ubuntu-22.04 + if: github.event.pull_request.draft == false + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODE_VERSION }} + cache: yarn + + - name: Restore dependencies + uses: actions/cache/restore@v3 + with: + path: node_modules + key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }} + + - name: Restore grpc + uses: actions/cache/restore@v3 + with: + path: | + ./packages/common/src/grpc-api + ./packages/nodejs/src/grpc-api + key: ${{ runner.os }}-grpc + + - name: Lint markdown + run: yarn markdown:lint + + markdown-linkcheck: + runs-on: ubuntu-22.04 + if: github.event.pull_request.draft == false + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODE_VERSION }} + cache: yarn + + - name: Restore dependencies + uses: actions/cache/restore@v3 + with: + path: node_modules + key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }} + + - name: Restore grpc + uses: actions/cache/restore@v3 + with: + path: | + ./packages/common/src/grpc-api + ./packages/nodejs/src/grpc-api + key: ${{ runner.os }}-grpc + + - name: Lint markdown + run: yarn markdown:linkcheck + + rust_lint_fmt: + runs-on: ubuntu-22.04 + if: github.event.pull_request.draft == false + defaults: + run: + working-directory: packages/rust-bindings + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: "recursive" + + - name: Install formatter + run: | + rustup default ${{ env.RUST_FMT }} + rustup component add rustfmt + + - name: Format + run: cargo fmt -- --color=always --check + + rust_lint_clippy: + runs-on: ubuntu-22.04 + needs: rust_lint_fmt + if: github.event.pull_request.draft == false + defaults: + run: + working-directory: packages/rust-bindings + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: "recursive" + + - name: Install clippy + run: | + rustup default ${{ env.RUST_VERSION }} + rustup component add clippy + + - uses: Swatinem/rust-cache@v2 + with: + workspaces: | + packages/rust-bindings + deps/concordium-deps + + - name: Run clippy + run: cargo clippy --color=always --tests --benches -- -Dclippy::all diff --git a/packages/common/tsconfig.build.json b/packages/common/tsconfig.build.json index bcf570d6a..8a61bfd43 100644 --- a/packages/common/tsconfig.build.json +++ b/packages/common/tsconfig.build.json @@ -7,6 +7,5 @@ "compilerOptions": { "rootDir": "./src", "outDir": "./lib/esm", - "allowJs": true } } diff --git a/packages/nodejs/package.json b/packages/nodejs/package.json index 09eb027aa..36b9c5a1a 100644 --- a/packages/nodejs/package.json +++ b/packages/nodejs/package.json @@ -20,8 +20,7 @@ "types": "lib/index.d.ts", "sideEffects": false, "files": [ - "/lib/**/*", - "/grpc-api/**/*" + "/lib/**/*" ], "devDependencies": { "@noble/ed25519": "^1.7.1", @@ -52,16 +51,16 @@ "tabWidth": 4 }, "scripts": { - "generate-js": "yarn run grpc_tools_node_protoc --js_out=import_style=commonjs,binary:grpc-api --grpc_out=grpc_js:grpc-api --plugin=protoc-gen-grpc=../../node_modules/.bin/grpc_tools_node_protoc_plugin -I ../../deps/concordium-base/concordium-grpc-api ../../deps/concordium-base/concordium-grpc-api/**/*.proto", - "generate-ts": "yarn run grpc_tools_node_protoc --plugin=protoc-gen-ts=../../node_modules/grpc_tools_node_protoc_ts/bin/protoc-gen-ts --ts_out=grpc_js:grpc-api -I ../../deps/concordium-base/concordium-grpc-api ../../deps/concordium-base/concordium-grpc-api/concordium_p2p_rpc.proto", + "generate-js": "yarn run grpc_tools_node_protoc --js_out=import_style=commonjs,binary:src/grpc-api --grpc_out=grpc_js:src/grpc-api --plugin=protoc-gen-grpc=../../node_modules/.bin/grpc_tools_node_protoc_plugin -I ../../deps/concordium-base/concordium-grpc-api ../../deps/concordium-base/concordium-grpc-api/**/*.proto", + "generate-ts": "yarn run grpc_tools_node_protoc --plugin=protoc-gen-ts=../../node_modules/grpc_tools_node_protoc_ts/bin/protoc-gen-ts --ts_out=grpc_js:src/grpc-api -I ../../deps/concordium-base/concordium-grpc-api ../../deps/concordium-base/concordium-grpc-api/concordium_p2p_rpc.proto", "generate": "([ -e \"../../deps/concordium-base/concordium-grpc-api\" ] && yarn generate-js && yarn generate-ts) || echo 'Please checkout submodules before building'", "lint": "eslint . --cache --ext .ts,.tsx --max-warnings 0", "lint-fix": "yarn --silent lint --fix; exit 0", "test": "jest", - "build": "rm -rf grpc-api; mkdir -p grpc-api; yarn generate && yarn build-dev", + "build": "rm -rf src/grpc-api; mkdir -p src/grpc-api; yarn generate && yarn build-dev", "build-dev": "yarn tsc-cjs", "tsc-cjs": "tsc -p tsconfig.build.json", - "clean": "rimraf -- lib grpc-api tsconfig.build.tsbuildinfo" + "clean": "rimraf -- lib src/grpc-api tsconfig.build.tsbuildinfo" }, "dependencies": { "@concordium/common-sdk": "9.4.0", diff --git a/packages/nodejs/src/client.ts b/packages/nodejs/src/client.ts index 51092be4d..81254c807 100644 --- a/packages/nodejs/src/client.ts +++ b/packages/nodejs/src/client.ts @@ -1,6 +1,6 @@ import { ChannelCredentials, Metadata, ServiceError } from '@grpc/grpc-js'; import { Buffer as BufferFormater } from 'buffer/'; -import { P2PClient } from '../grpc-api/concordium_p2p_rpc_grpc_pb'; +import { P2PClient } from './grpc-api/concordium_p2p_rpc_grpc_pb'; import { AccountAddress, BlockHash, @@ -14,7 +14,7 @@ import { SendTransactionRequest, TransactionHash, InvokeContractRequest, -} from '../grpc-api/concordium_p2p_rpc_pb'; +} from './grpc-api/concordium_p2p_rpc_pb'; import { serializeAccountTransactionForSubmission, AccountAddress as Address, diff --git a/packages/nodejs/src/util.ts b/packages/nodejs/src/util.ts index 7120bbae1..9a2330a7f 100644 --- a/packages/nodejs/src/util.ts +++ b/packages/nodejs/src/util.ts @@ -1,6 +1,6 @@ import * as fs from 'fs'; import { Buffer } from 'buffer/'; -import { BoolResponse, JsonResponse } from '../grpc-api/concordium_p2p_rpc_pb'; +import { BoolResponse, JsonResponse } from './grpc-api/concordium_p2p_rpc_pb'; /** * @deprecated This is a helper function for the v1 gRPC client, which has been deprecated diff --git a/tsconfig-base.json b/tsconfig-base.json index 58719d484..39e457139 100644 --- a/tsconfig-base.json +++ b/tsconfig-base.json @@ -9,6 +9,7 @@ "moduleResolution": "Node16", "target": "ES2020", "esModuleInterop": true, + "allowJs": true, "composite": true, "skipLibCheck": true }