name: packages/plugins

on:
  push:
    branches:
      - main
  pull_request:
    paths:
      - packages/plugins/**

defaults:
  run:
    working-directory: ./packages/plugins

jobs:
  foundry:
    strategy:
      fail-fast: true

    name: Foundry project
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: recursive

      - name: Install Foundry
        uses: foundry-rs/foundry-toolchain@v1
        with:
          version: nightly

      - name: Run Forge build
        run: |
          forge --version
          forge build --sizes
        id: build

      # Skip safe zk email recovery unit tests while finishing demo. We still have a passing integration test - SafeZkEmailRecoveryPluginIntegration.t.sol
      - name: Run Forge tests
        run: |
          forge test --no-match-path test/unit/safe/SafeZkEmailRecoveryPlugin.t.sol -vvv
        id: test

  hardhat:
    strategy:
      fail-fast: true

    name: Hardhat project
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: recursive

      - name: Setup Node 18
        uses: actions/setup-node@v3
        with:
          node-version: "18.x"
          cache: "yarn"
          cache-dependency-path: packages/plugins/yarn.lock

      - name: Install Yarn dependencies
        run: yarn install --frozen-lockfile

      - name: Copy env file
        run: cp .env.example .env

      - name: Run hardhat build
        run: yarn build

      - name: Start geth node & bundler in background
        run: ./script/start.sh &

      - name: Wait for bundler at port 3000
        run: RPC_URL='localhost:3000' SLEEP_DURATION_SECONDS=1 ./script/wait-for-rpc.sh

      - name: Run hardhat integration tests
        run: yarn hardhat test
