diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e2600a75..2b2f7d87 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -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" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 86ddb738..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 @@ -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 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 diff --git a/VERSION b/VERSION index 81c871de..227cea21 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.10.0 +2.0.0 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); + }); +}