Simple wrapper of hardhat test for GitHub Action
This action aims to run on top of hardhat project, make sure you're using hardhat in your project
Currently, we support 2 package manager(yarn
and npm
)
By specifying network
option in your workflow, this project can run on either local hardhat network
or testnet
One thing to note is that when you choose to run with testnet, since we're actually integrating with real blockchain, you need to provide an account with some amount of ETH based on your test case usage, you can provide your account via GitHub Secrets
Create a workflow file under .github/workflows
, and name it as for example test.yaml
and fill with following content
name: unit-test
on: [push]
jobs:
test:
runs-on: ubuntu-latest
name: Hardhat unit test
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Environment
uses: actions/setup-node@v3
- name: Test
uses: ambersun1234/hardhat-test-action@v1
with:
network: hardhat
or
name: unit-test
on: [push]
jobs:
test:
runs-on: ubuntu-latest
name: Hardhat unit test
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Environment
uses: actions/setup-node@v3
- name: Test
uses: ambersun1234/hardhat-test-action@v1
with:
network: goerli
private_key: ${{ secrets.PRIVATE_KEY }}
rpc_url: ${{ secrets.RPC_URL }}
In order for this action to work properly, you may need to specify repository secrets
PRIVATE_KEY
- Your private key without
0x
- Your private key without
RPC_URL
- RPC url endpoint, e.g.
https://eth-sepolia.g.alchemy.com/v2/xxxxxxxxxxxxxx
- RPC url endpoint, e.g.
Note that secrets are case sensitive
, be sure to create secrets with all upper case
You can find more information on Encrypted secrets
To align environment variable with your hardhat project,
please check your variable declaration match the following convention or not
We'll use only 2 categories of variable
- private key ➡️ defined as
PRIVATE_KEY
- rpc url ➡️ based on different test network, will have these structure
{NETWORK}_RPC_URL
, whereNETWORK
is the upper case of network name(e.g.GOERLI
,SEPOLIA
)
These environment variable needs to be consistent with data in
hardhat.config.ts
.env
You can find a complete example of how to use this action at github.com/ambersun1234/nft
$ yarn install
$ yarn webpack
This project is licensed under MIT license - see the LICENSE file for more detail