Skip to content

Commit

Permalink
adding actions pipeline, using env vars and other improvements (#2)
Browse files Browse the repository at this point in the history
* Update ci.yml
* updated: using env vars, update compiler and other cleanups
* Update README.md
  • Loading branch information
Salmandabbakuti authored Oct 22, 2022
1 parent 4bd0387 commit 62b25bd
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Be aware. dont commit this file or any of theses keys to your repo.
PRIV_KEY=
ETHEREUM_MAINNET_RPC_URL=
GOERLI_RPC_URL=
POLYGON_MUMBAI_RPC_URL=
POLYGON_MAINNET_RPC_URL=
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# adding tests
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches: [main, develop, init, "feat/*"]
pull_request:
branches: [main, develop, init, "feat/*"]

jobs:
e2e-test:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node-version: [14.x, 16.x, 18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }} on ${{ matrix.os }}
uses: actions/setup-node@v3
# uses: borales/[email protected]
with:
node-version: ${{ matrix.node-version }}
cache: yarn
- name: "Install packages"
run: yarn
- name: "Rename .env.example to .env"
run: mv .env.example .env
- name: "Start hardhat node"
run: yarn hardhat node & sleep 3
- name: "Compile contracts"
run: yarn compile
- name: "Run tests"
run: yarn test
- name: "Deploy contracts"
run: yarn deploy
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, a sample script that deploys that contract, and an example of a task implementation, which simply lists the available accounts with balances.

> Rename `env.example` to `.env` and add your env specific keys.
Try running some of the following tasks:

```shell
Expand Down
4 changes: 2 additions & 2 deletions contracts/greeter.sol → contracts/Greeter.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//SPDX-License-Identifier: MIT
pragma solidity 0.8.7;
pragma solidity 0.8.16;

contract greeter {
contract Greeter {
string private greeting;

constructor(string memory _greeting) {
Expand Down
24 changes: 16 additions & 8 deletions hardhat.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
require("@nomiclabs/hardhat-ethers");
require('dotenv').config();

// defining accounts to reuse.
const accounts = process.env.PRIV_KEY ? [process.env.PRIV_KEY] : [];

// This is a sample Hardhat task. To learn how to create your own go to
// https://hardhat.org/guides/create-task.html
Expand All @@ -15,7 +19,7 @@ task("accounts", "Prints the list of accounts with balances", async () => {
});

task("deploy", "Deploys Contract", async () => {
const contractFactory = await ethers.getContractFactory("greeter");
const contractFactory = await ethers.getContractFactory("Greeter");
const contract = await contractFactory.deploy("Hello, Hardhat!");
await contract.deployed();
console.log("contract deployed at:", contract.address);
Expand All @@ -39,21 +43,25 @@ module.exports = {
local: {
url: "http://127.0.0.1:8545",
},
main: {
url: process.env.ETHEREUM_MAINNET_RPC_URL,
accounts: accounts
},
goerli: {
url: "", // rpc providers: infura, alchemy
accounts: [] // private keys
url: process.env.GOERLI_RPC_URL,
accounts // private keys
},
polygonTest: {
url: "", // rpc providers: polygon, infura, alchemy
accounts: []
url: process.env.POLYGON_MUMBAI_RPC_URL,
accounts
},
polygonMain: {
url: "", // rpc providers: infura,polygon, alchemy
accounts: []
url: process.env.POLYGON_MAINNET_RPC_URL,
accounts
}
},
solidity: {
version: "0.8.7",
version: "0.8.16",
settings: {
optimizer: {
enabled: true,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.1.1",
"chai": "^4.3.6",
"dotenv": "^16.0.3",
"ethers": "^5.7.0",
"hardhat": "^2.10.2"
}
}
}
2 changes: 1 addition & 1 deletion scripts/deploy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

async function main() {
const contractFactory = await ethers.getContractFactory("greeter");
const contractFactory = await ethers.getContractFactory("Greeter");
const contract = await contractFactory.deploy("Hello, Hardhat!");
await contract.deployed();
return contract;
Expand Down
2 changes: 1 addition & 1 deletion test/sample-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { ethers } = require("hardhat");

describe("Contract Tests", function () {
it("Should return the new greeting once it's changed", async function () {
const contractFactory = await ethers.getContractFactory("greeter");
const contractFactory = await ethers.getContractFactory("Greeter");
const contract = await contractFactory.deploy("Hello, world!");
await contract.deployed();

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/diff/-/diff-5.0.0.tgz#7ed6ad76d859d030787ec35855f5b1daf31d852b"
integrity sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==

dotenv@^16.0.3:
version "16.0.3"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.0.3.tgz#115aec42bac5053db3c456db30cc243a5a836a07"
integrity sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==

[email protected], elliptic@^6.5.2, elliptic@^6.5.4:
version "6.5.4"
resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.4.tgz#da37cebd31e79a1367e941b592ed1fbebd58abbb"
Expand Down

0 comments on commit 62b25bd

Please sign in to comment.