From f3269191bbf0a05ffaf390155f54aa7197eb3645 Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Tue, 9 Apr 2024 16:36:52 +0300 Subject: [PATCH 1/4] Add generateAbi script --- .github/workflows/publish.yml | 12 +++++++++ .github/workflows/test.yml | 3 +++ scripts/generateAbi.ts | 50 +++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 scripts/generateAbi.ts diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e2600a75..4a997afd 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -55,6 +55,9 @@ jobs: echo "PRERELEASE=$PRERELEASE" >> $GITHUB_ENV bash ./scripts/build_and_publish.sh + - name: Generate ABI + run: npx hardhat run scripts/generateAbi.ts + - name: Create Release id: create_release uses: actions/create-release@v1 @@ -65,3 +68,12 @@ jobs: release_name: ${{ env.VERSION }} draft: false prerelease: ${{ env.PRERELEASE }} + + - name: Upload ABIs + id: upload-abi + uses: dwenegar/upload-release-assets@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + release_id: ${{ steps.create_release.outputs.id }} + assets_path: data/skale-manager-*-abi.json diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 86ddb738..54cf9d35 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -74,6 +74,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 diff --git a/scripts/generateAbi.ts b/scripts/generateAbi.ts new file mode 100644 index 00000000..016a95cd --- /dev/null +++ b/scripts/generateAbi.ts @@ -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); + }); +} From ed7dc50a6eab642bcef094156bde5216f0c4e724 Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Tue, 9 Apr 2024 16:44:58 +0300 Subject: [PATCH 2/4] Update actions --- .github/workflows/publish.yml | 40 +++++++++-------------------------- .github/workflows/test.yml | 27 +++++------------------ 2 files changed, 15 insertions(+), 52 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 4a997afd..16075679 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -18,28 +18,21 @@ env: jobs: build: runs-on: ubuntu-latest + + if: github.event_name != 'pull_request' || github.event.pull_request.merged == true + 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)" - - 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- + 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 @@ -59,21 +52,8 @@ jobs: run: npx hardhat run scripts/generateAbi.ts - 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 }} - - - name: Upload ABIs - id: upload-abi - uses: dwenegar/upload-release-assets@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - release_id: ${{ steps.create_release.outputs.id }} - assets_path: data/skale-manager-*-abi.json + artifacts: "data/skale-manager-*-abi.json" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 54cf9d35..cad355a1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 From f1536c585c8092c089ea03b7836dc06d4df69461 Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Tue, 9 Apr 2024 17:04:59 +0300 Subject: [PATCH 3/4] Commit generated ABIs --- .github/workflows/publish.yml | 61 ++++++++++++++++++++++++++++++++--- Dockerfile | 2 +- 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 16075679..2b2f7d87 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -21,9 +21,8 @@ jobs: if: github.event_name != 'pull_request' || github.event.pull_request.merged == true - env: - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + outputs: + version: ${{ steps.version.outputs.version }} steps: - uses: actions/checkout@v4 @@ -37,23 +36,75 @@ jobs: - 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 uses: ncipollo/release-action@v1 with: 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" diff --git a/Dockerfile b/Dockerfile index 054488d8..a178b410 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:16 +FROM node:18 RUN mkdir /usr/src/manager WORKDIR /usr/src/manager From 27f074d16fbf82e377be5e9bccdc401a58bfd011 Mon Sep 17 00:00:00 2001 From: Dmytro Stebaiev Date: Tue, 9 Apr 2024 17:06:51 +0300 Subject: [PATCH 4/4] Bump version --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 81c871de..227cea21 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.10.0 +2.0.0