Skip to content

Commit

Permalink
Merge pull request #1 from zeta-chain/feat/release
Browse files Browse the repository at this point in the history
ci: publish to npm workflow
  • Loading branch information
fadeev authored Jun 9, 2023
2 parents d7be34c + 0b6aea8 commit 5c2aabb
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 12 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/publish-npm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Publish to NPM

on:
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "16"
registry-url: "https://registry.npmjs.org"

- name: Install Dependencies
run: yarn install

- name: Build
run: yarn build

- name: Publish to NPM
run: yarn publish --new-version ${GITHUB_REF#refs/tags/v}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_REF: ${{ github.ref }}
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/src
/scripts
/networks.schema.json
/tsconfig.json
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zetachain/networks",
"version": "1.0.0",
"version": "0.0.0-set-on-publish",
"description": "",
"main": "dist/index.js",
"scripts": {
Expand Down
34 changes: 23 additions & 11 deletions src/getHardhatConfigNetworks.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
import fs from "fs";
import path from "path";

export const getHardhatConfigNetworks = (accounts: string[]): any => {
// Read and parse the JSON file
const dataBuffer = fs.readFileSync(
path.resolve(__dirname, "..", "data", "networks.json")
);
const dataJson: any = JSON.parse(dataBuffer.toString());
export const networks = JSON.parse(
fs
.readFileSync(path.resolve(__dirname, "..", "data", "networks.json"))
.toString()
);

export const getHardhatConfigNetworks = (accounts: string[]): any => {
const config: any = {};

// Loop through the JSON object and create the required structure
for (const network in dataJson) {
let apiUrls = dataJson[network].api;
for (const network in networks) {
let apiUrls = networks[network].api;
let evmApi = apiUrls?.find((api: any) => api.type === "evm");
config[network] = {
accounts,
chainId: dataJson[network].chain_id,
gas: dataJson[network].fees.assets[0].gas,
gasPrice: dataJson[network].fees.assets[0].gas_price,
chainId: networks[network].chain_id,
gas: networks[network].fees.assets[0].gas,
gasPrice: networks[network].fees.assets[0].gas_price,
url: evmApi?.url || "",
};
}

return config;
};

// Temporary function that maps chain IDs to the old chain names
// used by @zetachain/addresses
export const chainNameById = (chainId: number): any => {
return {
7001: "athens",
97: "bsc-testnet",
5: "goerli",
1001: "klaytn-baobab",
80001: "polygon-mumbai",
}[chainId];
};

0 comments on commit 5c2aabb

Please sign in to comment.