diff --git a/.github/workflows/ci-build.yaml b/.github/workflows/ci-build.yaml index 96c6224428..10d24535f6 100644 --- a/.github/workflows/ci-build.yaml +++ b/.github/workflows/ci-build.yaml @@ -4,47 +4,50 @@ name: CI-Build on: pull_request: types: [ closed ] + branches: [ master ] permissions: contents: write jobs: - devnet: - if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'CI:Deploy') + build-push: + if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'CI:Build ') + name: Build runs-on: ubuntu-24.04 - - services: - geth: - image: dmanov/go-ethereum:dev-latest - ports: - - 8545:8545 - - 30303:30303 - options: >- - --health-cmd="curl --fail http://localhost:8545 || exit 1" - --health-interval=10s - --health-timeout=5s - --health-retries=10 - command: > - --dev - --http --http.addr 0.0.0.0 - --http.api eth,net,web3 - --http.corsdomain="*" - --http.vhosts="*" + environment: dev + env: + ENVIRONMENT: dev + REPO_NAME: ${{ github.event.repository.name }} steps: - - name: Checkout code + - name: Checkout the repo uses: actions/checkout@v4 with: ref: master - - name: Set up Node.js - uses: actions/setup-node@v4 + - name: Autotag + id: autotag + uses: anothrNick/github-tag-action@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + WITH_V: false + + - name: Login to Docker Hub + uses: docker/login-action@v3 with: - node-version: '18' - cache: 'npm' - cache-dependency-path: hardhat/package-lock.json + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Install Hardhat dependencies - working-directory: ./hardhat - run: npm ci + - name: Docker metadata + id: metadata + uses: docker/metadata-action@v5 + with: + images: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPO_NAME }} + - name: Build and push to Docker Hub + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPO_NAME }}:${{ env.ENVIRONMENT }}-latest,${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPO_NAME }}:${{ env.ENVIRONMENT }}-${{ steps.autotag.outputs.tag }} + labels: ${{ steps.metadata.outputs.labels }} \ No newline at end of file diff --git a/.github/workflows/ci-deploy.yaml b/.github/workflows/ci-deploy.yaml index de081b56b0..2512b8e5a9 100644 --- a/.github/workflows/ci-deploy.yaml +++ b/.github/workflows/ci-deploy.yaml @@ -1,53 +1,35 @@ name: CI-Deploy - on: pull_request: - types: [ closed ] - branches: [ master ] - -permissions: - contents: write + types: [closed] + branches: [master] jobs: - build-push: - if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'CI:Build ') - name: Build - runs-on: ubuntu-24.04 - environment: dev - env: - ENVIRONMENT: dev - REPO_NAME: ${{ github.event.repository.name }} + deploy-contracts: + if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'CI:Deploy') + runs-on: ubuntu-latest steps: - - name: Checkout the repo + - name: Checkout Repo uses: actions/checkout@v4 with: ref: master - - name: Autotag - id: autotag - uses: anothrNick/github-tag-action@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - WITH_V: false + - name: Start Geth Devnet + run: | + docker compose up -d + echo "Waiting for Geth JSON-RPC..." + until curl -s http://localhost:8545; do sleep 1; done - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Install Node Modules + working-directory: ./hardhat + run: npm ci - - name: Docker metadata - id: metadata - uses: docker/metadata-action@v5 - with: - images: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPO_NAME }} + - name: Compile Contracts + working-directory: ./hardhat + run: npx hardhat compile - - name: Build and push to Docker Hub - uses: docker/build-push-action@v6 - with: - context: . - push: true - tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPO_NAME }}:${{ env.ENVIRONMENT }}-latest,${{ secrets.DOCKERHUB_USERNAME }}/${{ env.REPO_NAME }}:${{ env.ENVIRONMENT }}-${{ steps.autotag.outputs.tag }} - labels: ${{ steps.metadata.outputs.labels }} \ No newline at end of file + - name: Deploy Contracts + working-directory: ./hardhat + run: npx hardhat run scripts/deploy.ts --network localhost diff --git a/docker-compose.yaml b/docker-compose.yaml index 788dec5d10..5947cf2d45 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,4 +1,5 @@ version: "3.8" + services: geth: container_name: geth @@ -6,8 +7,12 @@ services: volumes: - ./devnet:/root/.ethereum ports: - - "8545:8545" # HTTP based JSON RPC API - - "30303:30303" # P2P + - "8545:8545" + - "30303:30303" command: > - --http --http.addr 0.0.0.0 --http.api eth,net,web3 - --dev \ No newline at end of file + --dev + --http + --http.addr 0.0.0.0 + --http.corsdomain="*" + --allow-insecure-unlock + --verbosity 3 diff --git a/hardhat/contracts/Counter.sol b/hardhat/contracts/Counter.sol new file mode 100644 index 0000000000..f5403d88cf --- /dev/null +++ b/hardhat/contracts/Counter.sol @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +contract Counter { + uint256 public count; + + function incBy(uint256 value) public { + count += value; + } +} diff --git a/hardhat/hardhat.config.ts b/hardhat/hardhat.config.ts index 7f88be946d..417322d85a 100644 --- a/hardhat/hardhat.config.ts +++ b/hardhat/hardhat.config.ts @@ -5,7 +5,8 @@ const config: HardhatUserConfig = { solidity: "0.8.28", networks: { localhost: { - url: "http://127.0.0.1:8545" + url: "http://127.0.0.1:8545", + chainId: 1337 } } }; diff --git a/hardhat/ignition/modules/Counter.ts b/hardhat/ignition/modules/Counter.ts new file mode 100644 index 0000000000..b9d46915f6 --- /dev/null +++ b/hardhat/ignition/modules/Counter.ts @@ -0,0 +1,9 @@ +import { buildModule } from "@nomicfoundation/hardhat-ignition/modules"; + +export default buildModule("CounterModule", (m) => { + const counter = m.contract("Counter"); + + m.call(counter, "incBy", [5n]); + + return { counter }; +}); \ No newline at end of file