NomicFoundation / hardhat

Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software.
https://hardhat.org
Other
7.21k stars 1.38k forks source link

Occasional Error with NPM install in Github Actions #4119

Closed ulmentflam closed 1 year ago

ulmentflam commented 1 year ago

Version of Hardhat

2.16.1

What happened?

When running in the github actions docker container ubuntu-latest, hardhat will occasionally fail to compile solidity v0.8.9 during npm install with the following error:

npm ERR! code 1
npm ERR! git dep preparation failed
npm ERR! command /opt/hostedtoolcache/node/1[8](https://github.com/<repo_name>/actions/runs/id/jobs/id#step:5:9).16.1/x64/bin/node /opt/hostedtoolcache/node/18.16.1/x64/lib/node_modules/npm/bin/npm-cli.js install --force --cache=/home/runner/.npm --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit --include=dev --include=peer --include=optional --no-package-lock-only --no-dry-run
npm ERR! npm ERR! code 1
npm ERR! npm ERR! git dep preparation failed
npm ERR! npm ERR! command /opt/hostedtoolcache/node/18.16.1/x64/bin/node /opt/hostedtoolcache/node/18.16.1/x64/lib/node_modules/npm/bin/npm-cli.js install --force --cache=/home/runner/.npm --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit --include=dev --include=peer --include=optional --no-package-lock-only --no-dry-run
npm ERR! npm ERR! > @0xsequence/create3@3.0.0 prepare
npm ERR! npm ERR! > yarn build
npm ERR! npm ERR! 
npm ERR! npm ERR! yarn run v1.22.1[9](https://github.com/<repo_name>/actions/runs/id/jobs/id#step:5:10)
npm ERR! npm ERR! $ hardhat compile
npm ERR! npm ERR! 
npm ERR! npm ERR! info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
npm ERR! npm ERR! Solidity 0.8.9 is not fully supported yet. You can still use Hardhat, but some features, like stack traces, might not work correctly.
npm ERR! npm ERR! 
npm ERR! npm ERR! Learn more at https://hardhat.org/reference/solidity-support"
npm ERR! npm ERR! 
npm ERR! npm ERR! An unexpected error occurred:
npm ERR! npm ERR! SyntaxError: /home/runner/.cache/hardhat-nodejs/compilers/linux-amd64/list.json: Unexpected end of JSON input
npm ERR! npm ERR!     at JSON.parse (<anonymous>)
npm ERR! npm ERR!     at /home/runner/.npm/_cacache/tmp/git-clone4VrSzb/node_modules/jsonfile/index.js:33:18
npm ERR! npm ERR!     at /home/runner/.npm/_cacache/tmp/git-clone4VrSzb/node_modules/graceful-fs/graceful-fs.js:123:16
npm ERR! npm ERR!     at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3)
npm ERR! npm ERR! error Command failed with exit code 1.
npm ERR! npm ERR! npm ERR! code 1
npm ERR! npm ERR! npm ERR! path /home/runner/.npm/_cacache/tmp/git-clone4VrSzb
npm ERR! npm ERR! npm ERR! command failed
npm ERR! npm ERR! npm ERR! command sh -c yarn build
npm ERR! npm ERR! 
npm ERR! npm ERR! npm ERR! A complete log of this run can be found in:
npm ERR! npm ERR! npm ERR!     /home/runner/.npm/_logs/2023-07-07T[13](https://github.com/<repo_name>/actions/runs/id/jobs/id#step:5:14)_46_42_922Z-debug-0.log
npm ERR! 
npm ERR! npm ERR! A complete log of this run can be found in:
npm ERR! npm ERR!     /home/runner/.npm/_logs/[20](https://github.com/<repo_name>/actions/runs/id/jobs/id#step:5:21)[23](https://github.com/<repo_name>/actions/runs/id/jobs/id#step:5:24)-07-07T13_46_40_892Z-debug-0.log

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2023-07-07T13_46_[25](https://github.com/<repo_name>/actions/runs/id/jobs/id#step:5:26)_908Z-debug-0.log
make: *** [Makefile:[38](https://github.com/<repo_name>/actions/runs/id/jobs/id#step:5:39): setup] Error 1
Error: Process completed with exit code 2.

If the action is run a second time, this error resolves. It is very strange that this issue is resolved with it is run again. It's hit or miss when this error appears. It could also be related to dependencies, @0xsequence and @openzepplin are both installed with npm, but npm installs dependencies without issues elsewhere. I have also experienced the same issue with running py-solc-x with the mythx-cli. This same error occurs occasionally at the same compile step for different dependencies.

Minimal reproduction steps

The GitHub actions yaml to reproduce this is as follows:

name: CI

on:
  push:
    branches: '*'

jobs:
  build:
    defaults:
      run:
        working-directory: .

    name: Build
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 18.16.1
          cache: npm
      - name: Install Dependencies
        run: npm install

A sample package.json is as follows:

{
  "name": "sample",
  "version": "1.0.0",
  "description": "sample package.json",
  "main": "index.js",
  "scripts": {
    "compile": "hardhat compile",
    "test": "hardhat test",
    "format": "prettier --write 'contracts/**/*.sol'",
    "lint": "solhint 'contracts/**/*.sol' && prettier --list-different 'contracts/**/*.sol'"
  },
  "author": "",
  "license": "",
  "devDependencies": {
    "@0xsequence/sstore2": "https://github.com/0xsequence/sstore2",
    "@nomicfoundation/hardhat-chai-matchers": "^1.0.6",
    "@nomicfoundation/hardhat-network-helpers": "^1.0.8",
    "@nomicfoundation/hardhat-toolbox": "^2.0.2",
    "@nomiclabs/hardhat-ethers": "^2.2.2",
    "@nomiclabs/hardhat-etherscan": "^3.1.7",
    "@openzeppelin/contracts": "^4.8.3",
    "@openzeppelin/contracts-upgradeable": "^4.8.3",
    "@openzeppelin/hardhat-upgrades": "^1.22.1",
    "@openzeppelin/merkle-tree": "^1.0.4",
    "@solidstate/hardhat-bytecode-exporter": "^1.1.1",
    "@typechain/ethers-v5": "^10.2.1",
    "@typechain/hardhat": "^6.1.6",
    "@types/chai": "^4.3.5",
    "@types/mocha": "^10.0.1",
    "alchemy-sdk": "^2.6.1",
    "ethers": "^5.7.2",
    "hardhat": "^2.16.1",
    "hardhat-docgen": "^1.3.0",
    "hardhat-gas-reporter": "^1.0.9",
    "lowdb": "^5.1.0",
    "prettier": "^2.8.6",
    "prettier-plugin-solidity": "^1.1.3",
    "solhint": "^3.4.1",
    "solhint-plugin-prettier": "^0.0.5",
    "solidity-coverage": "^0.8.4",
    "solidity-docgen": "^0.6.0-beta.35",
    "ts-node": "^10.9.1",
    "typechain": "^8.2.0",
    "typescript": "^5.1.6"
  },
  "dependencies": {
    "@0xsequence/create3": "https://github.com/0xsequence/create3",
    "chai": "^4.3.7",
    "dotenv": "^16.0.3",
    "uuid": "^9.0.0"
  }
}

Search terms

hardhat compile fails occasionally github actions npm install

ulmentflam commented 1 year ago

This is an additional sample of a similar error that has been occurring in the action when installing mythx-cli leveraging py-solc-x to install hardhat through Python, a similar re-run of the workflow was also able to fix this run.

npm ERR! npm ERR! Solidity 0.8.9 is not fully supported yet. You can still use Hardhat, but some features, like stack traces, might not work correctly.
npm ERR! npm ERR! 
npm ERR! npm ERR! Learn more at https://hardhat.org/reference/solidity-support"
npm ERR! npm ERR! 
npm ERR! npm ERR! Error HH503: Couldn't download compiler version 0.8.9. Checksum verification failed. Please check your connection.
npm ERR! npm ERR! For more info go to https://hardhat.org/HH503 or run Hardhat with --show-stack-traces
npm ERR! npm ERR! error Command failed with exit code 1.
npm ERR! npm ERR! npm ERR! code 1
npm ERR! npm ERR! npm ERR! path /home/runner/.npm/_cacache/tmp/git-cloneMPSkdY
npm ERR! npm ERR! npm ERR! command failed
npm ERR! npm ERR! npm ERR! command sh /tmp/prepare-26a68cad.sh
npm ERR! npm ERR! 
npm ERR! npm ERR! npm ERR! A complete log of this run can be found in:
npm ERR! npm ERR! npm ERR!     /home/runner/.npm/_logs/2023-06-26T20_48_21_178Z-debug-0.log
npm ERR! 
npm ERR! npm ERR! A complete log of this run can be found in:
npm ERR! npm ERR!     /home/runner/.npm/_logs/2023-06-26T20_48_18_353Z-debug-0.log

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2023-06-26T20_47_47_423Z-debug-0.log
make: *** [Makefile:32: setup] Error 1

This github action runner can replicate the above behavior:

name: CI

on:
  push:
    branches: '*'

jobs:
  analyzer:
    defaults:
      run:
        working-directory: .
    name: Mythx Analyzer
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: 3.11.4
      - name: Install Mythx
        run: pip3 install mythx-cli
fvictorio commented 1 year ago

This:

Solidity 0.8.9 is not fully supported yet. You can still use Hardhat, but some features, like stack traces, might not work correctly.

Makes me think that you are using a quite old version of Hardhat. Can you upgrade to the latest version and see if that fixes your problem?

ulmentflam commented 1 year ago

@fvictorio I'm bumping to 2.17.0 now to see if that fixes the issue.

csgeeek commented 1 year ago

I am facing a similar issue of the build getting failed on Github actions. I am trying to set up react-snap for my react project.

This is the error logged

The process '/opt/hostedtoolcache/node/18.16.1/x64/bin/npm'

Things I have tried:

  1. Fresh install by clearing cache

Any insights would be a lot helpful.

monterocjl commented 1 year ago

I get a similar issue when try to uses ArtiomTr/jest-coverage-report-action@v2 on a Github action.

Error: Error: The process '/opt/hostedtoolcache/node/18.16.1/x64/bin/npx' failed with exit code 1

fvictorio commented 1 year ago

@csgeeek @monterocjl can you give me a link to the failed runs?

csgeeek commented 1 year ago

Sure, here you go @fvictorio https://github.com/csgeeek/csgeeek.github.io/actions/runs/5567192020 Let me know if anymore details are required from my side.

fvictorio commented 1 year ago

@csgeeek but... that's not a Hardhat project? It seems like your personal website. Am I missing something here?

monterocjl commented 1 year ago

@csgeeek @monterocjl can you give me a link to the failed runs?

I resolved the issue. Just adding 'npm install npx' in the .yml file, before run ArtiomTr/jest-coverage-report-action@v2

fvictorio commented 1 year ago

Ok, I'm gonna close this issue because I'm pretty sure that most of the comments here are unrelated to Hardhat. If someone has a similar problem and is sure that it's Hardhat related and has reproduction steps, please open a new issue.