Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fix examples and run them in every new PR/per push #2830

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
310 changes: 183 additions & 127 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,99 +1,201 @@
name: Build & Test
on:
push:
branches:
- main
- develop
- release/*
- integration-test-workflow
pull_request:
branches:
- main
- develop
- release/*
push:
branches:
- main
- develop
- release/*
- integration-test-workflow
pull_request:
branches:
- main
- develop
- release/*

defaults:
run:
shell: bash
run:
shell: bash

permissions:
contents: read
pull-requests: write
contents: read
pull-requests: write

env:
CG_EXEC: ionice -c 2 -n 2 nice -n 19
CG_EXEC: ionice -c 2 -n 2 nice -n 19

jobs:
build:
name: Build using Node ${{ matrix.node }}
build:
name: Build using Node ${{ matrix.node }}
runs-on: hiero-client-sdk-linux-medium
strategy:
matrix:
node: ["20", "22"]

steps:
- name: Harden Runner
uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4
with:
egress-policy: audit

- name: Checkout Code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
submodules: true

- name: Install Task
uses: arduino/setup-task@b91d5d2c96a56797b48ac1e0e89220bf64044611 # v2.0.0
with:
version: 3.35.1

# Note: After Step-Security is enabled return to step-security/action-setup version
- name: Install PNPM
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
with:
version: 8.15.4

- name: Setup Node
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: ${{ matrix.node }}
cache: pnpm

- name: Build @hashgraph/sdk
run: task -v build

test:
name: Test using Node ${{ matrix.node }}
runs-on: hiero-client-sdk-linux-large
strategy:
matrix:
node: ["20"]

steps:
- name: Harden Runner
uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4
with:
egress-policy: audit

- name: Checkout Code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
submodules: recursive

- name: Install Task
uses: arduino/setup-task@b91d5d2c96a56797b48ac1e0e89220bf64044611 # v2.0.0
with:
version: 3.35.1

- name: "Create env file"
run: |
touch .env
echo OPERATOR_KEY="302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137" >> .env
echo OPERATOR_ID="0.0.2" >> .env
echo HEDERA_NETWORK="local-node" >> .env
cat .env

# Note: After Step-Security is enabled return to step-security/action-setup version
- name: Install PNPM
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
with:
version: 8.15.4

- name: Setup Node
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: ${{ matrix.node }}
cache: pnpm

- name: Build @hashgraph/sdk
id: build-sdk
run: task build

- name: Install Playwright Dependencies
id: playwright-deps
if: ${{ steps.build-sdk.conclusion == 'success' && !cancelled() && always() }}
run: sudo npx playwright install-deps

- name: Start the local node
id: start-local-node
if: ${{ steps.build-sdk.conclusion == 'success' && !cancelled() && always() }}
run: |
${{ env.CG_EXEC }} npx @hashgraph/hedera-local start -d -—network local --balance=100000 --network-tag=0.57.0
# Wait for the network to fully start
sleep 30

- name: Run Hedera SDK Integration Tests
if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }}
run: ${{ env.CG_EXEC }} task test:integration:codecov

- name: Upload coverage to Codecov
uses: codecov/codecov-action@5c47607acb93fed5485fdbf7232e8a31425f672a # v5.0.2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage/lcov.info
fail_ci_if_error: false

- name: Stop the local node
id: stop-local-node
if: ${{ steps.start-local-node.conclusion == 'success' && !cancelled() && always() }}
run: ${{ env.CG_EXEC }} npx @hashgraph/hedera-local stop

- name: Build @hashgraph/cryptography
working-directory: packages/cryptography
if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }}
run: ${{ env.CG_EXEC }} task build

- name: Unit Test @hashgraph/cryptography
working-directory: packages/cryptography
if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }}
run: ${{ env.CG_EXEC }} task test:unit

- name: Codecov @hashgraph/cryptography
working-directory: packages/cryptography
if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }}
run: ${{ env.CG_EXEC }} task test:unit:codecov

- name: Upload @hashgraph/cryptography coverage to Codecov
uses: codecov/codecov-action@5c47607acb93fed5485fdbf7232e8a31425f672a # v5.0.2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./packages/cryptography/coverage/lcov.info
fail_ci_if_error: false

- name: Unit Test @hashgraph/sdk
if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && steps.playwright-deps.conclusion == 'success' && !cancelled() && always() }}
run: ${{ env.CG_EXEC }} task test:unit

- name: Codecov @hashgraph/sdk
if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }}
run: ${{ env.CG_EXEC }} task test:unit:codecov

- name: Upload @hashgraph/sdk coverage to Codecov
uses: codecov/codecov-action@5c47607acb93fed5485fdbf7232e8a31425f672a # v5.0.2
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true

examples:
name: Run examples using Node ${{ matrix.node }}
runs-on: hiero-client-sdk-linux-medium
strategy:
matrix:
node: [ "20", "22" ]

steps:
- name: Harden Runner
uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4
with:
egress-policy: audit

- name: Checkout Code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
submodules: true

- name: Install Task
uses: arduino/setup-task@b91d5d2c96a56797b48ac1e0e89220bf64044611 # v2.0.0
with:
version: 3.35.1

# Note: After Step-Security is enabled return to step-security/action-setup version
- name: Install PNPM
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
with:
version: 8.15.4

- name: Setup Node
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: ${{ matrix.node }}
cache: pnpm

- name: Build @hashgraph/sdk
run: task -v build

test:
name: Test using Node ${{ matrix.node }}
runs-on: hiero-client-sdk-linux-large
strategy:
matrix:
node: [ "20" ]

steps:
- name: Harden Runner
uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4
with:
egress-policy: audit
egress-policy: audit

- name: Checkout Code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
submodules: recursive
- name: Checkout Code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
submodules: recursive

- name: Install Task
uses: arduino/setup-task@b91d5d2c96a56797b48ac1e0e89220bf64044611 # v2.0.0
with:
version: 3.35.1

- name: "Create env file"
run: |
touch .env
echo OPERATOR_KEY="302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137" >> .env
echo OPERATOR_ID="0.0.2" >> .env
echo HEDERA_NETWORK="local-node" >> .env
cat .env

# Note: After Step-Security is enabled return to step-security/action-setup version
- name: Install PNPM
uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0
with:
Expand All @@ -102,74 +204,28 @@ jobs:
- name: Setup Node
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: ${{ matrix.node }}
cache: pnpm
node-version: ${{ matrix.node }}
cache: pnpm

- name: Build @hashgraph/sdk
id: build-sdk
run: task build

- name: Install Playwright Dependencies
id: playwright-deps
if: ${{ steps.build-sdk.conclusion == 'success' && !cancelled() && always() }}
run: sudo npx playwright install-deps

- name: Start the local node
id: start-local-node
if: ${{ steps.build-sdk.conclusion == 'success' && !cancelled() && always() }}
if: ${{ !cancelled() && always() }}
run: |
${{ env.CG_EXEC }} npx @hashgraph/hedera-local start -d -—network local --balance=100000 --network-tag=0.57.0
# Wait for the network to fully start
sleep 30

- name: Run Hedera SDK Integration Tests
if: ${{ steps.build-sdk.conclusion == 'success' && steps.start-local-node.conclusion == 'success' && !cancelled() && always() }}
run: ${{ env.CG_EXEC }} task test:integration:codecov

- name: Upload coverage to Codecov
uses: codecov/codecov-action@5c47607acb93fed5485fdbf7232e8a31425f672a # v5.0.2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage/lcov.info
fail_ci_if_error: false

- name: Install dependencies
run: |
cd examples
pnpm i

- name: Run all еxamples
run: task run:examples
- name: Stop the local node
id: stop-local-node
if: ${{ steps.start-local-node.conclusion == 'success' && !cancelled() && always() }}
run: ${{ env.CG_EXEC }} npx @hashgraph/hedera-local stop

- name: Build @hashgraph/cryptography
working-directory: packages/cryptography
if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }}
run: ${{ env.CG_EXEC }} task build

- name: Unit Test @hashgraph/cryptography
working-directory: packages/cryptography
if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }}
run: ${{ env.CG_EXEC }} task test:unit

- name: Codecov @hashgraph/cryptography
working-directory: packages/cryptography
if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }}
run: ${{ env.CG_EXEC }} task test:unit:codecov

- name: Upload @hashgraph/cryptography coverage to Codecov
uses: codecov/codecov-action@5c47607acb93fed5485fdbf7232e8a31425f672a # v5.0.2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./packages/cryptography/coverage/lcov.info
fail_ci_if_error: false

- name: Unit Test @hashgraph/sdk
if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && steps.playwright-deps.conclusion == 'success' && !cancelled() && always() }}
run: ${{ env.CG_EXEC }} task test:unit

- name: Codecov @hashgraph/sdk
if: ${{ steps.build-sdk.conclusion == 'success' && steps.stop-local-node.conclusion == 'success' && !cancelled() && always() }}
run: ${{ env.CG_EXEC }} task test:unit:codecov

- name: Upload @hashgraph/sdk coverage to Codecov
uses: codecov/codecov-action@5c47607acb93fed5485fdbf7232e8a31425f672a # v5.0.2
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
4 changes: 2 additions & 2 deletions examples/create-contract-with-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import dotenv from "dotenv";
dotenv.config();

// Import the compiled contract
import payableContract from "./payable.json" assert { type: "json" };
import payableContract from "./payable.json" with { type: "json" };

async function main() {
if (
Expand Down Expand Up @@ -126,7 +126,7 @@ async function main() {
.freezeWithSigner(wallet);
await contractDeleteTransaction.signWithSigner(wallet);
const contractDeleteResult =
await transaction.executeWithSigner(wallet);
await contractDeleteTransaction.executeWithSigner(wallet);

// Delete the contract
// Note: The admin key of the contract needs to sign the transaction
Expand Down
2 changes: 1 addition & 1 deletion examples/create-simple-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import dotenv from "dotenv";
dotenv.config();

// Import the compiled contract
import helloWorld from "./hello_world.json" assert { type: "json" };
import helloWorld from "./hello_world.json" with { type: "json" };

async function main() {
if (
Expand Down
Loading