Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ABI generation #1068

Merged
merged 4 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 68 additions & 25 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,50 +18,93 @@ env:
jobs:
build:
runs-on: ubuntu-latest
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
steps:
- uses: actions/checkout@v2

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
if: github.event_name != 'pull_request' || github.event.pull_request.merged == true

- uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
outputs:
version: ${{ steps.version.outputs.version }}

steps:
- uses: actions/checkout@v4

- name: Install NODE JS
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'yarn'

- name: Install project
run: yarn install

- name: Build and publish container
- name: Calculate version
id: version
run: |
export BRANCH=${GITHUB_REF##*/}
echo "Branch $BRANCH"
export VERSION=$(bash ./scripts/calculate_version.sh)
echo "Version $VERSION"
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
( test $BRANCH = "stable" || test $BRANCH = "master" && export PRERELEASE=false ) || export PRERELEASE=true
echo "PRERELEASE=$PRERELEASE" >> $GITHUB_ENV
bash ./scripts/build_and_publish.sh

- name: Generate ABI
run: npx hardhat run scripts/generateAbi.ts

- name: Store artifacts
uses: actions/upload-artifact@v4
with:
name: data
path: data

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: ncipollo/release-action@v1
with:
tag_name: ${{ env.VERSION }}
release_name: ${{ env.VERSION }}
draft: false
tag: ${{ env.VERSION }}
prerelease: ${{ env.PRERELEASE }}
artifacts: "data/skale-manager-*-abi.json"

docker:
runs-on: ubuntu-latest

if: github.event_name != 'pull_request' || github.event.pull_request.merged == true

steps:
- uses: actions/checkout@v4

- name: Build and publish container
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: |
export BRANCH=${GITHUB_REF##*/}
echo "Branch $BRANCH"
export VERSION=$(bash ./scripts/calculate_version.sh)
echo "Version $VERSION"
bash ./scripts/build_and_publish.sh

abi:
runs-on: ubuntu-latest

needs:
build

env:
VERSION: ${{ needs.build.outputs.version }}

steps:
- uses: actions/checkout@v4
with:
ref: abi

- name: Load artifacts
uses: actions/download-artifact@v4
with:
name: data

- name: Commit ABI
uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: "Add ABI for version ${{ env.VERSION }}"
add: "*-abi.json"
30 changes: 8 additions & 22 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,19 @@ jobs:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

steps:
- uses: actions/checkout@v2

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-

- uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- uses: actions/checkout@v4

- name: Install NODE JS
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'

- name: Install project
run: yarn install
Expand All @@ -74,6 +57,9 @@ jobs:
NODE_VERSION: ${{ matrix.node-version }}
run: ./scripts/test_upgrade.sh

- name: Test ABI ageneration
run: npx hardhat run scripts/generateAbi.ts

- name: Run tests
run: npx hardhat coverage --solcoverjs .solcover.js

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:16
FROM node:18

RUN mkdir /usr/src/manager
WORKDIR /usr/src/manager
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.10.0
2.0.0
50 changes: 50 additions & 0 deletions scripts/generateAbi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { promises as fs } from 'fs';
import { contracts } from "../migrations/deploy";
import { ethers } from "hardhat";
import { getAbi, getVersion } from '@skalenetwork/upgrade-tools';
import { ContractFactory } from 'ethers';
import { Libraries } from '@nomiclabs/hardhat-ethers/types';

async function main() {
const allContracts = contracts.concat(["SkaleToken", "TimeHelpersWithDebug"])
const abi: {[name: string]: []} = {};
const librariesRequirements: {[name: string]: string[]} = {
"Nodes": [
"SegmentTree"
],
"SkaleDKG": [
"SkaleDkgAlright",
"SkaleDkgBroadcast",
"SkaleDkgComplaint",
"SkaleDkgPreResponse",
"SkaleDkgResponse"
]
}
for (const contractName of allContracts) {
console.log(`Load ABI of ${contractName}`);
let factory: ContractFactory;
if (Object.keys(librariesRequirements).includes(contractName)) {
const libraries: Libraries = {};
for(const library of librariesRequirements[contractName]) {
libraries[library] = ethers.constants.AddressZero;
}
factory = await ethers.getContractFactory(contractName, {libraries});
} else {
factory = await ethers.getContractFactory(contractName);
}
abi[contractName] = getAbi(factory.interface);
}
const version = await getVersion();
const filename = `data/skale-manager-${version}-abi.json`;
console.log(`Save to ${filename}`)
await fs.writeFile(filename, JSON.stringify(abi, null, 4));
}

if (require.main === module) {
main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});
}
Loading