1

I have an hardhat project and would like to add CI workflow using github actions. Here is my github repository. https://github.com/kimiro34/ens-registry-setup

.github/workflow/main.yml file looks like this

name: Node.js CI

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
env:
  NETWORK: $NETWORK
  RPC_URL_ZNX_TESTNET: $RPC_URL_ZNX_TESTNET
  RPC_URL_ZNX_MAINNET: $RPC_URL_ZNX_MAINNET
  MNEMONIC: $MNEMONIC
  ROPSTEN_URL: $ROPSTEN_URL
jobs:
  start-hardhat-node:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [16.x]

    steps:
      - uses: actions/checkout@v3
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node-version }}
      - run: npm install
      - run: npm run node:start
      - run: npm run test

Here is my package.json file.

{
  "name": "hardhat-project",
  "scripts": {
    "node:start": "npx hardhat node",
    "test": "npx hardhat test --network localhost",
    "ci": "scripts/test.sh",
    "compile": "npx hardhat compile",
    "deploy": "npx hardhat run --network deploy scripts/deploy.ts",
    "deploy:hardhat": "npx hardhat run --network localhost scripts/deploy.ts"
  },
  "devDependencies": {},
  "dependencies": {
    "@nomiclabs/hardhat-ethers": "^2.0.5",
    "@nomiclabs/hardhat-etherscan": "^3.0.3",
    "@nomiclabs/hardhat-waffle": "^2.0.3",
    "@typechain/ethers-v5": "^7.2.0",
    "@typechain/hardhat": "^2.3.1",
    "@types/chai": "^4.3.0",
    "@types/mocha": "^9.1.0",
    "@types/node": "^12.20.47",
    "@typescript-eslint/eslint-plugin": "^4.33.0",
    "@typescript-eslint/parser": "^4.33.0",
    "chai": "^4.3.6",
    "dotenv": "^10.0.0",
    "eslint": "^7.32.0",
    "eslint-config-prettier": "^8.5.0",
    "eslint-config-standard": "^16.0.3",
    "eslint-plugin-import": "^2.25.4",
    "eslint-plugin-node": "^11.1.0",
    "eslint-plugin-prettier": "^3.4.1",
    "eslint-plugin-promise": "^5.2.0",
    "ethereum-waffle": "^3.4.4",
    "ethers": "^5.6.2",
    "hardhat-gas-reporter": "^1.0.8",
    "prettier": "^2.6.2",
    "prettier-plugin-solidity": "^1.0.0-beta.13",
    "solhint": "^3.3.7",
    "solidity-coverage": "^0.7.20",
    "ts-node": "^10.7.0",
    "typechain": "^5.2.0",
    "typescript": "^4.6.3",
    "hardhat": "^2.9.3",
    "@ensdomains/ens-contracts": "^0.0.11",
    "eth-ens-namehash": "^2.0.8"
  }
}

The problem is after running npm run node:start cmd npm run test never starts. Here is the current status which I mean. https://github.com/kimiro34/ens-registry-setup/actions https://github.com/kimiro34/ens-registry-setup/runs/5870753222?check_suite_focus=true

I understand that this is because npm run node:start which runs 'npx hardhat node' and this runs local blockchain which won't stop.

So it is possible to test my hardhat project using github action?

3
  • 1
    See how I do this in prb-contracts, and also see my template. Commented Apr 7, 2022 at 16:42
  • Hello try to do the same but i don't really get how set up a Mnemonic for running test before a Merge Request. I can't add a Mnemonic if my repo, any idea
    – Hutgin
    Commented Oct 22, 2022 at 13:00
  • You can use GitHub Secrets to add your mnemonic in a GitHub repo. Consider starting from my Hardhat template. Commented Oct 22, 2022 at 13:03

1 Answer 1

2

You can run node:start and deploy commands concurrently.

Try the following:

name: CI
on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  tests:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
      - name: Install packages
        uses: actions/setup-node@v3
        with:
          node-version: '18.x'
      - run: yarn --ignore-scripts
        shell: bash
      - name: Create local node and deploy
        run: |
          yarn hardhat node &
          yarn hardhat run scripts/deploy.ts --network localhost
      - name: Run Tests
        run: yarn hardhat test

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.