diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..a5db7d3 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @kpachhai \ No newline at end of file diff --git a/.github/actions/install-go/action.yml b/.github/actions/install-go/action.yml new file mode 100644 index 0000000..753cb86 --- /dev/null +++ b/.github/actions/install-go/action.yml @@ -0,0 +1,25 @@ +# Copyright (C) 2023, AllianceBlock. All rights reserved. +# See the file LICENSE for licensing terms. + +name: 'Install Go toolchain with defaults' +description: 'Install a go toolchain with defaults' + +inputs: + cache: + description: 'to cache or not to cache, that is the question' + required: false + default: 'true' + cache-dependency-path: + description: 'forwards go actions/setup-go' + required: false + +runs: + using: composite + steps: + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.21' + check-latest: true + cache: ${{ inputs.cache }} + cache-dependency-path: ${{ inputs.cache-dependency-path }} diff --git a/.github/actions/nuklai-wallet-release/action.yml b/.github/actions/nuklai-wallet-release/action.yml new file mode 100644 index 0000000..6992fbe --- /dev/null +++ b/.github/actions/nuklai-wallet-release/action.yml @@ -0,0 +1,25 @@ +# Copyright (C) 2023, AllianceBlock. All rights reserved. +# See the file LICENSE for licensing terms. + +name: 'Release Nuklai Wallet' +description: 'Release the Nuklai Wallet' + +runs: + using: composite + steps: + - name: Set up Go + uses: ./.github/actions/install-go + with: + cache-dependency-path: | + go.sum + - name: Build wallet + working-directory: ./cmd/nuklai-wallet + shell: bash + run: scripts/build.sh + env: + PUBLISH: 'false' + - name: Archive Builds + uses: actions/upload-artifact@v4 + with: + name: nuklai-wallet + path: ./cmd/nuklai-wallet/nuklai-wallet.zip diff --git a/.github/actions/vm-release/action.yml b/.github/actions/vm-release/action.yml new file mode 100644 index 0000000..ad839eb --- /dev/null +++ b/.github/actions/vm-release/action.yml @@ -0,0 +1,55 @@ +# Copyright (C) 2023, AllianceBlock. All rights reserved. +# See the file LICENSE for licensing terms. + +name: 'Release VM' +description: 'Release the VM' + +inputs: + vm-name: + description: 'NuklaiVM' + required: true + github-token: + description: 'GitHub Token' + required: true + +runs: + using: composite + steps: + - name: Set up Go + uses: ./.github/actions/install-go + with: + cache-dependency-path: | + go.sum + examples/${{ inputs.vm-name }}/go.sum + - name: Set up arm64 cross compiler + shell: bash + run: | + sudo apt-get -y update + sudo apt-get -y install gcc-aarch64-linux-gnu + - name: Checkout osxcross + uses: actions/checkout@v2 + with: + repository: tpoechtrager/osxcross + path: osxcross + - name: Build osxcross + shell: bash + run: | + sudo apt-get -y install clang llvm-dev libxml2-dev uuid-dev libssl-dev bash patch make tar xz-utils bzip2 gzip sed cpio libbz2-dev + cd osxcross + wget https://github.com/joseluisq/macosx-sdks/releases/download/12.3/$MACOS_SDK_FNAME -O tarballs/$MACOS_SDK_FNAME + echo $MACOS_SDK_CHECKSUM tarballs/$MACOS_SDK_FNAME | sha256sum -c - + UNATTENDED=1 ./build.sh + echo $PWD/target/bin >> $GITHUB_PATH + env: + MACOS_SDK_FNAME: MacOSX12.3.sdk.tar.xz + MACOS_SDK_CHECKSUM: 3abd261ceb483c44295a6623fdffe5d44fc4ac2c872526576ec5ab5ad0f6e26c + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + distribution: goreleaser + version: latest + args: release + workdir: ./examples/${{ inputs.vm-name }}/ + env: + # https://docs.github.com/en/actions/security-guides/automatic-token-authentication#about-the-github_token-secret + GITHUB_TOKEN: ${{ inputs.github-token }} diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..fb8cfd5 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,78 @@ +# Copyright (C) 2023, AllianceBlock. All rights reserved. +# See the file LICENSE for licensing terms. + +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: 'CodeQL' + +on: + push: + branches: ['main'] + pull_request: + # The branches below must be a subset of the branches above + branches: ['main'] + schedule: + - cron: '41 18 * * 3' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: ['go'] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + queries: security-extended,security-and-quality + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + # âšī¸ Command-line programs to run using the OS shell. + # đ See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true diff --git a/.github/workflows/load-tests.yml b/.github/workflows/load-tests.yml deleted file mode 100644 index 59163f0..0000000 --- a/.github/workflows/load-tests.yml +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright (C) 2023, AllianceBlock. All rights reserved. -# See the file LICENSE for licensing terms. - -name: NuklaiVM Load Tests - -on: - push: - branches: - - main - pull_request: - types: [labeled, synchronize, reopened] - -jobs: - nuklaivm-load-tests: - if: ${{ github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'run load') }} - strategy: - matrix: - level: [v1, v2, v3] # v4 is not supported - runs-on: dev - timeout-minutes: 25 - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: '1.20' - check-latest: true - cache: true - cache-dependency-path: | - go.sum - - name: Run load tests - working-directory: ./ - shell: bash - run: GOAMD64=${{ matrix.level }} scripts/tests.load.sh -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true diff --git a/.github/workflows/nuklaivm-ci.yml b/.github/workflows/nuklaivm-ci.yml new file mode 100644 index 0000000..d7150ee --- /dev/null +++ b/.github/workflows/nuklaivm-ci.yml @@ -0,0 +1,143 @@ +# Copyright (C) 2023, AllianceBlock. All rights reserved. +# See the file LICENSE for licensing terms. + +name: NuklaiVM CI +on: + push: + branches: + - main + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + go-mod-tidy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Go + uses: ./.github/actions/install-go + - shell: bash + run: go mod tidy + - shell: bash + working-directory: ./ + run: go mod tidy + - shell: bash + run: scripts/tests.clean.sh + + nuklaivm-lint: + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Go + uses: ./.github/actions/install-go + with: + cache-dependency-path: | + go.sum + - name: Run static analysis tests + shell: bash + run: scripts/tests.lint.sh + - name: Build vm, cli, faucet, feed + shell: bash + run: scripts/build.sh + + nuklaivm-unit-tests: + runs-on: ubuntu-20.04-32 + timeout-minutes: 10 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Go + uses: ./.github/actions/install-go + with: + cache-dependency-path: | + go.sum + - name: Run unit tests + shell: bash + run: scripts/tests.unit.sh + - name: Run integration tests + shell: bash + run: scripts/tests.integration.sh + # - name: Archive code coverage results (text) + # uses: actions/upload-artifact@v4 + # with: + # name: code-coverage-out + # path: ./integration.coverage.out + # - name: Archive code coverage results (html) + # uses: actions/upload-artifact@v4 + # with: + # name: code-coverage-html + # path: ./integration.coverage.html + - name: Run e2e tests + shell: bash + run: scripts/run.sh + env: + MODE: 'test' + + nuklaivm-tests: + runs-on: ubuntu-latest + needs: [go-mod-tidy, nuklaivm-lint, nuklaivm-unit-tests] + steps: + - name: Finished NuklaiVM tests + run: echo "Finished NuklaiVM tests" + + nuklaivm-load-tests: + needs: [nuklaivm-unit-tests] + strategy: + matrix: + level: [v1, v2, v3] # v4 is not supported + runs-on: ubuntu-20.04-32 + timeout-minutes: 10 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Go + uses: ./.github/actions/install-go + with: + cache-dependency-path: | + go.sum + - name: Run load tests + shell: bash + run: GOAMD64=${{ matrix.level }} scripts/tests.load.sh + + nuklaivm-sync-tests: + needs: [nuklaivm-unit-tests] + runs-on: ubuntu-20.04-32 + timeout-minutes: 25 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Go + uses: ./.github/actions/install-go + with: + cache-dependency-path: | + go.sum + - name: Run sync tests + shell: bash + run: scripts/run.sh + env: + MODE: 'full-test' + + nuklaivm-wallet-release: + needs: [nuklaivm-load-tests, nuklaivm-sync-tests] + runs-on: macos-latest-xl + steps: + - name: Checkout + uses: actions/checkout@v4 + - uses: ./.github/actions/nuklai-wallet-release + + nuklaivm-release: + needs: [nuklaivm-load-tests, nuklaivm-sync-tests] + # We build with 20.04 to maintain max compatibility: https://github.com/golang/go/issues/57328 + runs-on: ubuntu-20.04-32 + steps: + - name: Checkout + uses: actions/checkout@v4 + - uses: ./.github/actions/vm-release + with: + vm-name: nuklaivm + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 76f4351..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,58 +0,0 @@ -# Copyright (C) 2023, AllianceBlock. All rights reserved. -# See the file LICENSE for licensing terms. - -name: NuklaiVM Release - -on: - push: - branches: - - main - tags: - - '*' - pull_request: - types: [labeled, synchronize, reopened] - -jobs: - nuklaivm-release: - # We build with 20.04 to maintain max compatibility: https://github.com/golang/go/issues/57328 - runs-on: dev - if: ${{ github.ref == 'refs/heads/main' || startsWith(github.event.ref, 'refs/tags/v') || contains(github.event.pull_request.labels.*.name, 'run release') }} - steps: - - name: Git checkout - uses: actions/checkout@v3 - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: '1.20' - check-latest: true - cache: true - cache-dependency-path: | - go.sum - - name: Set up arm64 cross compiler - run: | - apt-get -y update - apt-get -y install gcc-aarch64-linux-gnu - - name: Checkout osxcross - uses: actions/checkout@v2 - with: - repository: tpoechtrager/osxcross - path: osxcross - - name: Build osxcross - run: | - apt-get -y install clang llvm-dev libxml2-dev uuid-dev libssl-dev bash patch make tar xz-utils bzip2 gzip sed cpio libbz2-dev - cd osxcross - wget https://github.com/joseluisq/macosx-sdks/releases/download/12.3/$MACOS_SDK_FNAME -O tarballs/$MACOS_SDK_FNAME - echo $MACOS_SDK_CHECKSUM tarballs/$MACOS_SDK_FNAME | sha256sum -c - - UNATTENDED=1 ./build.sh - echo $PWD/target/bin >> $GITHUB_PATH - env: - MACOS_SDK_FNAME: MacOSX12.3.sdk.tar.xz - MACOS_SDK_CHECKSUM: 3abd261ceb483c44295a6623fdffe5d44fc4ac2c872526576ec5ab5ad0f6e26c - - name: Run GoReleaser - working-directory: ./ - shell: bash - run: scripts/build.release.sh - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 0000000..0ac71b6 --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,29 @@ +# Copyright (C) 2023, AllianceBlock. All rights reserved. +# See the file LICENSE for licensing terms. + +name: Mark stale issues and pull requests +on: + schedule: + - cron: '0 0 * * *' # Run every day at midnight UTC +jobs: + stale: + runs-on: ubuntu-latest + steps: + - uses: actions/stale@v8 + with: + # Overall configuration + operations-per-run: 100 + + # PR configuration + days-before-pr-stale: 30 + stale-pr-message: 'This PR has become stale because it has been open for 30 days with no activity. Adding the `lifecycle/frozen` label will exempt this PR from future lifecycle events..' + days-before-pr-close: -1 + stale-pr-label: lifecycle/stale + exempt-pr-labels: lifecycle/frozen + + # Issue configuration + days-before-issue-stale: 60 + stale-issue-message: 'This issue has become stale because it has been open 60 days with no activity. Adding the `lifecycle/frozen` label will exempt this issue from future lifecycle events.' + days-before-issue-close: -1 + stale-issue-label: lifecycle/stale + exempt-issue-labels: lifecycle/frozen diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml deleted file mode 100644 index f1ba0b7..0000000 --- a/.github/workflows/static-analysis.yml +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright (C) 2023, AllianceBlock. All rights reserved. -# See the file LICENSE for licensing terms. - -name: NuklaiVM Static Analysis - -on: - push: - branches: - - main - pull_request: - -jobs: - nuklaivm-lint: - runs-on: dev - timeout-minutes: 10 - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: '1.20' - check-latest: true - cache: true - cache-dependency-path: | - go.sum - - name: Run static analysis tests - working-directory: ./ - shell: bash - run: scripts/tests.lint.sh - - name: Build vm, cli - working-directory: ./ - shell: bash - run: scripts/build.sh - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true diff --git a/.github/workflows/sync-tests.yml b/.github/workflows/sync-tests.yml deleted file mode 100644 index a5780c8..0000000 --- a/.github/workflows/sync-tests.yml +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright (C) 2023, AllianceBlock. All rights reserved. -# See the file LICENSE for licensing terms. - -name: NuklaiVM Sync Tests - -on: - push: - branches: - - main - pull_request: - types: [labeled, synchronize, reopened] - -jobs: - nuklaivm-sync-tests: - if: ${{ github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'run sync') }} - runs-on: dev - timeout-minutes: 25 - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: "1.20" - check-latest: true - cache: true - cache-dependency-path: | - go.sum - - name: Run sync tests - working-directory: ./ - shell: bash - run: mkdir -p /data/github/tmp/nuklaivm && scripts/run.sh /data/github/tmp/nuklaivm - env: - MODE: "full-test" -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true diff --git a/.github/workflows/tidy-checker.yml b/.github/workflows/tidy-checker.yml deleted file mode 100644 index d49472d..0000000 --- a/.github/workflows/tidy-checker.yml +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (C) 2023, AllianceBlock. All rights reserved. -# See the file LICENSE for licensing terms. - -name: NuklaiVM Tidy Checker -on: - push: - branches: - - main - pull_request: - -jobs: - go_mod_tidy: - name: Tidy - runs-on: dev - steps: - - uses: actions/checkout@v3 - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: '1.20' - check-latest: true - cache: true - - shell: bash - run: go mod tidy - - shell: bash - run: scripts/tests.clean.sh - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml deleted file mode 100644 index 7e5f95e..0000000 --- a/.github/workflows/unit-tests.yml +++ /dev/null @@ -1,56 +0,0 @@ -# Copyright (C) 2023, AllianceBlock. All rights reserved. -# See the file LICENSE for licensing terms. - -name: NuklaiVM Unit Tests - -on: - push: - branches: - - main - pull_request: - types: [labeled, synchronize, reopened] - -jobs: - nuklaivm-unit-tests: - if: ${{ github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'run unit') }} - runs-on: dev - timeout-minutes: 25 - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: "1.20" - check-latest: true - cache: true - cache-dependency-path: | - go.sum - - name: Run unit tests - working-directory: ./ - shell: bash - run: scripts/tests.unit.sh - - name: Run integration tests - working-directory: ./ - shell: bash - run: scripts/tests.integration.sh - - name: Archive code coverage results (text) - uses: actions/upload-artifact@v3 - with: - name: code-coverage-out - path: ./integration.coverage.out - - name: Archive code coverage results (html) - uses: actions/upload-artifact@v3 - with: - name: code-coverage-html - path: ./integration.coverage.html - - name: Run e2e tests - working-directory: ./ - shell: bash - run: mkdir -p /data/github/tmp/nuklaivm && scripts/run.sh /data/github/tmp/nuklaivms - env: - MODE: "test" - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true diff --git a/.github/workflows/vm-release.yml b/.github/workflows/vm-release.yml new file mode 100644 index 0000000..53c447e --- /dev/null +++ b/.github/workflows/vm-release.yml @@ -0,0 +1,32 @@ +# Copyright (C) 2023, AllianceBlock. All rights reserved. +# See the file LICENSE for licensing terms. + +name: VM Release + +on: + push: + tags: + - '*' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + nuklai-wallet-release: + runs-on: macos-latest-xl + steps: + - name: Checkout + uses: actions/checkout@v4 + - uses: ./.github/actions/nuklai-wallet-release + + nuklaivm-release: + # We build with 20.04 to maintain max compatibility: https://github.com/golang/go/issues/57328 + runs-on: ubuntu-20.04-32 + steps: + - name: Checkout + uses: actions/checkout@v4 + - uses: ./.github/actions/vm-release + with: + vm-name: nuklaivm + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index b6ab582..6ae9709 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,5 @@ # nuklaivm -
- ---- - `nuklaivm` takes inspiration from [morpheusvm](https://github.com/ava-labs/hypersdk/tree/main/examples/morpheusvm) and [tokenvm](https://github.com/ava-labs/hypersdk/tree/main/examples/tokenvm) and implements the functionality of both of these VMs. In addition, `nuklaivm` also adds additional functionality such as staking native token `NAI`, has an diff --git a/cmd/nuklai-wallet/scripts/build.sh b/cmd/nuklai-wallet/scripts/build.sh index b9a7bdf..70d7cc2 100755 --- a/cmd/nuklai-wallet/scripts/build.sh +++ b/cmd/nuklai-wallet/scripts/build.sh @@ -31,7 +31,7 @@ fi rm -rf nuklai-wallet.zip # Exit early if not publishing -if [ ${PUBLISH} == false ]; then +if [ "${PUBLISH}" == false ]; then echo "not publishing app" ditto -c -k --keepParent build/bin/Nuklai\ Wallet.app nuklai-wallet.zip exit 0 @@ -39,16 +39,16 @@ fi echo "publishing app" # Sign code -codesign -s ${APP_SIGNING_KEY_ID} --deep --timestamp -o runtime -v build/bin/Nuklai\ Wallet.app +codesign -s "${APP_SIGNING_KEY_ID}" --deep --timestamp -o runtime -v build/bin/Nuklai\ Wallet.app ditto -c -k --keepParent build/bin/Nuklai\ Wallet.app nuklai-wallet.zip # Need to sign to allow for app to be opened on other computers -xcrun altool --notarize-app --primary-bundle-id ai.nukl.nuklai-wallet --username ${APPLE_NOTARIZATION_USERNAME} --password "@keychain:altool" --file nuklai-wallet.zip +xcrun altool --notarize-app --primary-bundle-id ai.nukl.nuklai-wallet --username "${APPLE_NOTARIZATION_USERNAME}" --password "@keychain:altool" --file nuklai-wallet.zip # Log until exit -read -p "Input APPLE_NOTARIZATION_REQUEST_ID: " APPLE_NOTARIZATION_REQUEST_ID +read -p -r "Input APPLE_NOTARIZATION_REQUEST_ID: " APPLE_NOTARIZATION_REQUEST_ID while true do - xcrun altool --notarization-info ${APPLE_NOTARIZATION_REQUEST_ID} -u ${APPLE_NOTARIZATION_USERNAME} -p "@keychain:altool" + xcrun altool --notarization-info "${APPLE_NOTARIZATION_REQUEST_ID}" -u "${APPLE_NOTARIZATION_USERNAME}" -p "@keychain:altool" sleep 15 done diff --git a/cmd/nuklai-wallet/scripts/dev.sh b/cmd/nuklai-wallet/scripts/dev.sh index 8a42931..c1e355d 100755 --- a/cmd/nuklai-wallet/scripts/dev.sh +++ b/cmd/nuklai-wallet/scripts/dev.sh @@ -16,9 +16,6 @@ mkdir -p "$nuklai_wallet_dir" # Install wails go install -v github.com/wailsapp/wails/v2/cmd/wails@v2.8.0 -# Save current directory -current_dir=$(pwd) - # Go up two directories pushd ../.. diff --git a/scripts/build.sh b/scripts/build.sh index 9848049..bb800a5 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -18,12 +18,10 @@ NUKLAIVM_PATH=$( cd .. && pwd ) -realpath() { - [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}" -} - if [[ $# -eq 1 ]]; then - BINARY_PATH=$(realpath $1) + BINARY_DIR=$(cd "$(dirname "$1")" && pwd) + BINARY_FNAME=$(basename "$1") + BINARY_PATH=$BINARY_DIR/$BINARY_FNAME elif [[ $# -eq 0 ]]; then # Set default binary directory location name="qeX5BUxbiwUhSePncmz1C7RdH6njYYv6dNZhJrdeXRKMnTpKt" @@ -33,23 +31,23 @@ else exit 1 fi -cd $NUKLAIVM_PATH +cd "$NUKLAIVM_PATH" echo "Building nuklaivm in $BINARY_PATH" -mkdir -p $(dirname $BINARY_PATH) -go build -o $BINARY_PATH ./cmd/nuklaivm +mkdir -p "$(dirname "$BINARY_PATH")" +go build -o "$BINARY_PATH" ./cmd/nuklaivm CLI_PATH=$NUKLAIVM_PATH/build/nuklai-cli echo "Building nuklai-cli in $CLI_PATH" -mkdir -p $(dirname $CLI_PATH) -go build -o $CLI_PATH ./cmd/nuklai-cli +mkdir -p "$(dirname "$CLI_PATH")" +go build -o "$CLI_PATH" ./cmd/nuklai-cli FAUCET_PATH=$NUKLAIVM_PATH/build/nuklai-faucet echo "Building nuklai-faucet in $FAUCET_PATH" -mkdir -p $(dirname $FAUCET_PATH) -go build -o $FAUCET_PATH ./cmd/nuklai-faucet +mkdir -p "$(dirname "$FAUCET_PATH")" +go build -o "$FAUCET_PATH" ./cmd/nuklai-faucet FEED_PATH=$NUKLAIVM_PATH/build/nuklai-feed echo "Building nuklai-feed in $FEED_PATH" -mkdir -p $(dirname $FEED_PATH) -go build -o $FEED_PATH ./cmd/nuklai-feed +mkdir -p "$(dirname "$FEED_PATH")" +go build -o "$FEED_PATH" ./cmd/nuklai-feed diff --git a/scripts/deploy.devnet.sh b/scripts/deploy.devnet.sh index a40aed4..59f5075 100755 --- a/scripts/deploy.devnet.sh +++ b/scripts/deploy.devnet.sh @@ -9,7 +9,7 @@ set -o pipefail # Ensure we return back to current directory pw=$(pwd) function cleanup() { - cd $pw + cd "$pw" } trap cleanup EXIT @@ -23,18 +23,20 @@ mkdir -p /tmp/avalanche-ops-cache # Create deployment directory (avalanche-ops creates metadata in cwd) DATE=$(date '+%m%d%Y-%H%M%S') DEPLOY_PREFIX=~/avalanche-ops-deploys/${DATE} -mkdir -p ${DEPLOY_PREFIX} +mkdir -p "${DEPLOY_PREFIX}" DEPLOY_ARTIFACT_PREFIX=${DEPLOY_PREFIX}/artifacts -mkdir -p ${DEPLOY_ARTIFACT_PREFIX} -echo create deployment folder: ${DEPLOY_PREFIX} -cd ${DEPLOY_PREFIX} +mkdir -p "${DEPLOY_ARTIFACT_PREFIX}" +echo create deployment folder: "${DEPLOY_PREFIX}" +cd "${DEPLOY_PREFIX}" # Set constants -export DEPLOYER_ARCH_TYPE=$(uname -m) -[ $DEPLOYER_ARCH_TYPE = x86_64 ] && DEPLOYER_ARCH_TYPE=amd64 -echo DEPLOYER_ARCH_TYPE: ${DEPLOYER_ARCH_TYPE} -export DEPLOYER_OS_TYPE=$(uname | tr '[:upper:]' '[:lower:]') -echo DEPLOYER_OS_TYPE: ${DEPLOYER_OS_TYPE} +DEPLOYER_ARCH_TYPE=$(uname -m) +export DEPLOYER_ARCH_TYPE +[ "$DEPLOYER_ARCH_TYPE" = x86_64 ] && DEPLOYER_ARCH_TYPE=amd64 +echo DEPLOYER_ARCH_TYPE: "${DEPLOYER_ARCH_TYPE}" +DEPLOYER_OS_TYPE=$(uname | tr '[:upper:]' '[:lower:]') +export DEPLOYER_OS_TYPE +echo DEPLOYER_OS_TYPE: "${DEPLOYER_OS_TYPE}" export AVALANCHEGO_VERSION="1.10.12" echo AVALANCHEGO_VERSION: ${AVALANCHEGO_VERSION} export NUKLAIVM_VERSION="0.1.0" @@ -47,11 +49,11 @@ echo EMISSION_ADDRESS: ${EMISSION_ADDRESS} # TODO: set deploy os/arch # Check valid setup -if [ ${DEPLOYER_OS_TYPE} != 'darwin' ]; then +if [ "${DEPLOYER_OS_TYPE}" != 'darwin' ]; then echo 'os is not supported' >&2 exit 1 fi -if [ ${DEPLOYER_ARCH_TYPE} != 'arm64' ]; then +if [ "${DEPLOYER_ARCH_TYPE}" != 'arm64' ]; then echo 'arch is not supported' >&2 exit 1 fi @@ -67,65 +69,65 @@ fi # Install avalanche-ops echo 'installing avalanche-ops...' if [ -f /tmp/avalanche-ops-cache/avalancheup-aws ]; then - cp /tmp/avalanche-ops-cache/avalancheup-aws ${DEPLOY_ARTIFACT_PREFIX}/avalancheup-aws + cp /tmp/avalanche-ops-cache/avalancheup-aws "${DEPLOY_ARTIFACT_PREFIX}"/avalancheup-aws echo 'found avalanche-ops in cache' else wget https://github.com/ava-labs/avalanche-ops/releases/download/latest/avalancheup-aws.aarch64-apple-darwin - mv ./avalancheup-aws.aarch64-apple-darwin ${DEPLOY_ARTIFACT_PREFIX}/avalancheup-aws - chmod +x ${DEPLOY_ARTIFACT_PREFIX}/avalancheup-aws - cp ${DEPLOY_ARTIFACT_PREFIX}/avalancheup-aws /tmp/avalanche-ops-cache/avalancheup-aws + mv ./avalancheup-aws.aarch64-apple-darwin "${DEPLOY_ARTIFACT_PREFIX}"/avalancheup-aws + chmod +x "${DEPLOY_ARTIFACT_PREFIX}"/avalancheup-aws + cp "${DEPLOY_ARTIFACT_PREFIX}"/avalancheup-aws /tmp/avalanche-ops-cache/avalancheup-aws fi -${DEPLOY_ARTIFACT_PREFIX}/avalancheup-aws --help +"${DEPLOY_ARTIFACT_PREFIX}"/avalancheup-aws --help # Install nuklai-cli echo 'installing nuklai-cli...' if [ -f /tmp/avalanche-ops-cache/nuklai-cli ]; then - cp /tmp/avalanche-ops-cache/nuklai-cli ${DEPLOY_ARTIFACT_PREFIX}/nuklai-cli + cp /tmp/avalanche-ops-cache/nuklai-cli "${DEPLOY_ARTIFACT_PREFIX}"/nuklai-cli echo 'found nuklai-cli in cache' else wget "https://github.com/nuklai/nuklaivm/releases/download/v${NUKLAIVM_VERSION}/nuklaivm_${NUKLAIVM_VERSION}_${DEPLOYER_OS_TYPE}_${DEPLOYER_ARCH_TYPE}.tar.gz" mkdir -p /tmp/nuklai-installs - tar -xvf nuklaivm_${NUKLAIVM_VERSION}_${DEPLOYER_OS_TYPE}_${DEPLOYER_ARCH_TYPE}.tar.gz -C /tmp/nuklai-installs - rm -rf nuklaivm_${NUKLAIVM_VERSION}_${DEPLOYER_OS_TYPE}_${DEPLOYER_ARCH_TYPE}.tar.gz - mv /tmp/nuklai-installs/nuklai-cli ${DEPLOY_ARTIFACT_PREFIX}/nuklai-cli + tar -xvf nuklaivm_${NUKLAIVM_VERSION}_"${DEPLOYER_OS_TYPE}"_"${DEPLOYER_ARCH_TYPE}".tar.gz -C /tmp/nuklai-installs + rm -rf nuklaivm_${NUKLAIVM_VERSION}_"${DEPLOYER_OS_TYPE}"_"${DEPLOYER_ARCH_TYPE}".tar.gz + mv /tmp/nuklai-installs/nuklai-cli "${DEPLOY_ARTIFACT_PREFIX}"/nuklai-cli rm -rf /tmp/nuklai-installs - cp ${DEPLOY_ARTIFACT_PREFIX}/nuklai-cli /tmp/avalanche-ops-cache/nuklai-cli + cp "${DEPLOY_ARTIFACT_PREFIX}"/nuklai-cli /tmp/avalanche-ops-cache/nuklai-cli fi # Download nuklaivm echo 'downloading nuklaivm...' if [ -f /tmp/avalanche-ops-cache/nuklaivm ]; then - cp /tmp/avalanche-ops-cache/nuklaivm ${DEPLOY_ARTIFACT_PREFIX}/nuklaivm - cp /tmp/avalanche-ops-cache/nuklai-cli-dev ${DEPLOY_ARTIFACT_PREFIX}/nuklai-cli-dev + cp /tmp/avalanche-ops-cache/nuklaivm "${DEPLOY_ARTIFACT_PREFIX}"/nuklaivm + cp /tmp/avalanche-ops-cache/nuklai-cli-dev "${DEPLOY_ARTIFACT_PREFIX}"/nuklai-cli-dev echo 'found nuklaivm in cache' else wget "https://github.com/ava-labs/hypersdk/releases/download/v${NUKLAIVM_VERSION}/nuklaivm_${NUKLAIVM_VERSION}_linux_amd64.tar.gz" mkdir -p /tmp/nuklai-installs tar -xvf nuklaivm_${NUKLAIVM_VERSION}_linux_amd64.tar.gz -C /tmp/nuklai-installs rm -rf nuklaivm_${NUKLAIVM_VERSION}_linux_amd64.tar.gz - mv /tmp/nuklai-installs/nuklaivm ${DEPLOY_ARTIFACT_PREFIX}/nuklaivm - mv /tmp/nuklai-installs/nuklai-cli ${DEPLOY_ARTIFACT_PREFIX}/nuklai-cli-dev + mv /tmp/nuklai-installs/nuklaivm "${DEPLOY_ARTIFACT_PREFIX}"/nuklaivm + mv /tmp/nuklai-installs/nuklai-cli "${DEPLOY_ARTIFACT_PREFIX}"/nuklai-cli-dev rm -rf /tmp/nuklai-installs - cp ${DEPLOY_ARTIFACT_PREFIX}/nuklaivm /tmp/avalanche-ops-cache/nuklaivm - cp ${DEPLOY_ARTIFACT_PREFIX}/nuklai-cli-dev /tmp/avalanche-ops-cache/nuklai-cli-dev + cp "${DEPLOY_ARTIFACT_PREFIX}"/nuklaivm /tmp/avalanche-ops-cache/nuklaivm + cp "${DEPLOY_ARTIFACT_PREFIX}"/nuklai-cli-dev /tmp/avalanche-ops-cache/nuklai-cli-dev fi # Setup genesis and configuration files -cat <